Search in sources :

Example 91 with FilePermission

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
    }
}
Also used : FilePermission(java.io.FilePermission)

Example 92 with FilePermission

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);
    }
}
Also used : FilePermission(java.io.FilePermission)

Example 93 with FilePermission

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);
}
Also used : FilePermission(java.io.FilePermission)

Example 94 with FilePermission

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);
}
Also used : SocketPermission(java.net.SocketPermission) FilePermission(java.io.FilePermission)

Example 95 with FilePermission

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);
}
Also used : FilePermission(java.io.FilePermission)

Aggregations

FilePermission (java.io.FilePermission)143 Deployment (org.jboss.arquillian.container.test.api.Deployment)38 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)29 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)29 PropertyPermission (java.util.PropertyPermission)23 IOException (java.io.IOException)22 RemotingPermission (org.jboss.remoting3.security.RemotingPermission)21 Permission (java.security.Permission)20 File (java.io.File)19 URL (java.net.URL)19 PermissionCollection (java.security.PermissionCollection)19 SocketPermission (java.net.SocketPermission)18 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)16 ReflectPermission (java.lang.reflect.ReflectPermission)12 Test (org.junit.Test)12 Permissions (java.security.Permissions)11 CodeSource (java.security.CodeSource)9 Path (java.nio.file.Path)8 SecurityPermission (java.security.SecurityPermission)8 Policy (java.security.Policy)7