Search in sources :

Example 96 with FilePermission

use of java.io.FilePermission in project rt.equinox.framework by eclipse.

the class SecurityAdminUnitTests method testPostponedConditions01.

public void testPostponedConditions01() {
    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, ALLLOCATION_CONDS, READONLY_INFOS, ConditionalPermissionInfo.DENY));
    // $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);
    tc1unsat.setSatisfied(true);
    tc2unsat.setSatisfied(true);
    // $NON-NLS-1$ //$NON-NLS-2$
    testSMPermission(pds, new FilePermission("test", "read"), true);
    tc1sat.setSatisfied(true);
    tc2sat.setSatisfied(true);
    update = cpa.newConditionalPermissionUpdate();
    rows = update.getConditionalPermissionInfos();
    rows.remove(0);
    // $NON-NLS-1$);
    assertTrue("failed to commit", update.commit());
    // $NON-NLS-1$ //$NON-NLS-2$
    testSMPermission(pds, new FilePermission("test", "read"), true);
    tc1unsat.setSatisfied(false);
    tc2unsat.setSatisfied(false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testSMPermission(pds, new FilePermission("test", "read"), false);
    update = cpa.newConditionalPermissionUpdate();
    rows = update.getConditionalPermissionInfos();
    rows.remove(0);
    // $NON-NLS-1$);
    assertTrue("failed to commit", update.commit());
    // $NON-NLS-1$ //$NON-NLS-2$
    testSMPermission(pds, new FilePermission("test", "read"), false);
}
Also used : TestCondition(ext.framework.b.TestCondition) FilePermission(java.io.FilePermission)

Example 97 with FilePermission

use of java.io.FilePermission in project rt.equinox.framework by eclipse.

the class SecurityAdminUnitTests method testDefaultPermissions02.

public void testDefaultPermissions02() {
    Bundle test = installTestBundle(TEST_BUNDLE);
    AccessControlContext acc = test.adapt(AccessControlContext.class);
    pa.setDefaultPermissions(READONLY_INFOS);
    pa.setPermissions(test.getLocation(), SOCKET_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"), false);
    testPermission(acc, new AllPermission(), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), true);
    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"), 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);
}
Also used : SocketPermission(java.net.SocketPermission) FilePermission(java.io.FilePermission)

Example 98 with FilePermission

use of java.io.FilePermission in project rt.equinox.framework by eclipse.

the class SecurityAdminUnitTests method testMultipleLocationConditions01.

public void testMultipleLocationConditions01() {
    Bundle test = installTestBundle(TEST_BUNDLE);
    AccessControlContext acc = test.adapt(AccessControlContext.class);
    // $NON-NLS-1$
    ConditionalPermissionInfo condPermInfo1 = cpa.addConditionalPermissionInfo(getLocationConditions("xxx", false), SOCKET_INFOS);
    ConditionalPermissionInfo condPermInfo2 = cpa.addConditionalPermissionInfo(ALLLOCATION_CONDS, READONLY_INFOS);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), false);
    // $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);
    condPermInfo1.delete();
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), false);
    // $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);
    condPermInfo2.delete();
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), true);
    // $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);
}
Also used : SocketPermission(java.net.SocketPermission) FilePermission(java.io.FilePermission)

Example 99 with FilePermission

use of java.io.FilePermission in project rt.equinox.framework by eclipse.

the class SecurityAdminUnitTests method testAccessControlContext04.

public void testAccessControlContext04() {
    // test multiple signer conditions
    ConditionalPermissionUpdate update = cpa.newConditionalPermissionUpdate();
    List rows = update.getConditionalPermissionInfos();
    rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { SIGNER_CONDITION1, SIGNER_CONDITION2 }, READONLY_INFOS, ConditionalPermissionInfo.ALLOW));
    rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] { SIGNER_CONDITION1 }, READWRITE_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
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    acc = cpa.getAccessControlContext(new String[] { "cn=t1,c=FR;cn=test1,c=US", "cn=t1,c=FR;cn=test2,c=US" });
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        acc.checkPermission(new FilePermission("test", "write"));
    } catch (AccessControlException e) {
        // $NON-NLS-1$
        fail("Unexpected AccessControlExcetpion", e);
    }
    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 100 with FilePermission

use of java.io.FilePermission in project Java-Tutorial by gpcodervn.

the class FilePermissionExample method main.

public static void main(String[] args) throws IOException {
    String srg = "D:\\WorkSpace\\gpcoder\\JavaIOTutorial\\data\\java.txt";
    // cấp quyền cho path1
    FilePermission file1 = new FilePermission("D:\\WorkSpace\\gpcoder\\JavaIOTutorial\\data\\-", "read");
    PermissionCollection permission = file1.newPermissionCollection();
    permission.add(file1);
    // cấp quyền cho path2
    FilePermission file2 = new FilePermission(srg, "write");
    permission.add(file2);
    if (permission.implies(new FilePermission(srg, "read,write"))) {
        System.out.println("Read, Write permission is granted for the path " + srg);
    } else {
        System.out.println("No Read, Write permission is granted for the path " + srg);
    }
}
Also used : PermissionCollection(java.security.PermissionCollection) 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