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 572366 verify product's public key on hc-fls interaction #697

Merged
merged 2 commits into from
Mar 30, 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
@@ -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();

}
2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
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;
}

}