Example usage for java.lang RuntimePermission RuntimePermission

List of usage examples for java.lang RuntimePermission RuntimePermission

Introduction

In this page you can find the example usage for java.lang RuntimePermission RuntimePermission.

Prototype


public RuntimePermission(String name) 

Source Link

Document

Creates a new RuntimePermission with the specified name.

Usage

From source file:org.jboss.as.test.clustering.single.singleton.SingletonServiceTestCase.java

@Deployment
public static Archive<?> deployment() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, "singleton.war");
    war.addPackage(NodeService.class.getPackage());
    war.setManifest(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.as.server\n"));
    war.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("getClassLoader"), // See org.jboss.as.server.deployment.service.ServiceActivatorProcessor#deploy()
            new ServerPermission("useServiceRegistry"), // See org.jboss.as.server.deployment.service.SecuredServiceRegistry
            new ServerPermission("getCurrentServiceContainer")), "permissions.xml");
    war.addAsServiceProvider(org.jboss.msc.service.ServiceActivator.class, NodeServiceActivator.class);
    return war;//w  w  w  . j a  v  a 2s  .c o m
}

From source file:com.thoughtworks.acceptance.SecurityManagerTest.java

protected void setUp() throws Exception {
    super.setUp();
    System.setSecurityManager(null);
    source = new CodeSource(new File("target").toURI().toURL(), (Certificate[]) null);

    sm = new DynamicSecurityManager();
    Policy policy = Policy.getPolicy();
    sm.setPermissions(source, policy.getPermissions(source));
    sm.addPermission(source, new RuntimePermission("setSecurityManager"));

    File mainClasses = new File(System.getProperty("user.dir"), "target/classes/-");
    File testClasses = new File(System.getProperty("user.dir"), "target/test-classes/-");
    String[] javaClassPath = StringUtils.split(System.getProperty("java.class.path"), File.pathSeparatorChar);
    File javaHome = new File(System.getProperty("java.home"), "-");

    // necessary permission start here
    sm.addPermission(source, new FilePermission(mainClasses.toString(), "read"));
    sm.addPermission(source, new FilePermission(testClasses.toString(), "read"));
    sm.addPermission(source, new FilePermission(javaHome.toString(), "read"));
    for (int i = 0; i < javaClassPath.length; ++i) {
        if (javaClassPath[i].endsWith(".jar")) {
            sm.addPermission(source, new FilePermission(javaClassPath[i], "read"));
        }//from   ww  w.  java  2 s  .c o  m
    }
}

From source file:org.jboss.as.test.clustering.cluster.singleton.SingletonBackupServiceTestCase.java

private static Archive<?> createDeployment() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, "singleton.war");
    war.addPackage(ValueServiceServlet.class.getPackage());
    war.setManifest(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.as.server\n"));
    war.addAsServiceProvider(org.jboss.msc.service.ServiceActivator.class, ValueServiceActivator.class);
    war.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("getClassLoader"), // See org.jboss.as.server.deployment.service.ServiceActivatorProcessor#deploy()
            new ServerPermission("useServiceRegistry"), // See org.jboss.as.server.deployment.service.SecuredServiceRegistry
            new ServerPermission("getCurrentServiceContainer")), "permissions.xml");
    return war;/* w  ww  . j  a  v a 2 s  .  c  o m*/
}

From source file:org.jboss.as.test.clustering.cluster.singleton.SingletonServiceTestCase.java

private static Archive<?> createDeployment() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, "singleton.war");
    war.addPackage(NodeService.class.getPackage());
    war.setManifest(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.as.server\n"));
    war.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("getClassLoader"), // See org.jboss.as.server.deployment.service.ServiceActivatorProcessor#deploy()
            new ServerPermission("useServiceRegistry"), // See org.jboss.as.server.deployment.service.SecuredServiceRegistry
            new ServerPermission("getCurrentServiceContainer")), "permissions.xml");
    war.addAsServiceProvider(org.jboss.msc.service.ServiceActivator.class, NodeServiceActivator.class);
    return war;/*from  w  w w.ja v  a 2  s .c  o m*/
}

