Search in sources :

Example 21 with PropertyPermission

use of java.util.PropertyPermission in project guava by google.

the class AbstractFutureInnocuousThreadTest method setUp.

@Override
protected void setUp() throws Exception {
    // Load the "normal" copy of SettableFuture and related classes.
    SettableFuture<?> unused = SettableFuture.create();
    // Hack to load AbstractFuture et. al. in a new classloader so that it tries to re-read the
    // cancellation-cause system property. This allows us to test what happens if reading the
    // property is forbidden and then continue running tests normally in one jvm without resorting
    // to even crazier hacks to reset static final boolean fields.
    final String concurrentPackage = SettableFuture.class.getPackage().getName();
    classReloader = new URLClassLoader(ClassPathUtil.getClassPathUrls()) {

        @GuardedBy("loadedClasses")
        final Map<String, Class<?>> loadedClasses = new HashMap<>();

        @Override
        public Class<?> loadClass(String name) throws ClassNotFoundException {
            if (name.startsWith(concurrentPackage) && // Use other classloader for ListenableFuture, so that the objects can interact
            !ListenableFuture.class.getName().equals(name)) {
                synchronized (loadedClasses) {
                    Class<?> toReturn = loadedClasses.get(name);
                    if (toReturn == null) {
                        toReturn = super.findClass(name);
                        loadedClasses.put(name, toReturn);
                    }
                    return toReturn;
                }
            }
            return super.loadClass(name);
        }
    };
    oldClassLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(classReloader);
    oldSecurityManager = System.getSecurityManager();
    /*
     * TODO(cpovirk): Why couldn't I get this to work with PermissionCollection and implies(), as
     * used by ClassPathTest?
     */
    final PropertyPermission readSystemProperty = new PropertyPermission("guava.concurrent.generate_cancellation_cause", "read");
    SecurityManager disallowPropertySecurityManager = new SecurityManager() {

        @Override
        public void checkPermission(Permission p) {
            if (readSystemProperty.equals(p)) {
                throw new SecurityException("Disallowed: " + p);
            }
        }
    };
    System.setSecurityManager(disallowPropertySecurityManager);
    settableFutureClass = classReloader.loadClass(SettableFuture.class.getName());
/*
     * We must keep the SecurityManager installed during the test body: It affects what kind of
     * threads ForkJoinPool.commonPool() creates.
     */
}
Also used : GuardedBy(javax.annotation.concurrent.GuardedBy) HashMap(java.util.HashMap) PropertyPermission(java.util.PropertyPermission) URLClassLoader(java.net.URLClassLoader) Permission(java.security.Permission) PropertyPermission(java.util.PropertyPermission)

Example 22 with PropertyPermission

use of java.util.PropertyPermission in project groovy by apache.

the class SecurityTest method testForbiddenProperty.

public void testForbiddenProperty() {
    String script = "System.getProperty(\"user.home\")";
    assertExecute(script, null, new PropertyPermission("user.home", "read"));
}
Also used : PropertyPermission(java.util.PropertyPermission)

Example 23 with PropertyPermission

use of java.util.PropertyPermission in project wildfly by wildfly.

the class RemoteProtocolChangeTestCase method createDeployment.

@Deployment
public static Archive createDeployment() {
    final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "remote-protocol-interceptor-test.jar");
    jar.addClasses(SampleBean.class, TestSuiteEnvironment.class);
    jar.addPackage(RemoteProtocolChangeTestCase.class.getPackage());
    jar.addPackage(AbstractServerInterceptorsSetupTask.class.getPackage());
    jar.addAsManifestResource(createPermissionsXmlAsset(new PropertyPermission("management.address", "read"), new PropertyPermission("node0", "read")), "permissions.xml");
    return jar;
}
Also used : PropertyPermission(java.util.PropertyPermission) AbstractServerInterceptorsSetupTask(org.jboss.as.test.shared.integration.ejb.interceptor.serverside.AbstractServerInterceptorsSetupTask) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 24 with PropertyPermission

use of java.util.PropertyPermission in project wildfly by wildfly.

the class ScheduledThreadPoolMetricsTestCase method getDeployment.

@Deployment
public static JavaArchive getDeployment() {
    final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ArtemisScheduledThreadpoolMetricsTestCase.jar");
    ejbJar.addPackage(TimeoutUtil.class.getPackage());
    ejbJar.addClasses(JMSThreadPoolMetricsSetup.class, JMSThreadPoolMetricsMDB.class, JMSThreadPoolMetricsUtil.class);
    ejbJar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr,org.jboss.remoting\n"), "MANIFEST.MF");
    ejbJar.addAsManifestResource(createPermissionsXmlAsset(new FilePermission(System.getProperty("jboss.inst") + File.separatorChar + "standalone" + File.separatorChar + "tmp" + File.separatorChar + "auth" + File.separatorChar + "*", "read"), new PropertyPermission("ts.timeout.factor", "read"), RemotingPermission.CREATE_ENDPOINT, RemotingPermission.CONNECT, new SocketPermission("localhost", "resolve")), "jboss-permissions.xml");
    return ejbJar;
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) PropertyPermission(java.util.PropertyPermission) SocketPermission(java.net.SocketPermission) TimeoutUtil(org.jboss.as.test.shared.TimeoutUtil) FilePermission(java.io.FilePermission) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 25 with PropertyPermission

use of java.util.PropertyPermission in project wildfly by wildfly.

the class AbstractRemoteEJBForwardingTestCase method createForwardingDeployment.

public static Archive<?> createForwardingDeployment(String moduleName, boolean tx) {
    JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, moduleName + ".jar");
    ejbJar.addClass(CommonStatefulSB.class);
    ejbJar.addClass(RemoteStatefulSB.class);
    // the forwarding classes
    ejbJar.addClass(AbstractForwardingStatefulSBImpl.class);
    if (tx) {
        ejbJar.addClass(ForwardingStatefulSBImpl.class);
    } else {
        ejbJar.addClass(NonTxForwardingStatefulSBImpl.class);
    }
    ejbJar.addClasses(EJBDirectory.class, NamingEJBDirectory.class, RemoteEJBDirectory.class);
    // remote outbound connection configuration
    ejbJar.addAsManifestResource(AbstractRemoteEJBForwardingTestCase.class.getPackage(), "jboss-ejb-client.xml", "jboss-ejb-client.xml");
    ejbJar.addAsResource(createPermissionsXmlAsset(new SocketPermission("localhost", "resolve"), new EJBClientPermission("changeWeakAffinity"), new PropertyPermission("jboss.node.name", "read")), "META-INF/jboss-permissions.xml");
    return ejbJar;
}
Also used : EJBClientPermission(org.jboss.ejb.client.EJBClientPermission) PropertyPermission(java.util.PropertyPermission) SocketPermission(java.net.SocketPermission) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive)

Aggregations

PropertyPermission (java.util.PropertyPermission)98 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