From be47709ab5b3e7d1e28c10d7b6979b16f71d8a5b Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Sun, 8 Nov 2020 21:14:35 +0300 Subject: [PATCH 1/3] Bug 568620 Update RemoteConditions miner to current FLS protocol Gather all the mined conditions from each available server connection Signed-off-by: eparovyshnaya --- .../META-INF/MANIFEST.MF | 2 +- .../hc/remote/impl/DecryptedConditions.java | 20 +++++------ .../internal/hc/remote/impl/HttpClient.java | 10 ++++-- .../hc/remote/impl/RemoteConditions.java | 35 +++++++++++-------- .../demo/SealedAccessCycleConfiguration.java | 2 +- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.hc/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.hc/META-INF/MANIFEST.MF index 2340e99ab..0330e15c0 100644 --- a/bundles/org.eclipse.passage.lic.hc/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.hc/META-INF/MANIFEST.MF @@ -18,7 +18,7 @@ Require-Bundle: org.apache.httpcomponents.httpcore;bundle-version="0.0.0", org.eclipse.passage.lic.net;bundle-version="0.0.0", org.eclipse.passage.lic.floating;bundle-version="0.1.0", org.eclipse.passage.lic.floating.model;bundle-version="0.1.0", - org.eclipse.emf.ecore.xmi + org.eclipse.emf.ecore.xmi;bundle-version="2.16.0" Export-Package: org.eclipse.passage.lic.internal.hc.remote;x-internal:=true, org.eclipse.passage.lic.internal.hc.remote.impl;x-internal:=true Bundle-ActivationPolicy: lazy diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java index e8f4eddc0..72b69305b 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java @@ -17,6 +17,7 @@ import java.util.Collection; import java.util.Collections; +import org.eclipse.passage.lic.floating.model.api.FloatingServerConnection; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.conditions.ConditionPack; import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionTransport; @@ -29,9 +30,11 @@ final class DecryptedConditions implements ResponseHandler { private final ConditionTransportRegistry transports; + private final FloatingServerConnection coordinates; - DecryptedConditions(ConditionTransportRegistry transports) { + DecryptedConditions(ConditionTransportRegistry transports, FloatingServerConnection coordinates) { this.transports = transports; + this.coordinates = coordinates; } /** @@ -40,22 +43,19 @@ final class DecryptedConditions implements ResponseHandler { */ @Override public Collection read(byte[] raw, String contentType) throws LicensingException { - try (ByteArrayInputStream stream = new ByteArrayInputStream(keyDecoded(base64Decoded(raw)))) { + try (ByteArrayInputStream stream = new ByteArrayInputStream(raw)) { return Collections.singleton(// new BaseConditionPack(// - "net", //$NON-NLS-1$ - transport(new ContentType.Of(contentType)).read(stream))); + source(), // + transport(new ContentType.Of(contentType)).read(stream)// + )); } catch (IOException e) { throw new LicensingException(HcMessages.DecryptedConditions_reading_error, e); } } - private byte[] base64Decoded(byte[] raw) throws LicensingException { - return raw; // FIXME: implement - } - - private byte[] keyDecoded(byte[] data) throws LicensingException { - return data; // FIXME: implement + private String source() { + return String.format("net:%s:%d", coordinates.getIp(), coordinates.getPort());//$NON-NLS-1$ } private ConditionTransport transport(ContentType contentType) throws LicensingException { diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpClient.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpClient.java index a7ec34e92..0c593fd06 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpClient.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpClient.java @@ -15,11 +15,13 @@ import java.io.InputStream; import java.net.HttpURLConnection; import java.util.Collection; +import java.util.Collections; import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; import org.eclipse.passage.lic.internal.api.conditions.ConditionPack; import org.eclipse.passage.lic.internal.api.diagnostic.Trouble; import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; +import org.eclipse.passage.lic.internal.base.diagnostic.BaseDiagnostic; import org.eclipse.passage.lic.internal.base.diagnostic.code.ServiceFailedOnInfrastructureDenial; import org.eclipse.passage.lic.internal.hc.i18n.HcMessages; import org.eclipse.passage.lic.internal.hc.remote.Client; @@ -35,8 +37,12 @@ public ServiceInvocationResult> remoteConditions(Reque return new BaseServiceInvocationResult>( netConditions(connection(request), miner)); } catch (Exception e) { - return new BaseServiceInvocationResult<>(new Trouble(new ServiceFailedOnInfrastructureDenial(), - HcMessages.HttpClient_final_error_message, e)); + return new BaseServiceInvocationResult<>(// + new BaseDiagnostic(// + Collections.emptyList(), // + Collections.singletonList(// + new Trouble(new ServiceFailedOnInfrastructureDenial(), + HcMessages.HttpClient_final_error_message, e)))); } } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditions.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditions.java index 9101f6184..b27bdc6f3 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditions.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditions.java @@ -13,6 +13,7 @@ package org.eclipse.passage.lic.internal.hc.remote.impl; import java.util.Collection; +import java.util.Collections; import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess; import org.eclipse.passage.lic.internal.api.LicensedProduct; @@ -28,6 +29,7 @@ import org.eclipse.passage.lic.internal.api.io.StreamCodecRegistry; import org.eclipse.passage.lic.internal.api.registry.StringServiceId; import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; +import org.eclipse.passage.lic.internal.base.SumOfCollections; import org.eclipse.passage.lic.internal.base.diagnostic.NoSevereErrors; import org.eclipse.passage.lic.internal.base.diagnostic.code.ServiceCannotOperate; import org.eclipse.passage.lic.internal.hc.i18n.MinerMessages; @@ -35,17 +37,14 @@ public final class RemoteConditions implements MinedConditions { private final ConditionTransportRegistry transports; - private final LicensedProduct product; private final KeyKeeperRegistry keys; private final StreamCodecRegistry codecs; private final StringServiceId id = new StringServiceId("remote"); //$NON-NLS-1$ - public RemoteConditions(LicensedProduct product, ConditionTransportRegistry transports, KeyKeeperRegistry keys, - StreamCodecRegistry codecs) { - this.product = product; - this.transports = transports; + public RemoteConditions(KeyKeeperRegistry keys, StreamCodecRegistry codecs, ConditionTransportRegistry transports) { this.keys = keys; this.codecs = codecs; + this.transports = transports; } @Override @@ -58,34 +57,40 @@ public ServiceInvocationResult> all(LicensedProduct pr KeyKeeper key; StreamCodec codec; try { - codec = codec(); - key = key(); + codec = codec(product); + key = key(product); } catch (LicensingException e) { return new BaseServiceInvocationResult<>(new Trouble(new ServiceCannotOperate(), MinerMessages.RemoteConditions_insfficient_configuration, e)); } + ServiceInvocationResult> accesses = // new AccessPacks(product, key, codec).get(); if (!new NoSevereErrors().test(accesses.diagnostic())) { return new BaseServiceInvocationResult<>(accesses.diagnostic()); } - for (FloatingLicenseAccess access : accesses.data().get()) { - new HttpClient().remoteConditions(// - new RemoteConditionsRequest(product, access), // - new DecryptedConditions(transports)); - } - return null; + return accesses.data().get().stream()// + .map(access -> conditions(product, access))// + .reduce(new BaseServiceInvocationResult.Sum<>(new SumOfCollections<>()))// + .orElse(new BaseServiceInvocationResult<>(Collections.emptyList())); + } + + private ServiceInvocationResult> conditions(LicensedProduct product, + FloatingLicenseAccess access) { + return new HttpClient().remoteConditions(// + new RemoteConditionsRequest(product, access), // + new DecryptedConditions(transports, access.getServer())); } - private KeyKeeper key() throws LicensingException { + private KeyKeeper key(LicensedProduct product) throws LicensingException { if (!keys.get().hasService(product)) { throw new LicensingException(String.format(MinerMessages.RemoteConditions_no_key_keeper, product)); } return keys.get().service(product); } - private StreamCodec codec() throws LicensingException { + private StreamCodec codec(LicensedProduct product) throws LicensingException { if (!codecs.get().hasService(product)) { throw new LicensingException(String.format(MinerMessages.RemoteConditions_no_stream_codec, product)); } diff --git a/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/SealedAccessCycleConfiguration.java b/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/SealedAccessCycleConfiguration.java index 03345dcd9..d001b2fc0 100644 --- a/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/SealedAccessCycleConfiguration.java +++ b/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/SealedAccessCycleConfiguration.java @@ -86,7 +86,7 @@ final class SealedAccessCycleConfiguration implements AccessCycleConfiguration { new ComponentRequirements() // )); conditions = new ReadOnlyRegistry<>(Arrays.asList(// - // new RemoteConditions(transports()), // + // new RemoteConditions(keyKeepers(), codecs(), transports()), // new UserHomeResidentConditions(miningEquipment()), // new InstallationResidentConditions(miningEquipment()), // new ConfigurationResidentConditions(miningEquipment())// From 3788a5f97b8c16b81de17492061cecdea60b99f2 Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Sun, 8 Nov 2020 21:20:47 +0300 Subject: [PATCH 2/3] Bug 568620 Update RemoteConditions miner to current FLS protocol eliminate redundant request query parameter Signed-off-by: eparovyshnaya --- .../passage/lic/internal/hc/remote/impl/RequestParameters.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java index 4f8aae505..7d3bdd228 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java @@ -19,14 +19,12 @@ import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess; import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.conditions.ConditionAction; -import org.eclipse.passage.lic.internal.api.conditions.UserRole; import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType; import org.eclipse.passage.lic.internal.base.NamedData; import org.eclipse.passage.lic.internal.base.ProductIdentifier; import org.eclipse.passage.lic.internal.base.ProductVersion; import org.eclipse.passage.lic.internal.base.conditions.mining.LicensingContentType; import org.eclipse.passage.lic.internal.net.LicensingAction; -import org.eclipse.passage.lic.internal.net.LicensingRole; final class RequestParameters { @@ -53,7 +51,6 @@ private NamedData[] parameters() throws UnsupportedEncodingException { new ProductIdentifier(encode(product.identifier())), // new ProductVersion(encode(product.version())), // new LicensingAction(new ConditionAction.Aquire()), // - new LicensingRole(new UserRole.Admin()), // new LicensingContentType(new ContentType.Xml()), // new LicenseUser(access.getUser()), // new ServerAuthenticationType(access.getServer()), // From 3d9775df4f3950aa06d6127d81aebbd8fa9cadf9 Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Sun, 8 Nov 2020 21:48:57 +0300 Subject: [PATCH 3/3] Bug 568620 Update RemoteConditions miner to current FLS protocol Eliminate redundant request query parameter from the corresponding test as well. Replenish test with new parameters. Signed-off-by: eparovyshnaya --- .../hc/remote/impl/ServerAuthenticationExpression.java | 6 +++--- .../internal/hc/remote/impl/ServerAuthenticationType.java | 6 +++--- .../lic/internal/hc/tests/RemoteConditionsRequestTest.java | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/ServerAuthenticationExpression.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/ServerAuthenticationExpression.java index e910fd108..f953340fa 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/ServerAuthenticationExpression.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/ServerAuthenticationExpression.java @@ -15,13 +15,13 @@ import org.eclipse.passage.lic.floating.model.api.FloatingServerConnection; import org.eclipse.passage.lic.internal.base.StringNamedData; -final class ServerAuthenticationExpression extends StringNamedData { +public final class ServerAuthenticationExpression extends StringNamedData { - ServerAuthenticationExpression(String value) { + public ServerAuthenticationExpression(String value) { super(value); } - ServerAuthenticationExpression(FloatingServerConnection server) { + public ServerAuthenticationExpression(FloatingServerConnection server) { this(server.getAuthentication().getExpression()); } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/ServerAuthenticationType.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/ServerAuthenticationType.java index 1c11f1878..50b684dc8 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/ServerAuthenticationType.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/ServerAuthenticationType.java @@ -15,13 +15,13 @@ import org.eclipse.passage.lic.floating.model.api.FloatingServerConnection; import org.eclipse.passage.lic.internal.base.StringNamedData; -final class ServerAuthenticationType extends StringNamedData { +public final class ServerAuthenticationType extends StringNamedData { - ServerAuthenticationType(String value) { + public ServerAuthenticationType(String value) { super(value); } - ServerAuthenticationType(FloatingServerConnection server) { + public ServerAuthenticationType(FloatingServerConnection server) { this(server.getAuthentication().getType()); } diff --git a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/RemoteConditionsRequestTest.java b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/RemoteConditionsRequestTest.java index 710bbf63b..cffc21c65 100644 --- a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/RemoteConditionsRequestTest.java +++ b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/RemoteConditionsRequestTest.java @@ -27,15 +27,15 @@ import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.conditions.ConditionAction; -import org.eclipse.passage.lic.internal.api.conditions.UserRole; import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType; import org.eclipse.passage.lic.internal.base.BaseLicensedProduct; import org.eclipse.passage.lic.internal.base.ProductIdentifier; import org.eclipse.passage.lic.internal.base.ProductVersion; import org.eclipse.passage.lic.internal.base.conditions.mining.LicensingContentType; import org.eclipse.passage.lic.internal.hc.remote.impl.RemoteConditionsRequest; +import org.eclipse.passage.lic.internal.hc.remote.impl.ServerAuthenticationExpression; +import org.eclipse.passage.lic.internal.hc.remote.impl.ServerAuthenticationType; import org.eclipse.passage.lic.internal.net.LicensingAction; -import org.eclipse.passage.lic.internal.net.LicensingRole; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -60,7 +60,8 @@ public void urlContainsAllParameters() throws IOException { assertTrue(url.getQuery().contains(new ProductIdentifier("any").key())); //$NON-NLS-1$ assertTrue(url.getQuery().contains(new ProductVersion("any").key())); //$NON-NLS-1$ assertTrue(url.getQuery().contains(new LicensingAction(new ConditionAction.Of("any")).key())); //$NON-NLS-1$ - assertTrue(url.getQuery().contains(new LicensingRole(new UserRole.Of("any")).key())); //$NON-NLS-1$ + assertTrue(url.getQuery().contains(new ServerAuthenticationExpression("any").key())); //$NON-NLS-1$ + assertTrue(url.getQuery().contains(new ServerAuthenticationType("any").key())); //$NON-NLS-1$ assertTrue(url.getQuery().contains("user")); //$NON-NLS-1$ assertTrue(url.getQuery().contains(new LicensingContentType(new ContentType.Of("any")).key())); //$NON-NLS-1$ }