use of java.io.FilePermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testAccessControlContext05.
public void testAccessControlContext05() {
// test with empty rows
// $NON-NLS-1$
AccessControlContext 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$ //$NON-NLS-2$
acc.checkPermission(new FilePermission("test", "read"));
acc.checkPermission(new AllPermission());
} catch (AccessControlException e) {
// $NON-NLS-1$
fail("Unexpected AccessControlExcetpion", e);
}
// set the default permissions
pa.setDefaultPermissions(READWRITE_INFOS);
// $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$ //$NON-NLS-2$
acc.checkPermission(new FilePermission("test", "read"));
} catch (AccessControlException e) {
// $NON-NLS-1$
fail("Unexpected AccessControlExcetpion", e);
}
try {
acc.checkPermission(new AllPermission());
// $NON-NLS-1$
fail("expecting AccessControlExcetpion");
} catch (AccessControlException e) {
// expected
}
}
use of java.io.FilePermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testAccessControlContext03.
public void testAccessControlContext03() {
// test multiple signer conditions
ConditionalPermissionUpdate update = cpa.newConditionalPermissionUpdate();
List rows = update.getConditionalPermissionInfos();
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { 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=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"));
// $NON-NLS-1$
fail("expecting AccessControlExcetpion");
} catch (AccessControlException e) {
// expected
}
update = cpa.newConditionalPermissionUpdate();
rows = update.getConditionalPermissionInfos();
rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { SIGNER_CONDITION2 }, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("failed to commit", update.commit());
// $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 testUpdate02.
public void testUpdate02() {
ConditionalPermissionUpdate update = cpa.newConditionalPermissionUpdate();
List rows = update.getConditionalPermissionInfos();
ConditionalPermissionInfo info = cpa.newConditionalPermissionInfo(null, ALLLOCATION_CONDS, READONLY_INFOS, ConditionalPermissionInfo.ALLOW);
rows.add(info);
// $NON-NLS-1$
assertTrue("failed to commit", update.commit());
Bundle test = installTestBundle(TEST_BUNDLE);
AccessControlContext acc = test.adapt(AccessControlContext.class);
// $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);
update = cpa.newConditionalPermissionUpdate();
rows = update.getConditionalPermissionInfos();
rows.clear();
// $NON-NLS-1$
assertTrue("failed to commit", update.commit());
// $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);
}
use of java.io.FilePermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testLocationPermission03.
public void testLocationPermission03() {
Bundle test = installTestBundle(TEST_BUNDLE);
AccessControlContext acc = test.adapt(AccessControlContext.class);
pa.setDefaultPermissions(READONLY_INFOS);
pa.setPermissions(test.getLocation(), READWRITE_INFOS);
ConditionalPermissionInfo condPermInfo = cpa.addConditionalPermissionInfo(ALLLOCATION_CONDS, SOCKET_INFOS);
// $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(), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), false);
pa.setPermissions(test.getLocation(), null);
// $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"), false);
testPermission(acc, new AllPermission(), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), true);
condPermInfo.delete();
// $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);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), false);
pa.setDefaultPermissions(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);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), true);
}
use of java.io.FilePermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testDefaultPermissions01.
public void testDefaultPermissions01() {
Bundle test = installTestBundle(TEST_BUNDLE);
AccessControlContext acc = test.adapt(AccessControlContext.class);
pa.setDefaultPermissions(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.setDefaultPermissions(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