Skip to content

Commit

Permalink
Merge pull request #529 from eclipse-passage/568620
Browse files Browse the repository at this point in the history
Bug 568620 Update RemoteConditions miner to current FLS protocol
  • Loading branch information
eparovyshnaya authored Nov 8, 2020
2 parents abafdf6 + 3d9775d commit 96817b6
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 41 deletions.
2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.lic.hc/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -40,22 +43,19 @@ final class DecryptedConditions implements ResponseHandler {
*/
@Override
public Collection<ConditionPack> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,8 +37,12 @@ public ServiceInvocationResult<Collection<ConditionPack>> remoteConditions(Reque
return new BaseServiceInvocationResult<Collection<ConditionPack>>(
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))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,24 +29,22 @@
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;

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
Expand All @@ -58,34 +57,40 @@ public ServiceInvocationResult<Collection<ConditionPack>> 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<Collection<FloatingLicenseAccess>> 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<Collection<ConditionPack>> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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()), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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$
}
Expand Down

0 comments on commit 96817b6

Please sign in to comment.