Skip to content

Commit

Permalink
Merge pull request #697 from eclipse-passage/572366-2
Browse files Browse the repository at this point in the history
Bug 572366 verify product's public key on hc-fls interaction
  • Loading branch information
eparovyshnaya authored Mar 30, 2021
2 parents f55076b + 08e7b72 commit 1f35482
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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.lic.internal.api;

/**
* Marker interface for a product based on Passage infrastructure to supply all
* necessary services
*/
public interface Gear {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* 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.lic.internal.api;

public interface GearSupplier<G extends Gear> {

G gear();

}
4 changes: 3 additions & 1 deletion bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Export-Package: org.eclipse.passage.lic.internal.equinox;
org.eclipse.passage.lic.jface,
org.eclipse.passage.lic.net,
org.eclipse.passage.seal.demo,
org.eclipse.passage.lic.jetty",
org.eclipse.passage.lic.jetty,
org.eclipse.passage.loc.api,
org.eclipse.passage.lbc.base",
org.eclipse.passage.lic.internal.equinox.acquire;x-internal:=true,
org.eclipse.passage.lic.internal.equinox.conditions;x-internal:=true,
org.eclipse.passage.lic.internal.equinox.events;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*******************************************************************************
* 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.lic.internal.equinox;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.function.Function;

import org.eclipse.passage.lic.internal.api.Gear;
import org.eclipse.passage.lic.internal.api.GearSupplier;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;

public abstract class GearAware<G extends Gear, S extends GearSupplier<G>> {

public final <T> Optional<T> withGear(Function<G, Optional<T>> with) {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
Collection<ServiceReference<S>> references = Collections.emptyList();
try {
references = context.getServiceReferences(supplier(), null);
} catch (InvalidSyntaxException e) {
return Optional.empty();
}
if (references.isEmpty()) {
return Optional.empty();
}
ServiceReference<S> any = references.iterator().next();
try {
return with.apply(context.getService(any).gear());
} finally {
context.ungetService(any);
}
}

protected abstract Class<S> supplier();

}
4 changes: 2 additions & 2 deletions bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Automatic-Module-Name: org.eclipse.passage.loc.api
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.passage.loc.api
Bundle-Version: 1.0.102.qualifier
Bundle-Version: 1.0.103.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Expand Down Expand Up @@ -34,7 +34,7 @@ Require-Bundle: org.eclipse.e4.core.services;bundle-version="0.0.0",
org.eclipse.osgi;bundle-version="0.0.0",
org.eclipse.passage.lic.base;bundle-version="1.0.0",
org.eclipse.passage.lic.emf;bundle-version="1.0.0",
org.eclipse.passage.lic.equinox;bundle-version="1.0.0",
org.eclipse.passage.lic.equinox;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.passage.lic.floating.model;bundle-version="0.1.0",
org.eclipse.passage.lic.licenses;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.passage.lic.products;bundle-version="1.0.0";visibility:=reexport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

import java.util.Optional;

import org.eclipse.passage.lic.internal.api.Gear;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.inspection.RuntimeEnvironmentRegistry;
import org.eclipse.passage.lic.internal.api.io.StreamCodec;

public interface OperatorGear {
public interface OperatorGear extends Gear {

Optional<StreamCodec> codec(LicensedProduct product);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*******************************************************************************/
package org.eclipse.passage.loc.internal.api;

public interface OperatorGearSupplier {
import org.eclipse.passage.lic.internal.api.GearSupplier;

OperatorGear gear();
public interface OperatorGearSupplier extends GearSupplier<OperatorGear> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,15 @@
*******************************************************************************/
package org.eclipse.passage.loc.internal.equinox;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.function.Function;

import org.eclipse.passage.lic.internal.equinox.GearAware;
import org.eclipse.passage.loc.internal.api.OperatorGear;
import org.eclipse.passage.loc.internal.api.OperatorGearSupplier;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;

public final class OperatorGearAware {
public final class OperatorGearAware extends GearAware<OperatorGear, OperatorGearSupplier> {

public <T> Optional<T> withGear(Function<OperatorGear, Optional<T>> with) {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
Collection<ServiceReference<OperatorGearSupplier>> references = Collections.emptyList();
try {
references = context.getServiceReferences(OperatorGearSupplier.class, null);
} catch (InvalidSyntaxException e) {
return Optional.empty();
}
if (references.isEmpty()) {
return Optional.empty();
}
ServiceReference<OperatorGearSupplier> any = references.iterator().next();
try {
return with.apply(context.getService(any).gear());
} finally {
context.ungetService(any);
}
@Override
protected Class<OperatorGearSupplier> supplier() {
return OperatorGearSupplier.class;
}

}

0 comments on commit 1f35482

Please sign in to comment.