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 575166 License Agreement management: license issuing #872

Merged
merged 2 commits into from
Aug 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
import org.eclipse.passage.lic.agreements.model.api.Agreement;
import org.eclipse.passage.lic.api.LicensingException;
import org.eclipse.passage.loc.internal.api.workspace.Agreements;
import org.eclipse.passage.loc.internal.equinox.OperatorGearAware;
import org.eclipse.passage.loc.internal.equinox.AgreementsService;
import org.eclipse.passage.loc.workbench.emfforms.renderers.TextWithButtonRenderer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
Expand Down Expand Up @@ -90,7 +88,7 @@ private String reside(File file) throws Exception {
// rename in already defined name if any:
// String name = definedName().orElse(file.getName());
String name = file.getName();
agreements().located(name).write(Files.readAllBytes(file.toPath()));
new AgreementsService().get().located(name).write(Files.readAllBytes(file.toPath()));
return name;
}

Expand Down Expand Up @@ -127,15 +125,6 @@ private Optional<String> definedName() {
}
}

private Agreements agreements() throws LicensingException {
Optional<Agreements> service = new OperatorGearAware()
.withGear(gear -> Optional.of(gear.workspace().agreements()));
if (!service.isPresent()) {
throw new LicensingException("There is no Agreements service supplied by Operator Workspace"); //$NON-NLS-1$
}
return service.get();
}

private Optional<Agreement> agreement() {
try {
IObservableValue<?> value = getModelValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* 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.loc.internal.equinox;

import java.util.Optional;

import org.eclipse.passage.lic.api.LicensingException;
import org.eclipse.passage.loc.internal.api.workspace.Agreements;

public final class AgreementsService {

public Agreements get() throws LicensingException {
Optional<Agreements> service = new OperatorGearAware()
.withGear(gear -> Optional.of(gear.workspace().agreements()));
if (!service.isPresent()) {
throw new LicensingException("There is no Agreements service supplied by Operator Workspace"); //$NON-NLS-1$
}
return service.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ final class IssuePersonalLicense {
}

ServiceInvocationResult<IssuedLicense> issue(Supplier<PersonalLicensePack> template) {
PersonalLicensePack license = adjsut(signed(EcoreUtil.copy(template.get())));
PersonalLicensePack license = new Builder(template.get())//
.adjusted()//
.guarded()//
.withSignature()//
.withAgreements()//
.build();
Optional<String> errors = new ErrorMessages().apply(license);
if (errors.isPresent()) {
return new BaseServiceInvocationResult<>(new Trouble(new LicenseValidationFailed(), errors.get()));
Expand All @@ -69,45 +74,86 @@ ServiceInvocationResult<IssuedLicense> issue(Supplier<PersonalLicensePack> templ
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_error_io, e));
}
LicensedProduct product = new BaseLicensedProduct(//
license.getLicense().getProduct().getIdentifier(), //
license.getLicense().getProduct().getVersion());
LicensedProduct product = product(license);
Path path = new UserHomeProductResidence(product).get();

Path decrypted;
try {
decrypted = new PersistedDecoded(path, license)//
.write(license.getLicense().getIdentifier() + new PassageFileExtension.LicenseDecrypted().get());
events.postEvent(OperatorLicenseEvents.decodedIssued(decrypted.toString()));
decrypted = decrypted(license, path);
} catch (LicensingException e) {
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_failed_to_save_decoded, e));
}

Path encrypted;
try {
encrypted = new PersistedEncoded(product, decrypted, new ProductPassword(products, operator))//
.write(license.getLicense().getIdentifier() + new PassageFileExtension.LicenseEncrypted().get());
encrypted = encrypted(license, product, decrypted);
} catch (LicensingException e) {
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_export_error, e));
}
events.postEvent(OperatorLicenseEvents.encodedIssued(encrypted.toString()));
return result(license, decrypted, encrypted);
}

private BaseServiceInvocationResult<IssuedLicense> result(PersonalLicensePack license, Path decrypted,
Path encrypted) {
return new BaseServiceInvocationResult<>(new BaseIssuedLicense(license, encrypted, decrypted));
}

private PersonalLicensePack adjsut(PersonalLicensePack license) {
Date issueDate = new Date();
license.getLicense().setIdentifier(UUID.randomUUID().toString());
license.getLicense().setIssueDate(issueDate);
new AssignGrantIdentifiers().accept(license);
new PersonalLicenseIssuingProtection().accept(license);
return license;
private Path encrypted(PersonalLicensePack license, LicensedProduct product, Path decrypted)
throws LicensingException {
Path encrypted = new PersistedEncoded(product, decrypted, new ProductPassword(products, operator))//
.write(license.getLicense().getIdentifier() + new PassageFileExtension.LicenseEncrypted().get());
events.postEvent(OperatorLicenseEvents.encodedIssued(encrypted.toString()));
return encrypted;
}

private PersonalLicensePack signed(PersonalLicensePack pack) {
new LicenseSignature().accept(pack.getLicense());
return pack;
private Path decrypted(PersonalLicensePack license, Path path) throws LicensingException {
Path decrypted = new PersistedDecoded(path, license)//
.write(license.getLicense().getIdentifier() + new PassageFileExtension.LicenseDecrypted().get());
events.postEvent(OperatorLicenseEvents.decodedIssued(decrypted.toString()));
return decrypted;
}

private BaseLicensedProduct product(PersonalLicensePack license) {
return new BaseLicensedProduct(//
license.getLicense().getProduct().getIdentifier(), //
license.getLicense().getProduct().getVersion());
}

private static final class Builder {

private final PersonalLicensePack pack;

Builder(PersonalLicensePack template) {
this.pack = EcoreUtil.copy(template);
}

Builder withSignature() {
new LicenseSignature().accept(pack.getLicense());
return this;
}

Builder withAgreements() {

// TODO
return this;
}

Builder adjusted() {
pack.getLicense().setIdentifier(UUID.randomUUID().toString());
pack.getLicense().setIssueDate(new Date());
new AssignGrantIdentifiers().accept(pack);
return this;
}

Builder guarded() {
new PersonalLicenseIssuingProtection().accept(pack);
return this;
}

PersonalLicensePack build() {
return pack;
}
}
}