use of java.util.PropertyPermission in project openj9 by eclipse.
the class Test_AccessController method test_doPrivilegedWithCombiner4.
/**
* java.security.AccessController#doPrivilegedWithCombiner(java.security.PrivilegedAction)
*/
@Test
public void test_doPrivilegedWithCombiner4() {
ClassLoader cl = new TestURLClassLoader(new URL[] { getClass().getProtectionDomain().getCodeSource().getLocation() }, null) {
public PermissionCollection getPermissions(CodeSource cs) {
PermissionCollection pc = super.getPermissions(cs);
pc.add(new PropertyPermission(PROP_USER, "read"));
return pc;
}
};
try {
Class<?> c = Class.forName("org.openj9.test.java.security.Test_AccessController$TestClass", true, cl);
Object o = c.newInstance();
Method m = c.getMethod("test", AccessControlContext.class);
Boolean result = (Boolean) (m.invoke(o, AccessController.getContext()));
if (!result) {
Assert.fail("test_doPrivilegedWithCombiner4 failed!");
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Unexpected exception thrown: " + e);
}
}
use of java.util.PropertyPermission 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]);
}
use of java.util.PropertyPermission in project openj9 by eclipse.
the class CodeTrusted method getPropertyNewPrivWithCombNoLimitedYes.
public String getPropertyNewPrivWithCombNoLimitedYes(final String prop) {
AccessControlContext acc1 = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, new Permissions()) });
AccessControlContext acc = new AccessControlContext(acc1, new MyDomainCombinerNo());
String result = AccessController.doPrivilegedWithCombiner(new PrivilegedAction<String>() {
public String run() {
String result = System.getProperty(prop);
System.out.println("Codetrusted - getPropertyNewPrivWithCombNoLimitedYes - getProperty " + prop + " is: " + result);
return result;
}
}, acc, new PropertyPermission("java.home", "read"));
return result;
}
use of java.util.PropertyPermission in project openj9 by eclipse.
the class CodeTrusted method getPropertyNewPrivWithCombYesLimitedYes.
public String getPropertyNewPrivWithCombYesLimitedYes(final String prop) {
AccessControlContext acc1 = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, new Permissions()) });
AccessControlContext acc = new AccessControlContext(acc1, new MyDomainCombinerYes());
String result = AccessController.doPrivilegedWithCombiner(new PrivilegedAction<String>() {
public String run() {
String result = System.getProperty(prop);
System.out.println("Codetrusted - getPropertyNewPrivWithCombYesLimitedYes - getProperty " + prop + " is: " + result);
return result;
}
}, acc, new PropertyPermission("java.home", "read"));
return result;
}
use of java.util.PropertyPermission in project groovy-core by groovy.
the class SecurityTest method testForbiddenProperty.
public void testForbiddenProperty() {
String script = "System.getProperty(\"user.home\")";
assertExecute(script, null, new PropertyPermission("user.home", "read"));
}
Aggregations