From source file:org.jboss.as.test.clustering.cluster.singleton.SingletonPolicyServiceTestCase.java

private static Archive<?> createDeployment() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, "singleton.war");
    war.addPackage(NodeService.class.getPackage());
    war.setManifest(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.as.server\n"));
    war.addAsServiceProvider(org.jboss.msc.service.ServiceActivator.class, NodeServicePolicyActivator.class);
    war.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("getClassLoader"), // See org.jboss.as.server.deployment.service.ServiceActivatorProcessor#deploy()
            new ServerPermission("useServiceRegistry"), // See org.jboss.as.server.deployment.service.SecuredServiceRegistry
            new ServerPermission("getCurrentServiceContainer")), "permissions.xml");
    return war;//from w  ww .jav  a 2 s. com
}

From source file:org.jboss.as.test.integration.web.security.WebSecuritySimpleRoleMappingSecurityManagerTestCase.java

@Deployment(testable = false)
public static WebArchive deployment() throws Exception {
    WebArchive war = prepareDeployment("jboss-web.xml");
    war.addAsManifestResource(/*from w  w  w .ja  va 2 s .c  o m*/
            createPermissionsXmlAsset(new RuntimePermission("org.picketbox.factories.SecurityFactory.*"),
                    new RuntimePermission("org.jboss.security.*"),
                    new javax.security.auth.AuthPermission("getLoginConfiguration")),
            "permissions.xml");
    return war;
}

From source file:com.thoughtworks.acceptance.SecurityManagerTest.java

public void testSerializeWithXppDriverAndSun14ReflectionProviderAndActiveSecurityManager() {
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.reflect"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.misc"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.text.resources"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.util.resources"));
    sm.addPermission(source, new RuntimePermission("accessDeclaredMembers"));
    sm.addPermission(source, new RuntimePermission("createClassLoader"));
    sm.addPermission(source, new RuntimePermission("fileSystemProvider"));
    sm.addPermission(source, new RuntimePermission("loadLibrary.nio"));
    sm.addPermission(source, new RuntimePermission("modifyThreadGroup"));
    sm.addPermission(source, new RuntimePermission("reflectionFactoryAccess"));
    sm.addPermission(source, new PropertyPermission("ibm.dst.compatibility", "read"));
    sm.addPermission(source, new PropertyPermission("java.home", "read"));
    sm.addPermission(source, new PropertyPermission("java.nio.file.spi.DefaultFileSystemProvider", "read"));
    sm.addPermission(source, new PropertyPermission("java.security.debug", "read"));
    sm.addPermission(source, new PropertyPermission("javax.xml.datatype.DatatypeFactory", "read"));
    sm.addPermission(source, new PropertyPermission("jaxp.debug", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.util.TimeZone.allowSetDefault", "read"));
    sm.addPermission(source, new PropertyPermission("sun.boot.class.path", "read"));
    sm.addPermission(source, new PropertyPermission("sun.nio.fs.chdirAllowed", "read"));
    sm.addPermission(source, new PropertyPermission("sun.timezone.ids.oldmapping", "read"));
    sm.addPermission(source, new PropertyPermission("user.country", "read"));
    sm.addPermission(source, new PropertyPermission("user.dir", "read"));
    sm.addPermission(source, new PropertyPermission("user.timezone", "read,write"));
    sm.addPermission(source, new ReflectPermission("suppressAccessChecks"));
    sm.addPermission(source, new NetPermission("specifyStreamHandler"));
    sm.setReadOnly();//from   w w  w  .  ja  va  2  s . co m
    System.setSecurityManager(sm);

    xstream = new XStream();
    xstream.allowTypesByWildcard(AbstractAcceptanceTest.class.getPackage().getName() + ".*objects.**");
    xstream.allowTypesByWildcard(this.getClass().getName() + "$*");

    assertBothWays();
}

From source file:org.jboss.additional.testsuite.jdkall.present.domain.suites.ReadEnvironmentVariablesTestCase.java

@Test
public void testReadEnvironmentVariablesForServers() throws Exception {
    DomainClient client = domainMasterLifecycleUtil.createDomainClient();
    DomainDeploymentManager manager = client.getDeploymentManager();

    try {/*from  ww w  . ja v  a 2  s.  co  m*/
        //Deploy the archive
        WebArchive archive = ShrinkWrap.create(WebArchive.class, "env-test.war")
                .addClass(EnvironmentTestServlet.class);
        archive.addAsResource(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.dmr \n"),
                "META-INF/MANIFEST.MF");
        archive.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("getenv.*")),
                "permissions.xml");

        final InputStream contents = archive.as(ZipExporter.class).exportAsInputStream();
        try {
            DeploymentPlan plan = manager.newDeploymentPlan().add("env-test.war", contents)
                    .deploy("env-test.war").toServerGroup("main-server-group")
                    .toServerGroup("other-server-group").build();
            DeploymentPlanResult result = manager.execute(plan).get();
            Assert.assertTrue(result.isValid());
        } finally {
            IoUtils.safeClose(contents);
        }

        Map<String, String> env = getEnvironmentVariables(client, "master", "main-one", "standard-sockets");
        checkEnvironmentVariable(env, "DOMAIN_TEST_MAIN_GROUP", "main_group");
        checkEnvironmentVariable(env, "DOMAIN_TEST_SERVER", "server");
        checkEnvironmentVariable(env, "DOMAIN_TEST_JVM", "jvm");

        env = getEnvironmentVariables(client, "slave", "main-three", "standard-sockets");
        checkEnvironmentVariable(env, "DOMAIN_TEST_MAIN_GROUP", "main_group");
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_SERVER"));
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_JVM"));

        env = getEnvironmentVariables(client, "slave", "other-two", "other-sockets");
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_MAIN_GROUP"));
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_SERVER"));
        Assert.assertFalse(env.containsKey("DOMAIN_TEST_JVM"));

    } finally {
        DeploymentPlanResult result = manager
                .execute(manager.newDeploymentPlan().undeploy("env-test.war").build()).get();
        Assert.assertTrue(result.isValid());
        IoUtils.safeClose(client);
    }
}

