use of java.security.Permission in project jboss-modules by jboss-modules.
the class PermissionsTest method testExpansion.
@Test
public void testExpansion() throws Exception {
Module module = moduleLoader.loadModule(MODULE_WITH_INVALID_EXPANSION);
Enumeration<Permission> permissions = module.getPermissionCollection().elements();
assertTrue(permissions.hasMoreElements());
Permission firstPermission = permissions.nextElement();
assertEquals(FilePermission.class.getName(), firstPermission.getClass().getName());
assertFalse(permissions.hasMoreElements());
}
use of java.security.Permission in project jboss-modules by jboss-modules.
the class FactoryPermissionCollection method getAssembled.
Permissions getAssembled() {
if (assembled == null) {
synchronized (this) {
if (assembled == null) {
final Permissions assembled = new Permissions();
for (PermissionFactory factory : factories) {
if (factory != null) {
final Permission permission = factory.construct();
if (permission != null) {
assembled.add(permission);
}
}
}
assembled.setReadOnly();
this.assembled = assembled;
}
}
}
return assembled;
}
use of java.security.Permission in project derby by apache.
the class SystemPrivilegesPermissionTest method checkImplies.
/**
* Tests DatabasePermission.implies().
*/
private void checkImplies(Permission[] dbp0, Permission[] dbp1, boolean[][] impls) throws IOException {
for (int i = 0; i < dbp0.length; i++) {
final Permission p0 = dbp0[i];
for (int j = 0; j < dbp1.length; j++) {
final Permission p1 = dbp1[j];
assertEquals("test: " + p0 + ".implies" + p1, impls[i][j], p0.implies(p1));
// assertEquals("test: " + p1 + ".implies" + p0,
// impls[j][i], p1.implies(p0));
}
}
}
use of java.security.Permission in project openj9 by eclipse.
the class PR66930ACCcheckPermission method test.
void test() {
final String baseName = this.getClass().getName();
ClassLoader privilegedCL = new URLClassLoader(new URL[] { this.getClass().getProtectionDomain().getCodeSource().getLocation() }, null) {
public PermissionCollection getPermissions(CodeSource cs) {
PermissionCollection pc = super.getPermissions(cs);
pc.add(PERM_CREATE_ACC);
return pc;
}
};
try {
Class<?> cls = Class.forName(baseName + "$PrivilegedClass", true, privilegedCL);
Object obj = cls.newInstance();
Method mt = cls.getMethod("test", AccessControlContext.class);
ProtectionDomain pd1 = new ProtectionDomain(null, null) {
public boolean implies(Permission perm) {
untrustedPDimpliesCalled = true;
System.out.println("Untrusted ProtectionDomain.implies() has been called");
return true;
}
};
System.setSecurityManager(new SecurityManager());
AccessControlContext accSimple = new AccessControlContext(new ProtectionDomain[] { pd1 });
untrustedPDimpliesCalled = false;
accSimple.checkPermission(PERM_JAVA_VERSION_READ);
if (!untrustedPDimpliesCalled) {
System.out.println("FAILED: untrusted ProtectionDomain.implies() should have been called");
}
AccessControlContext accInjected = AccessController.doPrivileged(new PrivilegedAction<AccessControlContext>() {
public AccessControlContext run() {
return AccessController.getContext();
}
}, accSimple);
untrustedPDimpliesCalled = false;
try {
accInjected.checkPermission(PERM_JAVA_VERSION_READ);
System.out.println("FAILED: AccessControlException NOT thrown");
} catch (AccessControlException ace) {
System.out.println("GOOD: AccessControlException is expected");
}
if (untrustedPDimpliesCalled) {
System.out.println("FAILED: untrusted ProtectionDomain.implies() should NOT be called");
}
mt.invoke(obj, accInjected);
System.out.println("ALL TESTS FINISHED");
} catch (Exception e) {
e.printStackTrace();
System.out.println("FAIL: TEST FAILED, probably setup issue.");
}
}
use of java.security.Permission in project openj9 by eclipse.
the class Test_AccessControlContext method test_Constructor.
/**
* @tests
* java.security.AccessControlContext#AccessControlContext(java.security
* .ProtectionDomain[])
*/
@Test
public void test_Constructor() {
final Permission perm = new PropertyPermission("java.class.path", "read");
PermissionCollection col = perm.newPermissionCollection();
col.add(perm);
final ProtectionDomain pd = new ProtectionDomain(null, col);
AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { pd });
try {
acc.checkPermission(perm);
} catch (SecurityException e) {
AssertJUnit.assertTrue("Should have permission", false);
}
final boolean[] result = new boolean[] { false };
Thread th = new Thread(new Runnable() {
public void run() {
AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { pd });
try {
acc.checkPermission(perm);
result[0] = true;
} catch (SecurityException e) {
}
}
});
th.start();
try {
th.join();
} catch (InterruptedException e) {
}
AssertJUnit.assertTrue("Thread should have permission", result[0]);
}
Aggregations