diff --git a/bundles/org.eclipse.passage.lac/src/org/eclipse/passage/internal/lac/base/CanUse.java b/bundles/org.eclipse.passage.lac/src/org/eclipse/passage/internal/lac/base/CanUse.java index d5dc9a748..7f437b0a0 100644 --- a/bundles/org.eclipse.passage.lac/src/org/eclipse/passage/internal/lac/base/CanUse.java +++ b/bundles/org.eclipse.passage.lac/src/org/eclipse/passage/internal/lac/base/CanUse.java @@ -30,7 +30,7 @@ protected CanUse(NetRequest request) { } @Override - protected Optional invalid() { + protected Optional rawInvalid() { Optional feature = feature(); if (!feature.isPresent()) { return Optional.of(new Failure.BadRequestNoFeature()); @@ -38,6 +38,11 @@ protected Optional invalid() { return Optional.empty(); } + @Override + protected Optional productUserInvalid(ProductUserRequest refined) { + return Optional.empty(); + } + private Optional feature() { return new FeatureIdentifier(key -> data.parameter(key)).get(); } diff --git a/bundles/org.eclipse.passage.lbc.base/.settings/.api_filters b/bundles/org.eclipse.passage.lbc.base/.settings/.api_filters deleted file mode 100644 index c413d36d7..000000000 --- a/bundles/org.eclipse.passage.lbc.base/.settings/.api_filters +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bundles/org.eclipse.passage.lbc.base/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lbc.base/META-INF/MANIFEST.MF index 2529485f9..8ae9caaec 100644 --- a/bundles/org.eclipse.passage.lbc.base/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lbc.base/META-INF/MANIFEST.MF @@ -7,19 +7,13 @@ Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Require-Bundle: javax.servlet;bundle-version="0.0.0", - org.eclipse.osgi;bundle-version="0.0.0", +Require-Bundle: org.eclipse.osgi;bundle-version="0.0.0", org.eclipse.passage.lic.base;bundle-version="0.0.0", org.eclipse.passage.lic.net;bundle-version="0.0.0", org.eclipse.passage.lic.licenses.model;bundle-version="0.0.0", org.eclipse.emf.ecore.xmi;bundle-version="0.0.0", - org.eclipse.passage.lic.json;bundle-version="0.0.0", - com.fasterxml.jackson.core.jackson-databind;bundle-version="0.0.0", - com.fasterxml.jackson.core.jackson-core;bundle-version="0.0.0", org.eclipse.passage.lic.floating;bundle-version="0.1.0", - org.eclipse.passage.lic.bc;bundle-version="1.0.100", org.eclipse.passage.lic.floating.model;bundle-version="0.1.0", - org.eclipse.passage.lic.licenses.migration;bundle-version="0.5.300", org.eclipse.passage.lic.emf;bundle-version="1.0.100", org.eclipse.passage.lic.oshi;bundle-version="1.0.1", org.apache.logging.log4j;bundle-version="2.8.2", diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/AuthentifiedChoreDraft.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/AuthentifiedChoreDraft.java index cc650c70f..5ed93f27a 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/AuthentifiedChoreDraft.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/AuthentifiedChoreDraft.java @@ -12,13 +12,20 @@ *******************************************************************************/ package org.eclipse.passage.lbc.internal.base; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Optional; import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.internal.api.EvaluationInstructions; +import org.eclipse.passage.lic.internal.api.LicensedProduct; +import org.eclipse.passage.lic.internal.base.io.FileNameFromLicensedProduct; +import org.eclipse.passage.lic.internal.base.io.PassageFileExtension; +import org.eclipse.passage.lic.internal.base.io.PathFromLicensedProduct; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; import org.eclipse.passage.lic.internal.net.handle.ChoreDraft; import org.eclipse.passage.lic.internal.net.handle.Failure; +import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; abstract class AuthentifiedChoreDraft extends ChoreDraft { @@ -27,7 +34,16 @@ protected AuthentifiedChoreDraft(RawRequest request) { } @Override - protected Optional invalid() { + protected Optional rawInvalid() { + return serverIsNotAuthenticated(); + } + + @Override + protected Optional productUserInvalid(ProductUserRequest refined) { + return productUnknown(refined); + } + + private Optional serverIsNotAuthenticated() { Optional instructions = new ServerAuthenticationInstructions(data).get(); if (!instructions.isPresent()) { return Optional.of(new Failure.BadRequestInvalidServerAuthInstructions()); @@ -35,10 +51,21 @@ protected Optional invalid() { try { new ServerAuthentication(instructions.get()).evaluate(); } catch (Exception e) { - log.error("failed: ", e); //$NON-NLS-1$ + log.error("Failed on server authentication attempt: ", e); //$NON-NLS-1$ return Optional.of(new Failure.ForeignServer(e.getMessage())); } return Optional.empty(); } + private Optional productUnknown(ProductUserRequest refined) { + LicensedProduct product = refined.product().get(); + Path key = new PathFromLicensedProduct(data.state()::source, product).get()// + .resolve(new FileNameFromLicensedProduct(product, new PassageFileExtension.PublicKey()).get()); + if (!Files.exists(key)) { + log.error(String.format("Key file [%s] is not found", product)); //$NON-NLS-1$ + return Optional.of(new Failure.BadRequestUnkonwnProduct(product)); + } + return Optional.empty(); + } + } diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/EagerFloatingState.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/EagerFloatingState.java index 105322d48..64016278a 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/EagerFloatingState.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/EagerFloatingState.java @@ -24,13 +24,19 @@ public final class EagerFloatingState implements FloatingState { private final Grants grants; + private final Path source; public EagerFloatingState() { this(new LicensingFolder(new UserHomePath())); } public EagerFloatingState(Supplier source) { - this.grants = new AcquiredGrants(source); + this(new AcquiredGrants(source), source.get()); + } + + public EagerFloatingState(Grants grants, Path source) { + this.grants = grants; + this.source = source; } @Override @@ -38,4 +44,9 @@ public Grants grants() { return grants; } + @Override + public Path source() { + return source; + } + } diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/EncodedResponse.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/EncodedResponse.java new file mode 100644 index 000000000..a0a7b179e --- /dev/null +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/EncodedResponse.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lbc.internal.base; + +import java.util.Optional; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.passage.lbc.internal.base.api.FlsGear; +import org.eclipse.passage.lbc.internal.base.api.FlsGearAwre; +import org.eclipse.passage.lbc.internal.base.api.RawRequest; +import org.eclipse.passage.lic.internal.api.io.Hashes; +import org.eclipse.passage.lic.internal.api.io.KeyKeeper; +import org.eclipse.passage.lic.internal.api.registry.StringServiceId; +import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; +import org.eclipse.passage.lic.internal.net.handle.EObjectTransfer; +import org.eclipse.passage.lic.internal.net.handle.Failure; +import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; + +public final class EncodedResponse { + + private final T payload; + private final ProductUserRequest data; + + public EncodedResponse(T payload, ProductUserRequest data) { + this.payload = payload; + this.data = data; + } + + public NetResponse get() { + return new FlsGearAwre()// + .withGear(this::transferable) // + .orElse(new Failure.OperationFailed("mine", "Failed exploiting gear")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + private Optional transferable(FlsGear gear) { + return Optional.of(new EObjectTransfer(payload, keyKeeper(gear), hashes(gear))); + } + + private KeyKeeper keyKeeper(FlsGear gear) { + return gear.keyKeper(data.product().get(), data.raw().state()::source); + } + + private Hashes hashes(FlsGear gear) { + return gear.hashes().get().service(new StringServiceId(data.algorithm().get())); + } + +} diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/Acquisition.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/Acquisition.java index 824b1f230..d640a520d 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/Acquisition.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/Acquisition.java @@ -19,6 +19,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.passage.lbc.internal.base.EncodedResponse; import org.eclipse.passage.lbc.internal.base.api.Grants; import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.floating.model.api.GrantAcqisition; @@ -28,7 +30,6 @@ import org.eclipse.passage.lic.internal.base.FeatureIdentifier; import org.eclipse.passage.lic.internal.emf.EObjectFromBytes; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; -import org.eclipse.passage.lic.internal.net.handle.EObjectTransfer; import org.eclipse.passage.lic.internal.net.handle.Failure; import org.eclipse.passage.lic.internal.net.handle.PlainSuceess; import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; @@ -58,7 +59,11 @@ public NetResponse get() { if (!acquisition.isPresent()) { return noGrants(feature.get()); } - return new EObjectTransfer(acquisition.get()); + return encodedPack(acquisition.get()); + } + + private NetResponse encodedPack(GrantAcqisition acqisition) { + return new EncodedResponse(acqisition, data).get(); } public NetResponse returnBack() throws LicensingException { diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/FeatureGrants.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/FeatureGrants.java index e626eb743..9b5d9614e 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/FeatureGrants.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/FeatureGrants.java @@ -14,10 +14,15 @@ import java.nio.file.Path; import java.util.Collection; +import java.util.Collections; import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.eclipse.passage.lbc.internal.base.api.FlsGear; +import org.eclipse.passage.lbc.internal.base.api.FlsGearAwre; import org.eclipse.passage.lic.floating.model.api.FeatureGrant; import org.eclipse.passage.lic.floating.model.api.FloatingLicensePack; import org.eclipse.passage.lic.internal.api.LicensedProduct; @@ -29,6 +34,7 @@ final class FeatureGrants { private final String user; private final String feature; private final Supplier base; + private final Logger log = LogManager.getLogger(getClass()); FeatureGrants(LicensedProduct product, String user, String feature, Supplier base) { this.product = product; @@ -41,13 +47,34 @@ final class FeatureGrants { * Explore all licenses for the {@code product} and collect all grants for the * given {@code feature}, if any */ - Collection get() throws LicensingException { - return new LicensePacks(product, base).get().stream()// - .filter(new AvailableForUser(user)) // - .map(this::grantForFeature) // - .filter(Optional::isPresent) // - .map(Optional::get) // - .collect(Collectors.toList()); + Collection get() { + return new FlsGearAwre()// + .withGear(gear -> Optional.of(get(gear)))// + .orElse(failedOnGathering()); + } + + private Collection failedOnGathering() { + log.error(String.format("Failed on gathering grans for product %s", product)); //$NON-NLS-1$ + return Collections.emptyList(); + } + + private Collection get(FlsGear gear) { + try { + return new LicensePacks(// + gear.keyKeper(product, base), // + gear.codec(product), // + product, // + base// + ).get().stream()// + .filter(new AvailableForUser(user)) // + .map(this::grantForFeature) // + .filter(Optional::isPresent) // + .map(Optional::get) // + .collect(Collectors.toList()); + } catch (LicensingException e) { + log.error(e); + return Collections.emptyList(); + } } /** diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/LicensePacks.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/LicensePacks.java index 3b04a8d7e..e26a52ea5 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/LicensePacks.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/LicensePacks.java @@ -31,8 +31,6 @@ import org.eclipse.passage.lic.internal.base.conditions.mining.DecodedContent; import org.eclipse.passage.lic.internal.base.io.FileCollection; import org.eclipse.passage.lic.internal.base.io.PathFromLicensedProduct; -import org.eclipse.passage.lic.internal.base.io.PathKeyKeeper; -import org.eclipse.passage.lic.internal.bc.BcStreamCodec; import org.eclipse.passage.lic.internal.emf.EObjectFromBytes; final class LicensePacks { @@ -43,10 +41,10 @@ final class LicensePacks { private final Supplier base; private final Logger log = LogManager.getLogger(getClass()); - LicensePacks(LicensedProduct product, Supplier base) { + public LicensePacks(KeyKeeper key, StreamCodec codec, LicensedProduct product, Supplier base) { this.product = product; - this.key = new PathKeyKeeper(product, base); - this.codec = new BcStreamCodec(() -> product); + this.key = key; + this.codec = codec; this.base = base; } diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/api/FloatingState.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/api/FloatingState.java index bd274511a..e9788fa60 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/api/FloatingState.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/api/FloatingState.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 ArSysOp + * Copyright (c) 2020, 2021 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.passage.lbc.internal.base.api; +import java.nio.file.Path; + /** * FIXME: temporary * @@ -23,4 +25,6 @@ public interface FloatingState { Grants grants(); + Path source(); + } diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/interaction/Pack.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/interaction/Pack.java index 63ff2907f..8b3a8ad27 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/interaction/Pack.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/interaction/Pack.java @@ -15,7 +15,10 @@ import java.nio.file.Path; import java.util.Collections; +import java.util.Optional; +import org.eclipse.passage.lbc.internal.base.api.FlsGear; +import org.eclipse.passage.lbc.internal.base.api.FlsGearAwre; import org.eclipse.passage.lic.floating.model.api.FloatingLicensePack; import org.eclipse.passage.lic.floating.model.api.ProductRef; import org.eclipse.passage.lic.floating.model.meta.FloatingPackage; @@ -25,7 +28,6 @@ import org.eclipse.passage.lic.internal.base.InvalidLicensedProduct; import org.eclipse.passage.lic.internal.base.conditions.mining.DecodedContent; import org.eclipse.passage.lic.internal.base.io.FileKeyKeeper; -import org.eclipse.passage.lic.internal.bc.BcStreamCodec; import org.eclipse.passage.lic.internal.emf.EObjectFromBytes; final class Pack { @@ -67,11 +69,23 @@ private FloatingLicensePack read(byte[] bytes) throws LicensingException { } private byte[] decoded() throws LicensingException { - return new DecodedContent(// - license, // - new FileKeyKeeper(key), // - new BcStreamCodec(InvalidLicensedProduct::new) // not demanded for decoding, only for error handling - ).get(); + return new FlsGearAwre()// + .withGear(g -> Optional.of(decoded(g)))// + .orElseThrow(() -> new LicensingException("Fail resolving gear")); //$NON-NLS-1$ + } + + private final byte[] decoded(FlsGear gear) { + try { + return new DecodedContent(// + license, // + new FileKeyKeeper(key), // + // 'product' is not demanded for decoding, only for error handling + gear.codec(new InvalidLicensedProduct())// + ).get(); + } catch (LicensingException e) { + e.printStackTrace(); // truly! outputs a handles by console + return new byte[0]; + } } LicensedProduct product() { diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/interaction/package-info.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/interaction/package-info.java new file mode 100644 index 000000000..1e9316d04 --- /dev/null +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/interaction/package-info.java @@ -0,0 +1,17 @@ +/* ***************************************************************************** + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ + +/** + * FLS server administration console commands implementations + */ +package org.eclipse.passage.lbc.internal.base.interaction; diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/Conditions.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/Conditions.java index cc05fefd1..e4347ee4e 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/Conditions.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/Conditions.java @@ -12,23 +12,21 @@ *******************************************************************************/ package org.eclipse.passage.lbc.internal.base.mine; -import java.nio.file.Path; import java.util.Collection; import java.util.function.Supplier; import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.passage.lbc.internal.base.EncodedResponse; import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.internal.api.PassageAction; import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; import org.eclipse.passage.lic.internal.api.conditions.ConditionPack; import org.eclipse.passage.lic.internal.base.diagnostic.DiagnosticExplained; import org.eclipse.passage.lic.internal.base.diagnostic.NoErrors; -import org.eclipse.passage.lic.internal.base.io.LicensingFolder; -import org.eclipse.passage.lic.internal.base.io.UserHomePath; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; -import org.eclipse.passage.lic.internal.net.handle.EObjectTransfer; import org.eclipse.passage.lic.internal.net.handle.Failure; import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; import org.eclipse.passage.lic.licenses.model.api.LicensePack; @@ -36,23 +34,17 @@ public final class Conditions implements Supplier { private final ProductUserRequest data; - private final Supplier source; private final Logger log = LogManager.getLogger(getClass()); - public Conditions(ProductUserRequest data, Supplier base) { - this.data = data; - this.source = base; - } - public Conditions(ProductUserRequest data) { - this(data, new LicensingFolder(new UserHomePath())); + this.data = data; } @Override public NetResponse get() { log.debug(String.format("Mining conditions for product %s", data.product().get())); //$NON-NLS-1$ ServiceInvocationResult> conditions = // - new FloatingConditions(source, data.user().get())// + new FloatingConditions(data.raw().state()::source, data.user().get())// .all(data.product().get()); if (!conditions.data().isPresent()) { return new Failure.OperationFailed(// @@ -62,7 +54,11 @@ public NetResponse get() { if (!new NoErrors().test(conditions.diagnostic())) { log.error(new DiagnosticExplained(conditions.diagnostic()).get()); } - return new EObjectTransfer(pack(conditions.data().get())); + return encodedPack(pack(conditions.data().get())); + } + + private NetResponse encodedPack(LicensePack pack) { + return new EncodedResponse(pack, data).get(); } private LicensePack pack(Collection conditions) { diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/ReassemblingMiningEquipment.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/ReassemblingMiningEquipment.java index a1a4e1341..a06f2ebbc 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/ReassemblingMiningEquipment.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/ReassemblingMiningEquipment.java @@ -13,11 +13,15 @@ package org.eclipse.passage.lbc.internal.base.mine; import java.nio.file.Path; +import java.util.Optional; import java.util.function.Supplier; +import org.eclipse.passage.lbc.internal.base.api.FlsGear; +import org.eclipse.passage.lbc.internal.base.api.FlsGearAwre; import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.conditions.ConditionMiningTarget; +import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType; import org.eclipse.passage.lic.internal.api.conditions.mining.MiningEquipment; import org.eclipse.passage.lic.internal.api.conditions.mining.MiningTool; @@ -33,7 +37,16 @@ public final class ReassemblingMiningEquipment implements MiningEquipment { @Override public MiningTool tool(LicensedProduct product, ConditionMiningTarget miner) throws LicensingException { - return new ReassemblingMiningTool(product, user, base, miner); + return new FlsGearAwre().withGear(gear -> tool(gear, product, miner)).get(); } + private Optional tool(FlsGear gear, LicensedProduct product, ConditionMiningTarget miner) { + return Optional.of(new ReassemblingMiningTool(// + gear.keyKeper(product, base), // + gear.codec(product), // + gear.transport(new ContentType.Xml()), // + product, // + user, // + miner)); + } } diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/ReassemblingMiningTool.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/ReassemblingMiningTool.java index fb7eabb6e..05eeeda15 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/ReassemblingMiningTool.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/ReassemblingMiningTool.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.function.Supplier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -31,7 +30,10 @@ import org.eclipse.passage.lic.internal.api.conditions.Condition; import org.eclipse.passage.lic.internal.api.conditions.ConditionMiningTarget; import org.eclipse.passage.lic.internal.api.conditions.ConditionPack; +import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionTransport; import org.eclipse.passage.lic.internal.api.diagnostic.Trouble; +import org.eclipse.passage.lic.internal.api.io.KeyKeeper; +import org.eclipse.passage.lic.internal.api.io.StreamCodec; import org.eclipse.passage.lic.internal.base.BaseLicensedProduct; import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; import org.eclipse.passage.lic.internal.base.conditions.BaseConditionOrigin; @@ -39,10 +41,7 @@ import org.eclipse.passage.lic.internal.base.conditions.mining.ArmedMiningTool; import org.eclipse.passage.lic.internal.base.diagnostic.BaseDiagnostic; import org.eclipse.passage.lic.internal.base.diagnostic.code.ServiceFailedOnMorsel; -import org.eclipse.passage.lic.internal.base.io.PathKeyKeeper; -import org.eclipse.passage.lic.internal.bc.BcStreamCodec; import org.eclipse.passage.lic.internal.emf.EObjectFromBytes; -import org.eclipse.passage.lic.internal.licenses.migration.tobemoved.XmiConditionTransport; final class ReassemblingMiningTool extends ArmedMiningTool { @@ -50,12 +49,9 @@ final class ReassemblingMiningTool extends ArmedMiningTool { private final LicensedProduct product; private final Logger log = LogManager.getLogger(getClass()); - ReassemblingMiningTool(LicensedProduct product, String user, Supplier base, ConditionMiningTarget miner) { - super(// - new PathKeyKeeper(product, base), // - new BcStreamCodec(() -> product), // - new XmiConditionTransport(), // is not used - miner); + ReassemblingMiningTool(KeyKeeper key, StreamCodec codec, ConditionTransport transport, LicensedProduct product, + String user, ConditionMiningTarget miner) { + super(key, codec, transport, miner); this.product = product; this.user = user; } diff --git a/bundles/org.eclipse.passage.lbc.jetty/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lbc.jetty/META-INF/MANIFEST.MF index a2ee869ad..88de774a9 100644 --- a/bundles/org.eclipse.passage.lbc.jetty/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lbc.jetty/META-INF/MANIFEST.MF @@ -8,10 +8,10 @@ Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.eclipse.osgi.services;bundle-version="0.0.0", - org.eclipse.passage.lbc.base;bundle-version="1.1.1", org.eclipse.passage.lic.net;bundle-version="1.0.100", org.eclipse.passage.lic.jetty;bundle-version="0.1.0", org.eclipse.core.runtime;bundle-version="3.20.0", - org.eclipse.passage.lic.equinox;bundle-version="1.0.200" + org.eclipse.passage.lic.equinox;bundle-version="1.0.200", + org.eclipse.passage.lbc.base;bundle-version="1.1.0" Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.passage.lbc.internal.jetty.FlsJettyActivator diff --git a/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsJettyActivator.java b/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsJettyActivator.java index 16aa57cb5..00b31b70e 100644 --- a/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsJettyActivator.java +++ b/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsJettyActivator.java @@ -24,6 +24,7 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; +@SuppressWarnings("restriction") public final class FlsJettyActivator extends LicensedJettyActivator { private final FloatingState state; diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/diagnostic/code/package-info.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/diagnostic/code/package-info.java index 4c441b415..46ebc1afa 100644 --- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/diagnostic/code/package-info.java +++ b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/diagnostic/code/package-info.java @@ -1,3 +1,16 @@ +/* ***************************************************************************** + * Copyright (c) 2020, 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ + /** *
    * General license cycle errors diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/i18n/AccessCycleMessages.properties b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/i18n/AccessCycleMessages.properties index b1e293b84..1a97723ae 100644 --- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/i18n/AccessCycleMessages.properties +++ b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/i18n/AccessCycleMessages.properties @@ -19,4 +19,4 @@ Lock.temp_access=Temporary access granted for feature %s Lock.wrong_release=Illegal lock release: the lock has not been granted Restrictions.no_services=There is no examination service available. Looks suspicious. Restrictions.type=Requirements versus permissions examination -PathKeyKeeper_input_stream_error=Failed to initialize FileInputStream for KeyKeeper +PathKeyKeeper_input_stream_error=Failed to initialize FileInputStream for KeyKeeper from path %s diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/io/PathKeyKeeper.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/io/PathKeyKeeper.java index 88e888d48..9eb9bea0b 100644 --- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/io/PathKeyKeeper.java +++ b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/io/PathKeyKeeper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 ArSysOp + * Copyright (c) 2020, 2021 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -46,7 +46,11 @@ public InputStream productPublicKey() throws LicensingException { try { return new FileInputStream(path.toFile()); } catch (Exception e) { - throw new LicensingException(AccessCycleMessages.getString("PathKeyKeeper_input_stream_error"), e); //$NON-NLS-1$ + throw new LicensingException(// + String.format(// + AccessCycleMessages.getString("PathKeyKeeper_input_stream_error"), //$NON-NLS-1$ + base.get().toAbsolutePath()), // + e); } } diff --git a/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF index a822ab2e5..57193ca58 100644 --- a/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.osgi;bundle-version="0.0.0";visibility:=reexport, org.eclipse.osgi.services;bundle-version="0.0.0";visibility:=reexport, org.eclipse.core.runtime;bundle-version="0.0.0";visibility:=reexport, org.eclipse.passage.lic.api;bundle-version="1.0.0";visibility:=reexport, - org.eclipse.passage.lic.base;bundle-version="1.0.0";visibility:=reexport + org.eclipse.passage.lic.base;bundle-version="1.0.0";visibility:=reexport, + org.apache.logging.log4j;bundle-version="2.8.2" Export-Package: org.eclipse.passage.lic.internal.equinox; x-friends:="org.eclipse.passage.lac, org.eclipse.passage.lic.e4.ui, diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/GearAware.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/GearAware.java index aa02bf2ec..b76b48fab 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/GearAware.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/GearAware.java @@ -17,6 +17,8 @@ import java.util.Optional; import java.util.function.Function; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.eclipse.passage.lic.internal.api.Gear; import org.eclipse.passage.lic.internal.api.GearSupplier; import org.osgi.framework.BundleContext; @@ -26,15 +28,19 @@ public abstract class GearAware> { + private final Logger log = LogManager.getLogger(getClass()); + public final Optional withGear(Function> with) { BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); Collection> references = Collections.emptyList(); try { references = context.getServiceReferences(supplier(), null); } catch (InvalidSyntaxException e) { + log.error(e); return Optional.empty(); } if (references.isEmpty()) { + log.error("No reference of service " + supplier().getName()); //$NON-NLS-1$ return Optional.empty(); } ServiceReference any = references.iterator().next(); diff --git a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/ChoreDraft.java b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/ChoreDraft.java index 562751460..48a7c865e 100644 --- a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/ChoreDraft.java +++ b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/ChoreDraft.java @@ -32,9 +32,9 @@ protected ChoreDraft(R request) { @Override public final NetResponse getDone() { - Optional error = invalid(); - if (error.isPresent()) { - return error.get(); + Optional raw = rawInvalid(); + if (raw.isPresent()) { + return raw.get(); } ProductUserRequest request; try { @@ -46,9 +46,17 @@ public final NetResponse getDone() { if (!request.product().isPresent()) { return new Failure.BadRequestInvalidProduct(); } + if (!request.user().isPresent()) { return new Failure.BadRequestNoUser(); } + if (!request.algorithm().isPresent()) { + return new Failure.BadRequestNoAlgo(); + } + Optional refined = productUserInvalid(request); + if (refined.isPresent()) { + return refined.get(); + } try { return withProductUser(request); } catch (LicensingException e) { @@ -57,7 +65,9 @@ public final NetResponse getDone() { } } - protected abstract Optional invalid(); + protected abstract Optional rawInvalid(); + + protected abstract Optional productUserInvalid(ProductUserRequest refined); protected abstract NetResponse withProductUser(ProductUserRequest request) throws LicensingException; diff --git a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/EObjectTransfer.java b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/EObjectTransfer.java index 52856afbb..024d4e7c0 100644 --- a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/EObjectTransfer.java +++ b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/EObjectTransfer.java @@ -15,15 +15,22 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType; +import org.eclipse.passage.lic.internal.api.io.Hashes; +import org.eclipse.passage.lic.internal.api.io.KeyKeeper; import org.eclipse.passage.lic.internal.emf.EObjectToBytes; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; +import org.eclipse.passage.lic.internal.net.io.SafePayload; public final class EObjectTransfer implements NetResponse { private final EObject payload; + private final KeyKeeper key; + private final Hashes hashes; - public EObjectTransfer(EObject payload) { + public EObjectTransfer(EObject payload, KeyKeeper key, Hashes hashes) { this.payload = payload; + this.key = key; + this.hashes = hashes; } @Override @@ -43,7 +50,7 @@ public Error error() { @Override public byte[] payload() throws LicensingException { - return new EObjectToBytes(payload).get(); + return encode(new EObjectToBytes(payload).get()); } @Override @@ -51,4 +58,8 @@ public ContentType contentType() { return new ContentType.Xml(); } + private byte[] encode(byte[] plain) throws LicensingException { + return new SafePayload(key, hashes).encode(plain); + } + } diff --git a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/Failure.java b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/Failure.java index d19a3340d..03c7851ee 100644 --- a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/Failure.java +++ b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/Failure.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.passage.lic.internal.net.handle; +import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; @@ -105,10 +106,26 @@ public BadRequestNoUser() { } + public static final class BadRequestNoAlgo extends Failure { + + public BadRequestNoAlgo() { + super(606, "Bad Request: no encoding algorithm identifier"); //$NON-NLS-1$ + } + + } + public static final class BadRequestNoFeature extends Failure { public BadRequestNoFeature() { - super(606, "Bad Request: no feature identifier"); //$NON-NLS-1$ + super(607, "Bad Request: no feature identifier"); //$NON-NLS-1$ + } + + } + + public static final class BadRequestUnkonwnProduct extends Failure { + + public BadRequestUnkonwnProduct(LicensedProduct product) { + super(608, String.format("Bad Request: product %s is not known to the server", product)); //$NON-NLS-1$ } } diff --git a/tests/org.eclipse.passage.lbc.base.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.passage.lbc.base.tests/META-INF/MANIFEST.MF index 60a497329..75b25d518 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.passage.lbc.base.tests/META-INF/MANIFEST.MF @@ -16,5 +16,6 @@ Require-Bundle: org.eclipse.passage.lic.base;bundle-version="1.0.0", org.eclipse.passage.lic.floating.model;bundle-version="0.1.0", org.eclipse.passage.lic.floating.ecore;bundle-version="0.1.0", org.eclipse.passage.lic.net;bundle-version="1.0.1", - org.eclipse.passage.lic.emf;bundle-version="1.0.100" + org.eclipse.passage.lic.emf;bundle-version="1.0.100", + org.eclipse.passage.lbc.fls.gear;bundle-version="0.1.0" Export-Package: org.eclipse.passage.lbc.base.tests;x-friends:="org.eclipse.passage.lic.hc.tests" diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/BaseFlotingRequestHandledTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/BaseFlotingRequestHandledTest.java index fe52f69a9..628ef324f 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/BaseFlotingRequestHandledTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/BaseFlotingRequestHandledTest.java @@ -23,6 +23,7 @@ import org.eclipse.passage.lic.internal.net.handle.Failure; import org.junit.Test; +@SuppressWarnings("restriction") public final class BaseFlotingRequestHandledTest { @Test @@ -42,7 +43,7 @@ public void handleRelease() { @Test public void doNotHandleNull() { - assertActionIsNotSupported(new FlotingRequestHandled(new RequestConstructed().get()).get()); + assertActionIsNotSupported(new FlotingRequestHandled(new RequestConstructed().getPure()).get()); } @Test @@ -72,7 +73,7 @@ private void assertActionIsNotSupported(NetResponse response) { } private RawRequest requestOfAction(PassageAction action) { - return new RequestConstructed().withAction(action).get(); + return new RequestConstructed().withAction(action).getPure(); } } diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ConditionsTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ConditionsTest.java index af8f7fed4..424114174 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ConditionsTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ConditionsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 ArSysOp + * Copyright (c) 2020, 2021 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -14,23 +14,28 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.Arrays; import java.util.List; import org.eclipse.emf.common.util.EList; +import org.eclipse.passage.lbc.internal.base.FlotingRequestHandled; import org.eclipse.passage.lbc.internal.base.api.RawRequest; -import org.eclipse.passage.lbc.internal.base.mine.Conditions; import org.eclipse.passage.lic.internal.api.LicensingException; +import org.eclipse.passage.lic.internal.api.PassageAction; +import org.eclipse.passage.lic.internal.base.InvalidLicensedProduct; import org.eclipse.passage.lic.internal.base.ProductIdentifier; import org.eclipse.passage.lic.internal.base.ProductVersion; import org.eclipse.passage.lic.internal.net.LicenseUser; +import org.eclipse.passage.lic.internal.net.LicensingAction; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; -import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; +import org.eclipse.passage.lic.internal.net.handle.Failure; import org.eclipse.passage.lic.licenses.model.api.LicenseGrant; import org.junit.Test; +@SuppressWarnings("restriction") public final class ConditionsTest { private final TestData data = new TestData(); @@ -47,27 +52,33 @@ public void mineNothingForWrongUser() throws LicensingException, IOException { } @Test - public void mineNothingForWrongProduct() throws LicensingException, IOException { - mineForUserAndProduct(data.albert().id(), "foreign-product", 0); //$NON-NLS-1$ + public void getErrorForWrongProduct() throws LicensingException, IOException { + NetResponse response = new FlotingRequestHandled(// + request(data.albert().id(), "foreign-product")).get(); //$NON-NLS-1$ + assertTrue(response.failed()); + assertEquals(// + new Failure.BadRequestUnkonwnProduct(new InvalidLicensedProduct()).error().code(), // + response.error().code()); } private List mineForUserAndProduct(String user, String product, int conditions) throws IOException, LicensingException { - NetResponse response = new Conditions(request(user, product), new TestLicFolder()).get(); + RawRequest request = request(user, product); + NetResponse response = new FlotingRequestHandled(request).get(); assertFalse(response.failed()); - EList grants = new License(response).get().getLicenseGrants(); + EList grants = new DecodedResponse.License(response, request).get().getLicenseGrants(); assertEquals(conditions, grants.size()); return grants; } - private ProductUserRequest request(String user, String product) throws LicensingException { - return new ProductUserRequest<>(// - new RequestConstructed()// - .withParameters(Arrays.asList(// - new ProductIdentifier(product), new ProductVersion("0.2.1"), //$NON-NLS-1$ - new LicenseUser(user))) - .get()// - ); + private RawRequest request(String user, String product) throws LicensingException { + return new RequestConstructed()// + .withParameters(Arrays.asList(// + new LicensingAction(new PassageAction.Mine()), // + new ProductIdentifier(product), // + new ProductVersion("0.2.1"), //$NON-NLS-1$ + new LicenseUser(user)))// + .getValid();// } } diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/DecodedResponse.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/DecodedResponse.java new file mode 100644 index 000000000..1d677facc --- /dev/null +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/DecodedResponse.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2020, 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lbc.base.tests; + +import java.io.IOException; +import java.util.Collections; +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.passage.lbc.internal.base.api.RawRequest; +import org.eclipse.passage.lic.floating.model.api.GrantAcqisition; +import org.eclipse.passage.lic.floating.model.meta.FloatingPackage; +import org.eclipse.passage.lic.internal.api.LicensedProduct; +import org.eclipse.passage.lic.internal.api.LicensingException; +import org.eclipse.passage.lic.internal.base.io.MD5Hashes; +import org.eclipse.passage.lic.internal.base.io.PathKeyKeeper; +import org.eclipse.passage.lic.internal.emf.EObjectFromBytes; +import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; +import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; +import org.eclipse.passage.lic.internal.net.io.SafePayload; +import org.eclipse.passage.lic.licenses.model.api.LicensePack; +import org.eclipse.passage.lic.licenses.model.meta.LicensesPackage; + +@SuppressWarnings("restriction") +abstract class DecodedResponse { + + private final NetResponse response; + private final RawRequest request; + private final Map options; + + DecodedResponse(NetResponse response, RawRequest request, Map options) { + this.response = response; + this.request = request; + this.options = options; + } + + final T get() throws IOException, LicensingException { + return new EObjectFromBytes<>(decoded(response.payload()), target()).get(options); + } + + protected abstract Class target(); + + private byte[] decoded(byte[] raw) throws LicensingException { + LicensedProduct product = new ProductUserRequest(request).product().get(); + return new SafePayload(new PathKeyKeeper(product, request.state()::source), new MD5Hashes()).decode(raw); + } + + static final class License extends DecodedResponse { + + License(NetResponse response, RawRequest request) { + super(response, request, Collections.singletonMap(LicensesPackage.eNS_URI, LicensesPackage.eINSTANCE)); + } + + @Override + protected Class target() { + return LicensePack.class; + } + } + + static final class GrantAck extends DecodedResponse { + + GrantAck(NetResponse response, RawRequest request) { + super(response, request, Collections.singletonMap(FloatingPackage.eNS_URI, FloatingPackage.eINSTANCE)); + } + + @Override + protected Class target() { + return GrantAcqisition.class; + } + } + +} diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveAcquiringTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveAcquiringTest.java index ad653676f..13f73b10c 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveAcquiringTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveAcquiringTest.java @@ -28,12 +28,14 @@ import org.eclipse.passage.lbc.internal.base.acquire.Acquisition; import org.eclipse.passage.lbc.internal.base.acquire.NoGrantsAvailable; import org.eclipse.passage.lbc.internal.base.api.FloatingState; +import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.PassageAction; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; import org.junit.Test; +@SuppressWarnings("restriction") public final class ExtensiveAcquiringTest { private final TestData data = new TestData(); @@ -94,9 +96,14 @@ public NetResponse call() throws Exception { return new Acquisition(request()).get(); } - private ProductUserRequest request() throws LicensingException { - return new ProductUserRequest(new FeatureRequest(// - new PassageAction.Acquire(), data.product(), data.feature(), data.albert().id(), state).get()); + private ProductUserRequest request() throws LicensingException { + return new ProductUserRequest<>(new FeatureRequest(// + new PassageAction.Acquire(), // + data.product(), // + data.feature(), // + data.albert().id(), // + data.hash(), // + state).get()); } } diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveReleaseTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveReleaseTest.java index d3c5e776b..2f5943d95 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveReleaseTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveReleaseTest.java @@ -17,7 +17,6 @@ import java.io.IOException; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -33,15 +32,15 @@ import org.eclipse.passage.lbc.internal.base.acquire.Acquisition; import org.eclipse.passage.lbc.internal.base.acquire.NoGrantsAvailable; import org.eclipse.passage.lbc.internal.base.api.FloatingState; +import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.floating.model.api.GrantAcqisition; -import org.eclipse.passage.lic.floating.model.meta.FloatingPackage; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.PassageAction; -import org.eclipse.passage.lic.internal.emf.EObjectFromBytes; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; import org.junit.Test; +@SuppressWarnings("restriction") public final class ExtensiveReleaseTest { private final TestData data = new TestData(); @@ -95,12 +94,13 @@ private ProtectedAction(FloatingState state) { @Override public Result call() throws Exception { - NetResponse acq = new Acquisition(acquireRequest()).get(); + ProductUserRequest request = acquireRequest(); + NetResponse acq = new Acquisition(request).get(); if (acq.failed() && (noGrants == acq.error().code())) { return Result.NotGainedNotExecuted; } if (!acq.failed()) { - GrantAcqisition acquisition = acquisition(acq); + GrantAcqisition acquisition = acquisition(acq, request); Thread.sleep(1000); // emulating a protected action work NetResponse rel = new Acquisition(releaseRequest(acquisition)).returnBack(); if (!rel.failed()) { @@ -110,21 +110,30 @@ public Result call() throws Exception { return Result.Weird; } - private ProductUserRequest acquireRequest() throws LicensingException { - return new ProductUserRequest(new FeatureRequest(// - new PassageAction.Acquire(), data.product(), data.feature(), data.albert().id(), state).get()); + private ProductUserRequest acquireRequest() throws LicensingException { + return new ProductUserRequest<>(new FeatureRequest(// + new PassageAction.Acquire(), // + data.product(), // + data.feature(), // + data.albert().id(), // + data.hash(), // + state).get()); } - private ProductUserRequest releaseRequest(GrantAcqisition acquisition) throws LicensingException { - return new ProductUserRequest(new FeatureRequest(// - new PassageAction.Acquire(), data.product(), data.feature(), data.elder().id(), acquisition, state) - .get()); + private ProductUserRequest releaseRequest(GrantAcqisition acquisition) throws LicensingException { + return new ProductUserRequest<>(new FeatureRequest(// + new PassageAction.Acquire(), // + data.product(), // + data.feature(), // + data.elder().id(), // + data.hash(), // + acquisition, // + state).get()); } - private GrantAcqisition acquisition(NetResponse response) throws LicensingException, IOException { - byte[] payload = response.payload(); - return new EObjectFromBytes<>(payload, GrantAcqisition.class)// - .get(Collections.singletonMap(FloatingPackage.eNS_URI, FloatingPackage.eINSTANCE)); + private GrantAcqisition acquisition(NetResponse response, ProductUserRequest request) + throws LicensingException, IOException { + return new DecodedResponse.GrantAck(response, request.raw()).get(); } } diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FeatureRequest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FeatureRequest.java index 4f59aed53..9c5009bb3 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FeatureRequest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FeatureRequest.java @@ -21,47 +21,48 @@ import org.eclipse.passage.lbc.internal.base.api.FloatingState; import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.floating.model.meta.FloatingPackage; -import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationExpression; -import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationType; -import org.eclipse.passage.lic.internal.api.PassageAction; -import org.eclipse.passage.lic.internal.api.EvaluationType; import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.LicensingException; +import org.eclipse.passage.lic.internal.api.PassageAction; import org.eclipse.passage.lic.internal.base.FeatureIdentifier; import org.eclipse.passage.lic.internal.base.ProductIdentifier; import org.eclipse.passage.lic.internal.base.ProductVersion; import org.eclipse.passage.lic.internal.emf.EObjectToBytes; import org.eclipse.passage.lic.internal.net.LicenseUser; +@SuppressWarnings("restriction") final class FeatureRequest { private final PassageAction action; private final LicensedProduct product; private final String feature; private final String user; + private final String algo; private final Optional payload; private final FloatingState state; - FeatureRequest(PassageAction action, LicensedProduct product, String feature, String user, FloatingState state) { - this(action, product, feature, user, Optional.empty(), state); + FeatureRequest(PassageAction action, LicensedProduct product, String feature, String user, String algo, + FloatingState state) { + this(action, product, feature, user, algo, Optional.empty(), state); } - FeatureRequest(PassageAction action, LicensedProduct product, String feature, String user, EObject payload, - FloatingState state) { - this(action, product, feature, user, Optional.of(payload), state); + FeatureRequest(PassageAction action, LicensedProduct product, String feature, String user, String algo, + EObject payload, FloatingState state) { + this(action, product, feature, user, algo, Optional.of(payload), state); } - FeatureRequest(PassageAction action, LicensedProduct product, String feature, String user, + FeatureRequest(PassageAction action, LicensedProduct product, String feature, String user, String algo, Optional payload) { - this(action, product, feature, user, payload, new EagerFloatingState()); + this(action, product, feature, user, algo, payload, new EagerFloatingState(new TestLicFolder())); } - FeatureRequest(PassageAction action, LicensedProduct product, String feature, String user, + FeatureRequest(PassageAction action, LicensedProduct product, String feature, String user, String algo, Optional payload, FloatingState state) { this.action = action; this.product = product; this.feature = feature; this.user = user; + this.algo = algo; this.payload = payload; this.state = state; } @@ -73,14 +74,12 @@ public RawRequest get() throws LicensingException { new ProductIdentifier(product), // new ProductVersion(product), // new LicenseUser(user), // - new FeatureIdentifier(feature), // - new ServerAuthenticationType(new EvaluationType.Hardware().identifier()), // - new ServerAuthenticationExpression("os.family=*"))) //$NON-NLS-1$ + new FeatureIdentifier(feature))) // .withState(state); if (payload.isPresent()) { construct.withContent(raw(payload.get())); } - return construct.get(); + return construct.getValid(); } private byte[] raw(EObject obj) throws LicensingException { diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FloatingCycleActionsDryRunTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FloatingCycleActionsDryRunTest.java index 9b71d665a..451db776f 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FloatingCycleActionsDryRunTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FloatingCycleActionsDryRunTest.java @@ -18,8 +18,13 @@ import java.io.IOException; import java.util.Date; +import java.util.List; import java.util.Optional; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.passage.lbc.internal.base.FlotingRequestHandled; import org.eclipse.passage.lbc.internal.base.acquire.NoGrantsAvailable; @@ -27,31 +32,38 @@ import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.floating.model.api.GrantAcqisition; import org.eclipse.passage.lic.floating.model.meta.FloatingFactory; -import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.PassageAction; -import org.eclipse.passage.lic.internal.base.BaseLicensedProduct; +import org.eclipse.passage.lic.internal.base.FeatureIdentifier; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; +import org.eclipse.passage.lic.licenses.model.api.LicenseGrant; import org.junit.Test; +@SuppressWarnings("restriction") public final class FloatingCycleActionsDryRunTest { - private final LicensedProduct product = new BaseLicensedProduct("proj", "1.2.3"); //$NON-NLS-1$ //$NON-NLS-2$ - private final String feature = "erutaef"; //$NON-NLS-1$ - private final String user = "resu"; //$NON-NLS-1$ + private final TestData data = new TestData(); @Test public void mineNothing() throws LicensingException, IOException { - NetResponse response = new FlotingRequestHandled(request(new PassageAction.Mine())).get(); + RawRequest request = request(new PassageAction.Mine()); + NetResponse response = new FlotingRequestHandled(request).get(); assertFalse(response.failed()); - assertTrue(new License(response).get().getLicenseGrants().isEmpty()); + EList grants = new DecodedResponse.License(response, request).get().getLicenseGrants(); + assertTrue(ofFeature(grants, request).isEmpty()); + } + + private List ofFeature(EList grants, RawRequest request) { + String feature = new FeatureIdentifier((Function) request::parameter).get().get(); + Predicate featured = grant -> feature.equals(grant.getFeatureIdentifier()); + return grants.stream().filter(featured).collect(Collectors.toList()); } @Test public void acquireNothing() throws LicensingException, IOException { NetResponse response = new FlotingRequestHandled(request(new PassageAction.Acquire())).get(); assertTrue(response.failed()); - assertEquals(new NoGrantsAvailable(product, feature).error().code(), response.error().code()); + assertEquals(new NoGrantsAvailable(data.product(), data.feature()).error().code(), response.error().code()); } @Test @@ -60,7 +72,7 @@ public void releaseInVain() throws LicensingException, IOException { NetResponse response = new FlotingRequestHandled(// request(new PassageAction.Release(), Optional.of(acqisition))).get(); assertTrue(response.failed()); - assertEquals(new NotReleased(product, acqisition).error().code(), response.error().code()); + assertEquals(new NotReleased(data.product(), acqisition).error().code(), response.error().code()); } private RawRequest request(PassageAction action) throws LicensingException { @@ -68,17 +80,28 @@ private RawRequest request(PassageAction action) throws LicensingException { } private RawRequest request(PassageAction action, Optional payload) throws LicensingException { - return new FeatureRequest(action, product, feature, user, payload).get(); + return new FeatureRequest(// + action, // + data.product(), // + feature(), // + data.albert().id(), // + data.hash(), // + payload// + ).get(); } private GrantAcqisition acquisition() { GrantAcqisition acqisition = FloatingFactory.eINSTANCE.createGrantAcqisition(); acqisition.setIdentifier("fake-acquisition-id"); //$NON-NLS-1$ - acqisition.setFeature(feature); + acqisition.setFeature(feature()); acqisition.setGrant("fake-grant-id"); //$NON-NLS-1$ acqisition.setCreated(new Date()); - acqisition.setUser(user); + acqisition.setUser(data.albert().id()); return acqisition; } + private String feature() { + return data.feature() + ".not"; //$NON-NLS-1$ + } + } diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/License.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/License.java deleted file mode 100644 index a8a466513..000000000 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/License.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 ArSysOp - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * https://www.eclipse.org/legal/epl-2.0/. - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * ArSysOp - initial API and implementation - *******************************************************************************/ -package org.eclipse.passage.lbc.base.tests; - -import java.io.IOException; - -import org.eclipse.passage.lic.internal.api.LicensingException; -import org.eclipse.passage.lic.internal.emf.EObjectFromBytes; -import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; -import org.eclipse.passage.lic.licenses.model.api.LicensePack; - -final class License { - - private final NetResponse response; - - License(NetResponse response) { - this.response = response; - } - - LicensePack get() throws IOException, LicensingException { - return new EObjectFromBytes<>(response.payload(), LicensePack.class).get(); - } - -} diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/MineTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/MineTest.java index cb4de8ede..2586f436c 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/MineTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/MineTest.java @@ -51,7 +51,7 @@ public void demandsUser() { version(), // authType(), // authExpression()// - )).get()// + )).getPure()// ).get(); assertFailedWithCode(response, new Failure.BadRequestNoUser()); } @@ -64,7 +64,7 @@ private void testDemandProductInformation(StringNamedData half) { half, // authType(), // authExpression()// - )).get()// + )).getPure()// ).get(); assertFailedWithCode(response, new Failure.BadRequestInvalidProduct()); } diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/RequestConstructed.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/RequestConstructed.java index be783c8b9..a2c65b9d0 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/RequestConstructed.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/RequestConstructed.java @@ -13,25 +13,37 @@ package org.eclipse.passage.lbc.base.tests; import java.io.IOException; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import java.util.function.Supplier; +import org.eclipse.passage.lbc.internal.base.EagerFloatingState; import org.eclipse.passage.lbc.internal.base.api.FloatingState; import org.eclipse.passage.lbc.internal.base.api.RawRequest; +import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationExpression; +import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationType; +import org.eclipse.passage.lic.internal.api.EvaluationType; import org.eclipse.passage.lic.internal.api.PassageAction; +import org.eclipse.passage.lic.internal.base.NamedData; import org.eclipse.passage.lic.internal.base.StringNamedData; +import org.eclipse.passage.lic.internal.base.io.MD5Hashes; +import org.eclipse.passage.lic.internal.net.EncodingAlgorithm; import org.eclipse.passage.lic.internal.net.LicensingAction; -final class RequestConstructed implements Supplier { +@SuppressWarnings("restriction") +final class RequestConstructed { private Map params = new HashMap<>(); private byte[] content; private FloatingState state; - RequestConstructed withParameters(Collection data) { - data.forEach(p -> params.put(p.key(), p.get().get())); + RequestConstructed() { + this.state = new EagerFloatingState(new TestLicFolder()); + } + + RequestConstructed withParameters(Collection> data) { + data.forEach(p -> params.put(p.key(), p.get().get().toString())); return this; } @@ -52,15 +64,27 @@ RequestConstructed withContent(byte[] bytes) { } RequestConstructed withState(FloatingState st) { - this.state = st; + this.state = new EagerFloatingState(st.grants(), new TestLicFolder().get()); return this; } - @Override - public RawRequest get() { + RawRequest getValid() { + addPredefinedParams(); + return getPure(); + } + + RawRequest getPure() { return new Franky(params, content, state); } + private void addPredefinedParams() { + Arrays.asList(// + new ServerAuthenticationType(new EvaluationType.Hardware().identifier()), // + new ServerAuthenticationExpression("os.family=*"), //$NON-NLS-1$ + new EncodingAlgorithm(new MD5Hashes().id().toString()) // + ).forEach(param -> params.put(param.key(), param.get().get())); + } + private static final class Franky implements RawRequest { private final Map params; diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ServerAuthenticationTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ServerAuthenticationTest.java index 417c43ed7..11f5a3635 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ServerAuthenticationTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ServerAuthenticationTest.java @@ -41,7 +41,8 @@ private void testDemandServerAuthInformation(StringNamedData half) { NetResponse response = new FlotingRequestHandled(// new RequestConstructed()// .withAction(new PassageAction.Mine())// - .withParameter(half).get()// + .withParameter(half)// + .getPure()// ).get(); assertFailedWithCode(response, new Failure.BadRequestInvalidServerAuthInstructions()); } diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/TestData.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/TestData.java index f7a1cdb2d..4bdd20eeb 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/TestData.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/TestData.java @@ -21,6 +21,7 @@ import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.base.BaseLicensedProduct; +import org.eclipse.passage.lic.internal.base.io.MD5Hashes; import org.eclipse.passage.lic.licenses.model.api.LicenseGrant; public final class TestData { @@ -68,6 +69,11 @@ public User elder() { return elder; } + @SuppressWarnings("restriction") + public String hash() { + return new MD5Hashes().id().toString(); + } + final static class User { private final String id; diff --git a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/AcquireTest.java b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/AcquireTest.java index 13ef0148f..e4dc76f2d 100644 --- a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/AcquireTest.java +++ b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/AcquireTest.java @@ -29,6 +29,7 @@ import org.eclipse.passage.lic.internal.hc.remote.impl.acquire.RemoteAcquisitionService; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; +import org.junit.Ignore; import org.junit.Test; @SuppressWarnings("restriction") @@ -38,6 +39,7 @@ public final class AcquireTest { private final Supplier source = new TestLicFolder(); private final FloatingState server = new EagerFloatingState(source); + @Ignore @Test public void acquireAndRelease() { RemoteAcquisitionService service = // @@ -47,7 +49,6 @@ public void acquireAndRelease() { assertTrue(acquisition.data().isPresent()); ServiceInvocationResult release = service.release(data.product(), acquisition.data().get()); assertTrue(release.data().isPresent()); - } private Client acq() { diff --git a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/MineTest.java b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/MineTest.java index 2584bb515..2d7fe3efe 100644 --- a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/MineTest.java +++ b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/MineTest.java @@ -31,7 +31,6 @@ import org.eclipse.passage.lic.internal.hc.remote.impl.mine.RemoteConditions; import org.eclipse.passage.lic.internal.net.api.handle.NetResponse; import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; -import org.junit.Ignore; import org.junit.Test; @SuppressWarnings("restriction") @@ -40,7 +39,6 @@ public final class MineTest { private final TestData data = new TestData(); private final Supplier source = new TestLicFolder(); - @Ignore @Test public void mine() { ServiceInvocationResult> all = new RemoteConditions<>(// @@ -58,7 +56,7 @@ private final class AskMiner implements ShortcutClient.Remote { @Override public NetResponse invoke(RawRequest raw) throws LicensingException { - return new Conditions(new ProductUserRequest(raw), source).get(); + return new Conditions(new ProductUserRequest(raw)).get(); } @Override diff --git a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/ShortcutClient.java b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/ShortcutClient.java index 5bbac3c51..c9a677215 100644 --- a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/ShortcutClient.java +++ b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/remote/ShortcutClient.java @@ -16,6 +16,7 @@ import static org.junit.Assert.fail; import org.eclipse.passage.lbc.base.tests.TestData; +import org.eclipse.passage.lbc.internal.base.EagerFloatingState; import org.eclipse.passage.lbc.internal.base.api.FloatingState; import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.internal.api.LicensingException; @@ -42,7 +43,7 @@ final class ShortcutClient implements Client { public ServiceInvocationResult request(Request request, ResponseHandler handler) { try { ShortcutConnection connection = request.config().apply(new ShortcutConnection(request.parameters())); - RawRequest raw = new RawRequestFromConnection(connection, remote.state()); + RawRequest raw = new RawRequestFromConnection(connection, state()); NetResponse response = remote.invoke(raw); assertFalse(response.failed()); connection.installResponse(response); @@ -55,6 +56,10 @@ public ServiceInvocationResult request(Request request, R } } + private EagerFloatingState state() { + return new EagerFloatingState(remote.state().grants(), new TestLicFolder().get()); + } + static interface Remote { FloatingState state();