use of java.util.PropertyPermission in project openj9 by eclipse.
the class TestToArrayOfProtectionDomains method main.
public static void main(String[] args) {
try {
AccessController.checkPermission(new PropertyPermission("java.home", "read"));
System.out.println("FAILED: access not denied!");
} catch (AccessControlException ace) {
System.out.println("ALL TESTS COMPLETED AND PASSED");
}
}
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 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 elasticsearch by elastic.
the class TikaImpl method getRestrictedPermissions.
// compute some minimal permissions for parsers. they only get r/w access to the java temp directory,
// the ability to load some resources from JARs, and read sysprops
static PermissionCollection getRestrictedPermissions() {
Permissions perms = new Permissions();
// property/env access needed for parsing
perms.add(new PropertyPermission("*", "read"));
perms.add(new RuntimePermission("getenv.TIKA_CONFIG"));
// add permissions for resource access:
// classpath
addReadPermissions(perms, JarHell.parseClassPath());
// plugin jars
if (TikaImpl.class.getClassLoader() instanceof URLClassLoader) {
addReadPermissions(perms, ((URLClassLoader) TikaImpl.class.getClassLoader()).getURLs());
}
// jvm's java.io.tmpdir (needs read/write)
perms.add(new FilePermission(System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "-", "read,readlink,write,delete"));
// current hacks needed for POI/PDFbox issues:
perms.add(new SecurityPermission("putProviderProperty.BC"));
perms.add(new SecurityPermission("insertProvider"));
perms.add(new ReflectPermission("suppressAccessChecks"));
// xmlbeans, use by POI, needs to get the context classloader
perms.add(new RuntimePermission("getClassLoader"));
perms.setReadOnly();
return perms;
}
Aggregations