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 573129 StremCodec must supply encryption keys to streams #752

Merged
merged 3 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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
@@ -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