use of java.io.FilePermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testAccessControlContext07.
public void testAccessControlContext07() {
// test ! signer condition
ConditionalPermissionUpdate update = cpa.newConditionalPermissionUpdate();
List rows = update.getConditionalPermissionInfos();
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { NOT_SIGNER_CONDITION1 }, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("failed to commit", update.commit());
// $NON-NLS-1$
AccessControlContext acc = cpa.getAccessControlContext(new String[] { "cn=t1,c=FR;cn=test1,c=US" });
try {
// $NON-NLS-1$ //$NON-NLS-2$
acc.checkPermission(new FilePermission("test", "write"));
// $NON-NLS-1$
fail("expecting AccessControlExcetpion");
} catch (AccessControlException e) {
// expected
}
try {
// $NON-NLS-1$ //$NON-NLS-2$
acc.checkPermission(new FilePermission("test", "read"));
// $NON-NLS-1$
fail("expecting AccessControlExcetpion");
} catch (AccessControlException e) {
// expected
}
// $NON-NLS-1$
acc = cpa.getAccessControlContext(new String[] { "cn=t1,c=FR;cn=test2,c=US" });
try {
// $NON-NLS-1$ //$NON-NLS-2$
acc.checkPermission(new FilePermission("test", "write"));
// $NON-NLS-1$
fail("expecting AccessControlExcetpion");
} catch (AccessControlException e) {
// expected
}
try {
// $NON-NLS-1$ //$NON-NLS-2$
acc.checkPermission(new FilePermission("test", "read"));
} catch (AccessControlException e) {
// $NON-NLS-1$
fail("Unexpected AccessControlExcetpion", e);
}
}
use of java.io.FilePermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testMultipleLocationConditions02.
public void testMultipleLocationConditions02() {
Bundle test = installTestBundle(TEST_BUNDLE);
AccessControlContext pd = test.adapt(AccessControlContext.class);
// $NON-NLS-1$
ConditionalPermissionInfo condPermInfo1 = cpa.addConditionalPermissionInfo(getLocationConditions("xxx", false), SOCKET_INFOS);
ConditionalPermissionInfo condPermInfo2 = cpa.addConditionalPermissionInfo(ALLLOCATION_CONDS, READONLY_INFOS);
ConditionalPermissionInfo condPermInfo3 = cpa.addConditionalPermissionInfo(getLocationConditions(test.getLocation(), false), RUNTIME_INFOS);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new SocketPermission("localhost", "accept"), false);
// $NON-NLS-1$
testPermission(pd, new RuntimePermission("exitVM", null), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new FilePermission("test", "read"), true);
condPermInfo1.delete();
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new SocketPermission("localhost", "accept"), false);
// $NON-NLS-1$
testPermission(pd, new RuntimePermission("exitVM", null), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new FilePermission("test", "read"), true);
condPermInfo2.delete();
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new SocketPermission("localhost", "accept"), false);
// $NON-NLS-1$
testPermission(pd, new RuntimePermission("exitVM", null), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new FilePermission("test", "read"), false);
condPermInfo3.delete();
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new SocketPermission("localhost", "accept"), true);
// $NON-NLS-1$
testPermission(pd, new RuntimePermission("exitVM", null), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new FilePermission("test", "write"), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(pd, new FilePermission("test", "read"), true);
}
use of java.io.FilePermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testPostponedConditions05.
public void testPostponedConditions05() {
installConditionBundle();
TestCondition.clearConditions();
Bundle test1 = installTestBundle(TEST_BUNDLE);
Bundle test2 = installTestBundle(TEST2_BUNDLE);
ProtectionDomain pd1 = test1.adapt(ProtectionDomain.class);
ProtectionDomain pd2 = test2.adapt(ProtectionDomain.class);
ProtectionDomain[] pds = new ProtectionDomain[] { pd1, pd2 };
ConditionalPermissionUpdate update = cpa.newConditionalPermissionUpdate();
List rows = update.getConditionalPermissionInfos();
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { POST_MUT_SAT }, READONLY_INFOS, ConditionalPermissionInfo.DENY));
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { POST_MUT_UNSAT }, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { POST_MUT_SAT }, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { POST_MUT_UNSAT }, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
rows.add(cpa.newConditionalPermissionInfo(null, ALLLOCATION_CONDS, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$);
assertTrue("failed to commit", update.commit());
// $NON-NLS-1$ //$NON-NLS-2$
testSMPermission(pds, new FilePermission("test", "read"), false);
// $NON-NLS-1$
TestCondition tc1sat = TestCondition.getTestCondition("POST_MUT_SAT_" + test1.getBundleId());
// $NON-NLS-1$
TestCondition tc2sat = TestCondition.getTestCondition("POST_MUT_SAT_" + test2.getBundleId());
// $NON-NLS-1$
TestCondition tc1unsat = TestCondition.getTestCondition("POST_MUT_UNSAT_" + test1.getBundleId());
// $NON-NLS-1$
TestCondition tc2unsat = TestCondition.getTestCondition("POST_MUT_UNSAT_" + test2.getBundleId());
// $NON-NLS-1$
assertNotNull("tc1sat", tc1sat);
// $NON-NLS-1$
assertNotNull("tc2sat", tc2sat);
// $NON-NLS-1$
assertNotNull("tc1unsat", tc1unsat);
// $NON-NLS-1$
assertNotNull("tc2unsat", tc2unsat);
tc1sat.setSatisfied(false);
tc2sat.setSatisfied(false);
// $NON-NLS-1$ //$NON-NLS-2$
testSMPermission(pds, new FilePermission("test", "read"), true);
}
use of java.io.FilePermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testPostponedConditions03.
public void testPostponedConditions03() {
installConditionBundle();
TestCondition.clearConditions();
Bundle test1 = installTestBundle(TEST_BUNDLE);
Bundle test2 = installTestBundle(TEST2_BUNDLE);
ProtectionDomain pd1 = test1.adapt(ProtectionDomain.class);
ProtectionDomain pd2 = test2.adapt(ProtectionDomain.class);
ProtectionDomain[] pds = new ProtectionDomain[] { pd1, pd2 };
ConditionalPermissionUpdate update = cpa.newConditionalPermissionUpdate();
List rows = update.getConditionalPermissionInfos();
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { POST_MUT_SAT }, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { POST_MUT_SAT }, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { POST_MUT_UNSAT }, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
rows.add(cpa.newConditionalPermissionInfo(null, ALLLOCATION_CONDS, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$);
assertTrue("failed to commit", update.commit());
// $NON-NLS-1$ //$NON-NLS-2$
testSMPermission(pds, new FilePermission("test", "read"), true);
// $NON-NLS-1$
TestCondition tc1sat = TestCondition.getTestCondition("POST_MUT_SAT_" + test1.getBundleId());
// $NON-NLS-1$
TestCondition tc2sat = TestCondition.getTestCondition("POST_MUT_SAT_" + test2.getBundleId());
// $NON-NLS-1$
TestCondition tc1unsat = TestCondition.getTestCondition("POST_MUT_UNSAT_" + test1.getBundleId());
// $NON-NLS-1$
TestCondition tc2unsat = TestCondition.getTestCondition("POST_MUT_UNSAT_" + test2.getBundleId());
// $NON-NLS-1$
assertNotNull("tc1sat", tc1sat);
// $NON-NLS-1$
assertNotNull("tc2sat", tc2sat);
// $NON-NLS-1$
assertNotNull("tc1unsat", tc1unsat);
// $NON-NLS-1$
assertNotNull("tc2unsat", tc2unsat);
tc1sat.setSatisfied(false);
tc2sat.setSatisfied(false);
tc1unsat.setSatisfied(true);
tc2unsat.setSatisfied(true);
// $NON-NLS-1$ //$NON-NLS-2$
testSMPermission(pds, new FilePermission("test", "read"), true);
}
use of java.io.FilePermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testLocationPermission01.
public void testLocationPermission01() {
Bundle test = installTestBundle(TEST_BUNDLE);
AccessControlContext acc = test.adapt(AccessControlContext.class);
pa.setPermissions(test.getLocation(), READONLY_INFOS);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
testPermission(acc, new AllPermission(), false);
pa.setPermissions(test.getLocation(), null);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "write"), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new FilePermission("test", "read"), true);
testPermission(acc, new AllPermission(), true);
}
Aggregations