use of java.security.PermissionCollection in project core by weld.
the class ProtectionDomainCache method create.
private ProtectionDomain create(ProtectionDomain domain) {
if (domain.implies(ACCESS_DECLARED_MEMBERS_PERMISSION)) {
return domain;
}
PermissionCollection permissions = domain.getPermissions();
PermissionCollection proxyPermissions = new Permissions();
if (permissions != null) {
Enumeration<Permission> permissionElements = permissions.elements();
while (permissionElements.hasMoreElements()) {
proxyPermissions.add(permissionElements.nextElement());
}
}
proxyPermissions.add(ACCESS_DECLARED_MEMBERS_PERMISSION);
return new ProtectionDomain(domain.getCodeSource(), proxyPermissions);
}
use of java.security.PermissionCollection in project openj9 by eclipse.
the class Test_J9VMInternalsImpl method test_checkPackageAccess.
@Test
public void test_checkPackageAccess() throws Throwable {
final String className = getClass().getName();
System.setSecurityManager(new SecurityManager());
try {
/*
* these tests are not dependent on the ClassLoader behaviour
*/
try {
@SuppressWarnings("rawtypes") Class // $NON-NLS-1$
cl = Class.forName(className + "$SuperclassRestricted");
Assert.fail(// $NON-NLS-1$
"FAILED: successfully loaded " + cl + // $NON-NLS-1$
" with restricted superclass");
} catch (SecurityException e) {
/* intentionally empty */
}
try {
@SuppressWarnings("rawtypes") Class // $NON-NLS-1$
cl = Class.forName(className + "$InterfaceRestricted");
Assert.fail(// $NON-NLS-1$
"FAILED: successfully loaded " + cl + // $NON-NLS-1$
" with restricted interface");
} catch (SecurityException e) {
/* intentionally empty */
}
} finally {
System.setSecurityManager(null);
}
/*
* special ClassLoader that changes behavior every time the
* $NCDFEHelper class load is attempted
*/
ClassLoader loader1 = new URLClassLoader(new URL[] { getClass().getProtectionDomain().getCodeSource().getLocation() }, null) {
int behaviorLoadingNCDFEHelper = 2;
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Class findClass(String name) throws ClassNotFoundException {
Class result;
if (name.startsWith(ORG_TESTNG)) {
result = Class.forName(name, true, ClassLoader.getSystemClassLoader());
} else {
if (name.equals(className + "$NCDFEHelper") && behaviorLoadingNCDFEHelper > 0) {
// $NON-NLS-1$
// $NON-NLS-1$
logger.debug("Trying to load NCDFEHelper");
behaviorLoadingNCDFEHelper--;
if (behaviorLoadingNCDFEHelper == 1) {
throw new OutOfMemoryError();
}
throw new LinkageError();
}
result = super.findClass(name);
}
return result;
}
};
/*
* run the $TestNCDFE test
*/
@SuppressWarnings("rawtypes") Class // $NON-NLS-1$
cl1 = Class.forName(className + "$TestNCDFE", true, loader1);
Object testInstance1 = cl1.newInstance();
@SuppressWarnings("unchecked") Method // $NON-NLS-1$
testMethod1 = cl1.getMethod("runTest1");
testMethod1.invoke(testInstance1);
/*
* Create a ClassLoader with AllPermission so classes loaded by this loader
* are not restricted by the default permissions of the application ClassLoader.
*/
ClassLoader privilegedLoader = new URLClassLoader(new URL[] { getClass().getProtectionDomain().getCodeSource().getLocation() }, null) {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Class findClass(String name) throws ClassNotFoundException {
Class result;
if (name.startsWith(ORG_TESTNG)) {
result = Class.forName(name, true, ClassLoader.getSystemClassLoader());
} else {
if (!name.startsWith(className + TEST_RESTRICTED)) {
throw new ClassNotFoundException(name);
}
result = super.findClass(name);
}
return result;
}
@Override
public PermissionCollection getPermissions(CodeSource csource) {
PermissionCollection permCollection = super.getPermissions(csource);
/*
* Allow AllPermission so we can use this classloader
* to define a custom SecurityManager.
*/
permCollection.add(new AllPermission());
return permCollection;
}
};
/*
* These tests are dependent on the ClassLoader behaviour.
* The default application ClassLoader checks package access of the classes being loaded.
* Other ClassLoaders don't have this behaviour
* and depend on the VM to do the check. We wish to test the VM behavior.
*/
@SuppressWarnings("rawtypes") Class cl2 = Class.forName(className + TEST_RESTRICTED, true, privilegedLoader);
Object testInstance2 = cl2.newInstance();
@SuppressWarnings("unchecked") Method // $NON-NLS-1$
testMethod2 = cl2.getMethod("runTest2", String.class);
testMethod2.invoke(testInstance2, className);
}
use of java.security.PermissionCollection in project scheduling by ow2-proactive.
the class ClientsPolicy method getPermissions.
@Override
public PermissionCollection getPermissions(final ProtectionDomain domain) {
try {
readLock.lock();
PermissionCollection permissions = new Permissions();
// Look up permissions
Principal[] principals = domain.getPrincipals();
boolean identityPrincipal = false;
if (principals != null) {
for (Principal principal : principals) {
if (principal instanceof IdentityPrincipal) {
identityPrincipal = true;
PermissionCollection pc = original.getPermissions(domain);
if (pc != null) {
Permission permission = new PrincipalPermission((IdentityPrincipal) principal);
// always adding identity permission
permissions.add(permission);
if (debug) {
// WARNING cannot use log4j as it may lead to recursive permission check
System.out.println(principal + " has " + permission);
}
for (Enumeration<Permission> en = pc.elements(); en.hasMoreElements(); ) {
permission = en.nextElement();
// boot class path, so they were not correctly resolved at JVM start up time
if (permission instanceof UnresolvedPermission) {
permission = resolvePermission((UnresolvedPermission) permission);
if (permission == null)
continue;
}
// For IdentityPrincipal org.ow2.proactive.permissions.AllPermissions must be used
if (!permission.getClass().isAssignableFrom(AllPermission.class)) {
if (debug) {
// WARNING cannot use log4j as it may lead to recursive permission check
System.out.println(principal + " has " + permission);
}
permissions.add(permission);
}
}
}
}
}
}
if (!identityPrincipal) {
return original.getPermissions(domain);
}
return permissions;
} finally {
readLock.unlock();
}
}
use of java.security.PermissionCollection in project ecf by eclipse.
the class RssServerSOContainer method main.
public static void main(String[] args) throws Exception {
RssServerSOContainerGroup[] serverGroups = null;
final List servers = new ArrayList();
int port = DEFAULT_PORT;
if (args.length > 0) {
if (args[0].equals("-p")) {
port = Integer.parseInt(args[1]);
}
}
// Get server identity
final String serverName = "//" + InetAddress.getLocalHost().getHostName() + ":" + port;
serverGroups = new RssServerSOContainerGroup[1];
// Setup server group
serverGroups[0] = new RssServerSOContainerGroup(port);
// Create identity for server
final ID id = IDFactory.getDefault().createStringID(serverName);
// Create server config object with identity and default timeout
final SOContainerConfig config = new SOContainerConfig(id);
// Make server instance
System.out.println("Creating ECF server container...");
final RssServerSOContainer server = new RssServerSOContainer(config, serverGroups[0], DEFAULT_KEEPALIVE);
// Setup join policy
((ISharedObjectContainerGroupManager) server).setConnectPolicy(new IConnectHandlerPolicy() {
public PermissionCollection checkConnect(Object address, ID fromID, ID targetID, String targetGroup, Object connectData) throws Exception {
System.out.println("JOIN Addr=" + address + ";From=" + fromID + ";Group=" + targetGroup + ";Data=" + connectData);
return null;
}
public void refresh() {
System.out.println("joinPolicy.refresh()");
}
});
// Setup add shared object policy
final ISharedObjectManager manager = server.getSharedObjectManager();
manager.setRemoteAddPolicy(new ISharedObjectPolicy() {
public PermissionCollection checkAddSharedObject(ID fromID, ID toID, ID localID, ReplicaSharedObjectDescription newObjectDescription) throws SecurityException {
System.out.println("ADDSHAREDOBJECT From=" + fromID + ";To=" + toID + ";SharedObjectDesc=" + newObjectDescription);
return null;
}
public void refresh() {
System.out.println("sharedObjectPolicy.refresh()");
}
});
serverGroups[0].putOnTheAir();
servers.add(server);
System.out.println("success!");
System.out.println("Waiting for JOIN requests at '" + id.getName() + "'...");
System.out.println("<Ctrl>+C to stop server");
}
use of java.security.PermissionCollection in project jboss-modules by jboss-modules.
the class ModuleClassLoader method getProtectionDomain.
private ProtectionDomain getProtectionDomain(CodeSource codeSource) {
final IdentityHashMap<CodeSource, ProtectionDomain> map = protectionDomains;
synchronized (map) {
ProtectionDomain protectionDomain = map.get(codeSource);
if (protectionDomain == null) {
final PermissionCollection permissions = module.getPermissionCollection();
protectionDomain = new ModularProtectionDomain(codeSource, permissions, this);
map.put(codeSource, protectionDomain);
}
return protectionDomain;
}
}
Aggregations