use of org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager in project rt.equinox.framework by eclipse.
the class SystemBundleActivator method installSecurityManager.
private void installSecurityManager(EquinoxConfiguration configuration) throws BundleException {
String securityManager = configuration.getConfiguration(Constants.FRAMEWORK_SECURITY);
if (System.getSecurityManager() != null && securityManager != null) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new BundleException("Cannot specify the \"" + Constants.FRAMEWORK_SECURITY + "\" configuration property when a security manager is already installed.");
}
if (securityManager == null) {
// $NON-NLS-1$
securityManager = configuration.getConfiguration(EquinoxConfiguration.PROP_EQUINOX_SECURITY, configuration.getProperty("java.security.manager"));
}
if (securityManager != null) {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
if (securityManager.length() == 0)
// use the default one from java
sm = new SecurityManager();
else if (securityManager.equals(Constants.FRAMEWORK_SECURITY_OSGI))
// use an OSGi enabled manager that understands postponed conditions
sm = new EquinoxSecurityManager();
else {
// try to use a specific classloader by classname
try {
Class<?> clazz = Class.forName(securityManager);
sm = (SecurityManager) clazz.newInstance();
} catch (ClassNotFoundException e) {
// do nothing
} catch (ClassCastException e) {
// do nothing
} catch (InstantiationException e) {
// do nothing
} catch (IllegalAccessException e) {
// do nothing
}
}
if (sm == null)
throw new NoClassDefFoundError(securityManager);
if (configuration.getDebug().DEBUG_SECURITY)
// $NON-NLS-1$
Debug.println("Setting SecurityManager to: " + sm);
System.setSecurityManager(sm);
setSecurityManagner = sm;
return;
}
}
}
use of org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager in project rt.equinox.framework by eclipse.
the class EquinoxBundle method hasPermission.
@Override
public boolean hasPermission(Object permission) {
Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
ProtectionDomain domain = current.getDomain();
if (domain != null) {
if (permission instanceof Permission) {
SecurityManager sm = System.getSecurityManager();
if (sm instanceof EquinoxSecurityManager) {
/*
* If the FrameworkSecurityManager is active, we need to do checks the "right" way.
* We can exploit our knowledge that the security context of FrameworkSecurityManager
* is an AccessControlContext to invoke it properly with the ProtectionDomain.
*/
AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { domain });
try {
sm.checkPermission((Permission) permission, acc);
return true;
} catch (Exception e) {
return false;
}
}
return domain.implies((Permission) permission);
}
return false;
}
return true;
}
Aggregations