From source file:com.thoughtworks.acceptance.SecurityManagerTest.java

public void testSerializeWithXppDriverAndPureJavaReflectionProviderAndActiveSecurityManager() {
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.misc"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.text.resources"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.util.resources"));
    sm.addPermission(source, new RuntimePermission("accessDeclaredMembers"));
    sm.addPermission(source, new RuntimePermission("createClassLoader"));
    sm.addPermission(source, new RuntimePermission("fileSystemProvider"));
    sm.addPermission(source, new RuntimePermission("loadLibrary.nio"));
    sm.addPermission(source, new RuntimePermission("modifyThreadGroup"));
    sm.addPermission(source, new PropertyPermission("ibm.dst.compatibility", "read"));
    sm.addPermission(source, new PropertyPermission("java.home", "read"));
    sm.addPermission(source, new PropertyPermission("java.nio.file.spi.DefaultFileSystemProvider", "read"));
    sm.addPermission(source, new PropertyPermission("java.security.debug", "read"));
    sm.addPermission(source, new PropertyPermission("javax.xml.datatype.DatatypeFactory", "read"));
    sm.addPermission(source, new PropertyPermission("jaxp.debug", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.util.TimeZone.allowSetDefault", "read"));
    sm.addPermission(source, new PropertyPermission("sun.boot.class.path", "read"));
    sm.addPermission(source, new PropertyPermission("sun.io.serialization.extendedDebugInfo", "read"));
    sm.addPermission(source, new PropertyPermission("sun.nio.fs.chdirAllowed", "read"));
    sm.addPermission(source, new PropertyPermission("sun.timezone.ids.oldmapping", "read"));
    sm.addPermission(source, new PropertyPermission("user.country", "read"));
    sm.addPermission(source, new PropertyPermission("user.dir", "read"));
    sm.addPermission(source, new PropertyPermission("user.timezone", "read,write"));
    sm.addPermission(source, new ReflectPermission("suppressAccessChecks"));
    sm.addPermission(source, new NetPermission("specifyStreamHandler"));
    sm.setReadOnly();/*  ww w.  j a  v  a 2 s .  c  o  m*/
    System.setSecurityManager(sm);

    xstream = new XStream(new PureJavaReflectionProvider());
    xstream.allowTypesByWildcard(AbstractAcceptanceTest.class.getPackage().getName() + ".*objects.**");
    xstream.allowTypesByWildcard(this.getClass().getName() + "$*");

    assertBothWays();
}

From source file:com.thoughtworks.acceptance.SecurityManagerTest.java

public void testSerializeWithDomDriverAndPureJavaReflectionProviderAndActiveSecurityManager() {
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.text.resources"));
    sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.util.resources"));
    sm.addPermission(source, new RuntimePermission("accessDeclaredMembers"));
    sm.addPermission(source, new RuntimePermission("createClassLoader"));
    sm.addPermission(source, new RuntimePermission("fileSystemProvider"));
    sm.addPermission(source, new RuntimePermission("loadLibrary.nio"));
    sm.addPermission(source, new RuntimePermission("modifyThreadGroup"));
    sm.addPermission(source, new RuntimePermission("reflectionFactoryAccess"));
    sm.addPermission(source, new PropertyPermission(
            "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration", "read"));
    sm.addPermission(source, new PropertyPermission("elementAttributeLimit", "read"));
    sm.addPermission(source, new PropertyPermission("entityExpansionLimit", "read"));
    sm.addPermission(source,// w  ww  .  j av a  2 s  .co m
            new PropertyPermission("http://java.sun.com/xml/dom/properties/ancestor-check", "read"));
    sm.addPermission(source, new PropertyPermission("ibm.dst.compatibility", "read"));
    sm.addPermission(source, new PropertyPermission("java.home", "read"));
    sm.addPermission(source, new PropertyPermission("java.nio.file.spi.DefaultFileSystemProvider", "read"));
    sm.addPermission(source, new PropertyPermission("java.security.debug", "read"));
    sm.addPermission(source, new PropertyPermission("javax.xml.datatype.DatatypeFactory", "read"));
    sm.addPermission(source, new PropertyPermission("javax.xml.parsers.DocumentBuilderFactory", "read"));
    sm.addPermission(source, new PropertyPermission("javax.xml.accessExternalDTD", "read"));
    sm.addPermission(source, new PropertyPermission("javax.xml.accessExternalSchema", "read"));
    sm.addPermission(source, new PropertyPermission("jaxp.debug", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.util.TimeZone.allowSetDefault", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.xml.elementAttributeLimit", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.xml.entityExpansionLimit", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.xml.maxElementDepth", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.xml.maxGeneralEntitySizeLimit", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.xml.maxParameterEntitySizeLimit", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.xml.maxOccurLimit", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.xml.maxXMLNameLimit", "read"));
    sm.addPermission(source, new PropertyPermission("jdk.xml.totalEntitySizeLimit", "read"));
    sm.addPermission(source, new PropertyPermission("maxOccurLimit", "read"));
    sm.addPermission(source, new PropertyPermission("sun.boot.class.path", "read"));
    sm.addPermission(source, new PropertyPermission("sun.nio.fs.chdirAllowed", "read"));
    sm.addPermission(source, new PropertyPermission("sun.timezone.ids.oldmapping", "read"));
    sm.addPermission(source, new PropertyPermission("user.country", "read"));
    sm.addPermission(source, new PropertyPermission("user.dir", "read"));
    sm.addPermission(source, new PropertyPermission("user.timezone", "read,write"));
    sm.addPermission(source, new NetPermission("specifyStreamHandler"));
    sm.addPermission(source, new ReflectPermission("suppressAccessChecks"));
    sm.setReadOnly();
    System.setSecurityManager(sm);

    xstream = new XStream(new PureJavaReflectionProvider(), new DomDriver());
    xstream.allowTypesByWildcard(AbstractAcceptanceTest.class.getPackage().getName() + ".*objects.**");
    xstream.allowTypesByWildcard(this.getClass().getName() + "$*");

    assertBothWays();
}