new URL[]{ new URL("file:/foo") });
ClassLoader ldr2 = new URLClassLoader(
new URL[]{ new URL("file:/bar") }, ldr1);
Thread thr = Thread.currentThread();
AggregatePolicyProvider policy = new AggregatePolicyProvider();
checkPolicy0Permissions(policy);
thr.setContextClassLoader(ldr1);
checkPolicy0Permissions(policy);
System.setProperty("java.security.policy", policy1File);
policy.refresh();
checkPolicy1Permissions(policy);
thr.setContextClassLoader(null);
policy.setPolicy(null, new PolicyFileProvider(policy0File));
policy.setPolicy(ldr1,
new DynamicPolicyProvider(new PolicyFileProvider(policy1File)));
checkPolicy0Permissions(policy);
if (policy.grantSupported()) {
throw new TestException("1-st grant is supported.");
}
try {
policy.grant(null, null,
new Permission[]{ new RuntimePermission("foo") });
throw new TestException("1-st grant does not throw exception.");
} catch (UnsupportedOperationException e) {
}
thr.setContextClassLoader(ldr1);
checkPolicy1Permissions(policy);
if (!policy.grantSupported()) {
throw new TestException("2-nd grant is not supported.");
}
policy.grant(null, null,
new Permission[]{ new RuntimePermission("foo") });
thr.setContextClassLoader(ldr2);
checkPolicy1Permissions(policy);
if (!policy.grantSupported()) {
throw new TestException("3-rd grant is not supported.");
}
policy.grant(null, null,
new Permission[]{ new RuntimePermission("foo") });
policy.setPolicy(ldr2, new PolicyFileProvider(policy0File));
checkPolicy0Permissions(policy);
if (policy.grantSupported()) {
throw new TestException("4-th grant is supported.");
}
try {
policy.grant(null, null,
new Permission[]{ new RuntimePermission("foo") });
throw new TestException("2-nd grant does not throw exception.");
} catch (UnsupportedOperationException e) {
}
thr.setContextClassLoader(ldr1);
checkPolicy1Permissions(policy);
if (!policy.grantSupported()) {
throw new TestException("5-th grant is not supported.");
}
policy.grant(null, null,
new Permission[]{ new RuntimePermission("foo") });
policy.setPolicy(ldr2, null);
thr.setContextClassLoader(ldr2);
checkPolicy1Permissions(policy);
if (!policy.grantSupported()) {
throw new TestException("6-th grant is not supported.");
}
policy.grant(null, null,
new Permission[]{ new RuntimePermission("foo") });
}