Skip to content

Commit

Permalink
Merge pull request #752 from eclipse-passage/573004-2
Browse files Browse the repository at this point in the history
Bug 573129 StremCodec must supply encryption keys to streams
  • Loading branch information
eparovyshnaya authored Apr 26, 2021
2 parents 9da5f99 + 824aa11 commit c526797
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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.LicensingException;
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;
Expand All @@ -37,9 +38,14 @@ public EncodedResponse(T payload, ProductUserRequest<RawRequest> data) {
}

public NetResponse get() {
return new FlsGearAwre()//
.withGear(this::transferable) //
.orElse(new Failure.OperationFailed("mine", "Failed exploiting gear")); //$NON-NLS-1$ //$NON-NLS-2$
try {
return new FlsGearAwre()//
.withGear(this::transferable) //
.orElse(new Failure.OperationFailed("mine", "Failed exploiting gear")); //$NON-NLS-1$ //$NON-NLS-2$
} catch (LicensingException e) {
// unreachable, development mistake
throw new IllegalStateException("FLS configurational is not complete", e); //$NON-NLS-1$
}
}

private Optional<NetResponse> transferable(FlsGear gear) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,25 @@ final class FeatureGrants {
* given {@code feature}, if any
*/
Collection<FeatureGrant> get() {
return new FlsGearAwre()//
.withGear(gear -> Optional.of(get(gear)))//
.orElse(failedOnGathering());
try {
return new FlsGearAwre()//
.withGear(gear -> Optional.of(get(gear)))//
.orElse(failedOnGathering());
} catch (LicensingException e) {
return exceptionOnGathering(e);
}
}

private Collection<FeatureGrant> failedOnGathering() {
log.error(String.format("Failed on gathering grants for product %s", product)); //$NON-NLS-1$
return Collections.emptyList();
}

private Collection<FeatureGrant> exceptionOnGathering(LicensingException e) {
log.error(String.format("Failed on gathering grants for product %s", product), e); //$NON-NLS-1$
return Collections.emptyList();
}

private Collection<FeatureGrant> get(FlsGear gear) {
try {
return new LicensePacks(//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import java.util.Collection;
import java.util.Collections;
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.eclipse.passage.lic.internal.api.LicensingException;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
Expand All @@ -30,7 +30,7 @@ public abstract class GearAware<G extends Gear, S extends GearSupplier<G>> {

private final Logger log = LogManager.getLogger(getClass());

public final <T> Optional<T> withGear(Function<G, Optional<T>> with) {
public final <T> Optional<T> withGear(Unsafe<G, T> with) throws LicensingException {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
Collection<ServiceReference<S>> references = Collections.emptyList();
try {
Expand All @@ -46,11 +46,19 @@ public final <T> Optional<T> withGear(Function<G, Optional<T>> with) {
ServiceReference<S> any = references.iterator().next();
try {
return with.apply(context.getService(any).gear());
} catch (Exception e) {
throw new LicensingException("Error on service invokation", e); //$NON-NLS-1$
} finally {
context.ungetService(any);
}
}

protected abstract Class<S> supplier();

@FunctionalInterface
public interface Unsafe<G extends Gear, T> {

Optional<T> apply(G gear) throws Exception;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ private Path open(LicensedProduct licensed, Path path) {

@SuppressWarnings("restriction")
private Optional<StreamCodec> codec(LicensedProduct product) {
return new OperatorGearAware().withGear(gear -> gear.codec(product));
try {
return new OperatorGearAware().withGear(gear -> gear.codec(product));
} catch (LicensingException e) {
return Optional.empty();// TODO: under construction
}
}

private Optional<String> validate(ProductVersionDescriptor target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Require-Bundle: org.eclipse.osgi.services;bundle-version="0.0.0",
org.eclipse.passage.lic.emf;bundle-version="0.0.0",
org.eclipse.passage.loc.api;bundle-version="0.0.0",
org.eclipse.passage.loc.workbench;bundle-version="0.0.0";visibility:=reexport,
org.eclipse.passage.lic.licenses.model;bundle-version="0.0.0"
org.eclipse.passage.lic.licenses.model;bundle-version="0.0.0",
org.apache.logging.log4j;bundle-version="2.8.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.passage.loc.internal.workbench.emfforms;x-internal:=true,
org.eclipse.passage.loc.internal.workbench.emfforms.i18n;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2020 ArSysOp
* Copyright (c) 2018, 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
Expand All @@ -20,13 +20,16 @@

import javax.inject.Inject;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
import org.eclipse.emf.ecp.view.spi.model.VControl;
import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
import org.eclipse.emfforms.spi.common.report.ReportService;
import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
import org.eclipse.passage.lic.internal.api.EvaluationType;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.api.inspection.RuntimeEnvironment;
import org.eclipse.passage.loc.internal.api.OperatorGear;
import org.eclipse.passage.loc.internal.equinox.OperatorGearAware;
Expand All @@ -35,14 +38,21 @@
@SuppressWarnings("restriction")
public class ConditionTypeRenderer extends ComboControlRenderer {

private final Logger log = LogManager.getLogger(getClass());
private final List<String> environments;

@Inject
public ConditionTypeRenderer(VControl vElement, ViewModelContext viewContext, ReportService reportService,
EMFFormsDatabinding emfFormsDatabinding, EMFFormsLabelProvider emfFormsLabelProvider,
VTViewTemplateProvider vtViewTemplateProvider) {
super(vElement, viewContext, reportService, emfFormsDatabinding, emfFormsLabelProvider, vtViewTemplateProvider);
environments = new OperatorGearAware().withGear(this::names).orElseGet(Collections::emptyList);
Optional<List<String>> found = Optional.empty();
try {
found = new OperatorGearAware().withGear(this::names);
} catch (LicensingException e) {
log.error(e);
}
environments = found.orElseGet(Collections::emptyList);
}

@Override
Expand Down

0 comments on commit c526797

Please sign in to comment.