use of org.osgi.framework.ServicePermission in project felix by apache.
the class BundleContextImpl method getService.
public <S> S getService(ServiceReference<S> ref) {
checkValidity();
if (ref == null) {
throw new NullPointerException("Specified service reference cannot be null.");
}
Object sm = System.getSecurityManager();
if (sm != null) {
((SecurityManager) sm).checkPermission(new ServicePermission(ref, ServicePermission.GET));
}
return m_felix.getService(m_bundle, ref, false);
}
use of org.osgi.framework.ServicePermission in project rt.equinox.framework by eclipse.
the class PermissionTests method badServicePermission.
protected void badServicePermission(String name, String actions) {
try {
ServicePermission p = new ServicePermission(name, actions);
// $NON-NLS-1$
fail(p + " created with invalid actions");
} catch (IllegalArgumentException e) {
// expected
}
}
use of org.osgi.framework.ServicePermission in project aries by apache.
the class Util method findContextClassloader.
private static ClassLoader findContextClassloader(Bundle consumerBundle, String className, String methodName, Class<?> clsArg) {
BaseActivator activator = BaseActivator.activator;
String requestedClass;
Map<Pair<Integer, String>, String> args;
if (ServiceLoader.class.getName().equals(className) && "load".equals(methodName)) {
requestedClass = clsArg.getName();
args = new HashMap<Pair<Integer, String>, String>();
args.put(new Pair<Integer, String>(0, Class.class.getName()), requestedClass);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
sm.checkPermission(new ServicePermission(requestedClass, ServicePermission.GET));
} catch (AccessControlException ace) {
// access denied
activator.log(Level.FINE, "No permission to obtain service of type: " + requestedClass);
return null;
}
}
} else {
requestedClass = className;
// only supported on ServiceLoader.load() at the moment
args = null;
}
Collection<Bundle> bundles = new ArrayList<Bundle>(activator.findProviderBundles(requestedClass));
activator.log(Level.FINE, "Found bundles providing " + requestedClass + ": " + bundles);
Collection<Bundle> allowedBundles = activator.findConsumerRestrictions(consumerBundle, className, methodName, args);
if (allowedBundles != null) {
for (Iterator<Bundle> it = bundles.iterator(); it.hasNext(); ) {
if (!allowedBundles.contains(it.next())) {
it.remove();
}
}
}
switch(bundles.size()) {
case 0:
return null;
case 1:
Bundle bundle = bundles.iterator().next();
return getBundleClassLoader(bundle);
default:
List<ClassLoader> loaders = new ArrayList<ClassLoader>();
for (Bundle b : bundles) {
loaders.add(getBundleClassLoader(b));
}
return new MultiDelegationClassloader(loaders.toArray(new ClassLoader[loaders.size()]));
}
}
Aggregations