Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 568632 Implement feature grant acquire/release #536

Merged
merged 2 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Export-Package: org.eclipse.passage.lic.internal.base;
org.eclipse.passage.lic.equinox,
org.eclipse.passage.lic.hc,
org.eclipse.passage.lic.jface,
org.eclipse.passage.loc.licenses.core",
org.eclipse.passage.loc.licenses.core,
org.eclipse.passage.lic.net",
org.eclipse.passage.lic.internal.base.access;x-internal:=true,
org.eclipse.passage.lic.internal.base.conditions;
x-friends:="org.eclipse.passage.lbc.base,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* 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.lic.internal.base;

import java.util.Map;
import java.util.function.Function;

/**
* Supplies an {@code identifier} of a feature under licensing, which is
* expected to be stored in a variety of sources under a special key.
*
* @see NamedData
*/
public final class FeatureIdentifier extends StringNamedData {

public FeatureIdentifier(String value) {
super(value);
}

public FeatureIdentifier(Map<String, Object> values) {
super(values);
}

public FeatureIdentifier(Function<String, String> retriever) {
super(retriever);
}

@Override
public String key() {
return "licensing.feature.identifier"; //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Export-Package: org.eclipse.passage.lic.floating.model.api;
org.eclipse.passage.loc.dashboard.ui,
org.eclipse.passage.loc.api,
org.eclipse.passage.loc.licenses.core,
org.eclipse.passage.lic.hc",
org.eclipse.passage.lic.hc,
org.eclipse.passage.lic.net",
org.eclipse.passage.lic.floating.model.impl;x-internal:=true,
org.eclipse.passage.lic.floating.model.meta;
x-friends:="org.eclipse.passage.lic.floating.e4.ui,
org.eclipse.passage.lic.floating.edit,
org.eclipse.passage.loc.licenses.core,
org.eclipse.passage.loc.floating.emfforms,
org.eclipse.passage.loc.dashboard.ui",
org.eclipse.passage.lic.floating.model.util;x-friends:="org.eclipse.passage.lic.floating.edit",
org.eclipse.passage.lic.internal.floating.model;x-friends:="org.eclipse.passage.loc.dashboard.ui"
org.eclipse.passage.lic.floating.model.util;x-friends:="org.eclipse.passage.lic.floating.edit"
Bundle-ClassPath: .
Bundle-ActivationPolicy: lazy

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public final class AccessMessages extends NLS {
public static String AccessPacks_unexpected_amount;
public static String AccessPacks_unexpected_type;
public static String AccessPacks_files_gaining_failed;

public static String MineRequestParameters_encoding_failed;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, AccessMessages.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ AccessPacks_failed_xmi_read=Reading xmi content failed
AccessPacks_unexpected_amount=Unexpected amount of contents in Floating License Access file: %d
AccessPacks_unexpected_type=Unexpected content: %s
AccessPacks_files_gaining_failed = Failed to locate Floating License Access files
MineRequestParameters_encoding_failed=Failed to encode url query parameter value [%s] to UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.passage.lic.internal.base.io.UserHomePath;

final class AccessFiles {

private final LicensedProduct product;

public AccessFiles(LicensedProduct product) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
import org.eclipse.passage.lic.internal.base.diagnostic.code.ServiceFailedOnMorsel;
import org.eclipse.passage.lic.internal.hc.i18n.AccessMessages;

final class AccessPacks implements Supplier<ServiceInvocationResult<Collection<FloatingLicenseAccess>>> {
public final class AccessPacks implements Supplier<ServiceInvocationResult<Collection<FloatingLicenseAccess>>> {

private final LicensedProduct product;
private final KeyKeeper key;
private final StreamCodec codec;

AccessPacks(LicensedProduct product, KeyKeeper key, StreamCodec codec) {
public AccessPacks(LicensedProduct product, KeyKeeper key, StreamCodec codec) {
this.product = product;
this.key = key;
this.codec = codec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.passage.lic.internal.net.LicensingServerCoordinates;

final class FloatingServerCoordinates implements LicensingServerCoordinates {

private final FloatingLicenseAccess access;

FloatingServerCoordinates(FloatingLicenseAccess access) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*******************************************************************************/
package org.eclipse.passage.lic.internal.hc.remote.impl;

import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -37,12 +36,12 @@
* <li>{@code config()} to gain a proper request headers configuring unit</li>
* </ul>
*/
public final class RemoteConditionsRequest implements Request<HttpURLConnection> {
public abstract class RemoteRequest implements Request<HttpURLConnection> {

private final LicensedProduct product;
private final FloatingLicenseAccess access;
protected final LicensedProduct product;
protected final FloatingLicenseAccess access;

public RemoteConditionsRequest(LicensedProduct product, FloatingLicenseAccess access) {
public RemoteRequest(LicensedProduct product, FloatingLicenseAccess access) {
this.product = product;
this.access = access;
}
Expand All @@ -54,15 +53,16 @@ public URL url() throws LicensingException {
return new URL("http", //$NON-NLS-1$
corrdinates.host(), //
Integer.parseInt(corrdinates.port()), //
new MineRequestParameters(product, access).query());
parameters().query());
} catch (LicensingException //
| NumberFormatException //
| MalformedURLException //
| UnsupportedEncodingException e) {
| MalformedURLException e) {
throw new LicensingException(HcMessages.RemoteConditionsRequest_failed_to_compose_url, e);
}
}

protected abstract RequestParameters parameters();

@Override
public Configuration<HttpURLConnection> config() {
return new HttpUrlConnectionConfiguration(1000, new HashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,32 @@
import java.net.URLEncoder;
import java.util.Arrays;

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.mining.ContentType;
import org.eclipse.passage.lic.internal.api.LicensingException;
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.hc.i18n.AccessMessages;

final class RequestParameters {
public abstract class RequestParameters {

private final LicensedProduct product;
private final FloatingLicenseAccess access;

RequestParameters(LicensedProduct product, FloatingLicenseAccess access) {
this.product = product;
this.access = access;
protected RequestParameters() {
}

String query() throws UnsupportedEncodingException {
public final String query() throws LicensingException {
StringBuilder params = new StringBuilder();
Arrays.stream(parameters())//
.map(NamedData.Writable<String>::new)//
.forEach(writable -> writable.write(params, "=", "&")); //$NON-NLS-1$ //$NON-NLS-2$
return '?' + params.toString();

}

@SuppressWarnings("rawtypes")
private NamedData[] parameters() throws UnsupportedEncodingException {
return new NamedData[] { //
new ProductIdentifier(encode(product.identifier())), //
new ProductVersion(encode(product.version())), //
new LicensingAction(new ConditionAction.Acquire()), //
new LicensingContentType(new ContentType.Xml()), //
new LicenseUser(access.getUser()), //
new ServerAuthenticationType(access.getServer()), //
new ServerAuthenticationExpression(access.getServer()) };
}

private String encode(String value) throws UnsupportedEncodingException {
return URLEncoder.encode(value, "UTF-8"); //$NON-NLS-1$
protected abstract NamedData[] parameters() throws LicensingException;

protected String encode(String value) throws LicensingException {
try {
return URLEncoder.encode(value, "UTF-8"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
throw new LicensingException(AccessMessages.MineRequestParameters_encoding_failed, e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.hc.remote.impl;
package org.eclipse.passage.lic.internal.hc.remote.impl.mine;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.hc.remote.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
package org.eclipse.passage.lic.internal.hc.remote.impl.mine;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
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.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.hc.remote.impl.RequestParameters;
import org.eclipse.passage.lic.internal.net.LicenseUser;
import org.eclipse.passage.lic.internal.net.LicensingAction;
import org.eclipse.passage.lic.internal.net.ServerAuthenticationExpression;
import org.eclipse.passage.lic.internal.net.ServerAuthenticationType;

final class MineRequestParameters {

final class MineRequestParameters extends RequestParameters {
private final LicensedProduct product;
private final FloatingLicenseAccess access;

Expand All @@ -36,17 +36,9 @@ final class MineRequestParameters {
this.access = access;
}

String query() throws UnsupportedEncodingException {
StringBuilder params = new StringBuilder();
Arrays.stream(parameters())//
.map(NamedData.Writable<String>::new)//
.forEach(writable -> writable.write(params, "=", "&")); //$NON-NLS-1$ //$NON-NLS-2$
return '?' + params.toString();

}

@Override
@SuppressWarnings("rawtypes")
private NamedData[] parameters() throws UnsupportedEncodingException {
protected NamedData[] parameters() throws LicensingException {
return new NamedData[] { //
new ProductIdentifier(encode(product.identifier())), //
new ProductVersion(encode(product.version())), //
Expand All @@ -57,8 +49,4 @@ private NamedData[] parameters() throws UnsupportedEncodingException {
new ServerAuthenticationExpression(access.getServer()) };
}

private String encode(String value) throws UnsupportedEncodingException {
return URLEncoder.encode(value, "UTF-8"); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.hc.remote.impl;
package org.eclipse.passage.lic.internal.hc.remote.impl.mine;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -33,6 +33,8 @@
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;
import org.eclipse.passage.lic.internal.hc.remote.impl.AccessPacks;
import org.eclipse.passage.lic.internal.hc.remote.impl.HttpClient;

public final class RemoteConditions implements MinedConditions {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* 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.lic.internal.hc.remote.impl.mine;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.hc.remote.impl.RemoteRequest;
import org.eclipse.passage.lic.internal.hc.remote.impl.RequestParameters;

public final class RemoteConditionsRequest extends RemoteRequest {

public RemoteConditionsRequest(LicensedProduct product, FloatingLicenseAccess access) {
super(product, access);
}

@Override
protected RequestParameters parameters() {
return new MineRequestParameters(product, access);
}

}
Loading