public static void main(String[] args) throws Exception {
if ((sm = System.getSecurityManager()) == null) {
System.setSecurityManager(sm = new SecurityManager());
}
DynamicPolicyProvider policy = new DynamicPolicyProvider();
Policy.setPolicy(policy);
sm.checkPermission(new RuntimePermission("A"));
checkPermissionFail(new RuntimePermission("B"));
checkPermissionFail(new RuntimePermission("C"));
try {
policy.grant(Test.class, null,
new Permission[]{
new RuntimePermission("B"),
new RuntimePermission("C")
});
throw new Error("grant of B, C should not succeed");
} catch (SecurityException e) {
}
sm.checkPermission(new RuntimePermission("A"));
checkPermissionFail(new RuntimePermission("B"));
checkPermissionFail(new RuntimePermission("C"));
checkPermissionFail(new RuntimePermission("D"));
policy.grant(Test.class, null,
new Permission[]{ new RuntimePermission("B") });
try {
policy.grant(Test.class, null,
new Permission[]{ new RuntimePermission("C") });
throw new Error("grant of C should not succeed");
} catch (SecurityException e) {
}
sm.checkPermission(new RuntimePermission("A"));
sm.checkPermission(new RuntimePermission("B"));
checkPermissionFail(new RuntimePermission("C"));
checkPermissionFail(new RuntimePermission("D"));
System.setProperty("java.security.policy",
System.getProperty("test.src", ".") + File.separator + "policy.1");
policy.refresh();
checkPermissionFail(new RuntimePermission("A"));
sm.checkPermission(new RuntimePermission("B"));
checkPermissionFail(new RuntimePermission("C"));
sm.checkPermission(new RuntimePermission("D"));
try {
policy.grant(Test.class, null,
new Permission[]{ new RuntimePermission("A") });
throw new Error("grant of A should not succeed");
} catch (SecurityException e) {
}
policy.grant(Test.class, null,
new Permission[]{ new RuntimePermission("C") });
checkPermissionFail(new RuntimePermission("A"));
sm.checkPermission(new RuntimePermission("B"));
sm.checkPermission(new RuntimePermission("C"));