Search in sources :

Example 56 with PropertyPermission

use of java.util.PropertyPermission in project openj9 by eclipse.

the class TestToArrayOfProtectionDomains method main.

public static void main(String[] args) {
    try {
        AccessController.checkPermission(new PropertyPermission("java.home", "read"));
        System.out.println("FAILED: access not denied!");
    } catch (AccessControlException ace) {
        System.out.println("ALL TESTS COMPLETED AND PASSED");
    }
}
Also used : PropertyPermission(java.util.PropertyPermission) AccessControlException(java.security.AccessControlException)

Example 57 with PropertyPermission

use of java.util.PropertyPermission in project openj9 by eclipse.

the class CodeTrusted method getPropertyNewPrivWithCombNoLimitedYes.

public String getPropertyNewPrivWithCombNoLimitedYes(final String prop) {
    AccessControlContext acc1 = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, new Permissions()) });
    AccessControlContext acc = new AccessControlContext(acc1, new MyDomainCombinerNo());
    String result = AccessController.doPrivilegedWithCombiner(new PrivilegedAction<String>() {

        public String run() {
            String result = System.getProperty(prop);
            System.out.println("Codetrusted - getPropertyNewPrivWithCombNoLimitedYes - getProperty " + prop + " is: " + result);
            return result;
        }
    }, acc, new PropertyPermission("java.home", "read"));
    return result;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) PropertyPermission(java.util.PropertyPermission) Permissions(java.security.Permissions)

Example 58 with PropertyPermission

use of java.util.PropertyPermission in project openj9 by eclipse.

the class CodeTrusted method getPropertyNewPrivWithCombYesLimitedYes.

public String getPropertyNewPrivWithCombYesLimitedYes(final String prop) {
    AccessControlContext acc1 = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, new Permissions()) });
    AccessControlContext acc = new AccessControlContext(acc1, new MyDomainCombinerYes());
    String result = AccessController.doPrivilegedWithCombiner(new PrivilegedAction<String>() {

        public String run() {
            String result = System.getProperty(prop);
            System.out.println("Codetrusted - getPropertyNewPrivWithCombYesLimitedYes - getProperty " + prop + " is: " + result);
            return result;
        }
    }, acc, new PropertyPermission("java.home", "read"));
    return result;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) PropertyPermission(java.util.PropertyPermission) Permissions(java.security.Permissions)

Example 59 with PropertyPermission

use of java.util.PropertyPermission in project openj9 by eclipse.

the class Test_AccessControlContext method test_Constructor.

/**
 * @tests
 *        java.security.AccessControlContext#AccessControlContext(java.security
 *        .ProtectionDomain[])
 */
@Test
public void test_Constructor() {
    final Permission perm = new PropertyPermission("java.class.path", "read");
    PermissionCollection col = perm.newPermissionCollection();
    col.add(perm);
    final ProtectionDomain pd = new ProtectionDomain(null, col);
    AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { pd });
    try {
        acc.checkPermission(perm);
    } catch (SecurityException e) {
        AssertJUnit.assertTrue("Should have permission", false);
    }
    final boolean[] result = new boolean[] { false };
    Thread th = new Thread(new Runnable() {

        public void run() {
            AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { pd });
            try {
                acc.checkPermission(perm);
                result[0] = true;
            } catch (SecurityException e) {
            }
        }
    });
    th.start();
    try {
        th.join();
    } catch (InterruptedException e) {
    }
    AssertJUnit.assertTrue("Thread should have permission", result[0]);
}
Also used : PermissionCollection(java.security.PermissionCollection) ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) PropertyPermission(java.util.PropertyPermission) Permission(java.security.Permission) PropertyPermission(java.util.PropertyPermission) Test(org.testng.annotations.Test)

Example 60 with PropertyPermission

use of java.util.PropertyPermission in project elasticsearch by elastic.

the class TikaImpl method getRestrictedPermissions.

// compute some minimal permissions for parsers. they only get r/w access to the java temp directory,
// the ability to load some resources from JARs, and read sysprops
static PermissionCollection getRestrictedPermissions() {
    Permissions perms = new Permissions();
    // property/env access needed for parsing
    perms.add(new PropertyPermission("*", "read"));
    perms.add(new RuntimePermission("getenv.TIKA_CONFIG"));
    // add permissions for resource access:
    // classpath
    addReadPermissions(perms, JarHell.parseClassPath());
    // plugin jars
    if (TikaImpl.class.getClassLoader() instanceof URLClassLoader) {
        addReadPermissions(perms, ((URLClassLoader) TikaImpl.class.getClassLoader()).getURLs());
    }
    // jvm's java.io.tmpdir (needs read/write)
    perms.add(new FilePermission(System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "-", "read,readlink,write,delete"));
    // current hacks needed for POI/PDFbox issues:
    perms.add(new SecurityPermission("putProviderProperty.BC"));
    perms.add(new SecurityPermission("insertProvider"));
    perms.add(new ReflectPermission("suppressAccessChecks"));
    // xmlbeans, use by POI, needs to get the context classloader
    perms.add(new RuntimePermission("getClassLoader"));
    perms.setReadOnly();
    return perms;
}
Also used : PropertyPermission(java.util.PropertyPermission) URLClassLoader(java.net.URLClassLoader) Permissions(java.security.Permissions) ReflectPermission(java.lang.reflect.ReflectPermission) FilePermission(java.io.FilePermission) SecurityPermission(java.security.SecurityPermission)

Aggregations

PropertyPermission (java.util.PropertyPermission)99 Deployment (org.jboss.arquillian.container.test.api.Deployment)49 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)46 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)35 FilePermission (java.io.FilePermission)23 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)18 SocketPermission (java.net.SocketPermission)13 JMSOperations (org.jboss.as.test.integration.common.jms.JMSOperations)13 Permission (java.security.Permission)10 AccessControlException (java.security.AccessControlException)8 RemotingPermission (org.jboss.remoting3.security.RemotingPermission)8 PermissionCollection (java.security.PermissionCollection)7 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)7 ReflectPermission (java.lang.reflect.ReflectPermission)6 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)6 Permissions (java.security.Permissions)5 SecurityPermission (java.security.SecurityPermission)5 AccessControlContext (java.security.AccessControlContext)4 TimeoutUtil (org.jboss.as.test.shared.TimeoutUtil)4 Method (java.lang.reflect.Method)3