Search in sources :

Example 11 with FilePermission

use of java.io.FilePermission in project joda-time by JodaOrg.

the class TestDateTimeZone method testZoneInfoProviderResourceLoading.

public void testZoneInfoProviderResourceLoading() {
    final Set<String> ids = new HashSet<String>(DateTimeZone.getAvailableIDs());
    ids.remove(DateTimeZone.getDefault().getID());
    final String id = ids.toArray(new String[ids.size()])[new Random().nextInt(ids.size())];
    try {
        Policy.setPolicy(new Policy() {

            @Override
            public PermissionCollection getPermissions(CodeSource codesource) {
                Permissions p = new Permissions();
                // enable everything
                p.add(new AllPermission());
                return p;
            }

            @Override
            public void refresh() {
            }

            @Override
            public boolean implies(ProtectionDomain domain, Permission permission) {
                return !(permission instanceof FilePermission) && !permission.getName().contains(id);
            }
        });
        System.setSecurityManager(new SecurityManager());
        // will throw IllegalArgumentException if the resource can
        // not be loaded
        final DateTimeZone zone = DateTimeZone.forID(id);
        assertNotNull(zone);
    } finally {
        System.setSecurityManager(null);
        Policy.setPolicy(ALLOW);
    }
}
Also used : Policy(java.security.Policy) PermissionCollection(java.security.PermissionCollection) ProtectionDomain(java.security.ProtectionDomain) CodeSource(java.security.CodeSource) FilePermission(java.io.FilePermission) Random(java.util.Random) Permissions(java.security.Permissions) AllPermission(java.security.AllPermission) FilePermission(java.io.FilePermission) Permission(java.security.Permission) AllPermission(java.security.AllPermission) HashSet(java.util.HashSet)

Example 12 with FilePermission

use of java.io.FilePermission in project jdk8u_jdk by JetBrains.

the class MyBasicPermission method tryFilePC.

static void tryFilePC() throws Exception {
    try {
        FilePermission p0 = new FilePermission("/home/foobar", "read");
        PermissionCollection pc = p0.newPermissionCollection();
        // this should lock out future adds
        pc.setReadOnly();
        //
        FilePermission p1 = new FilePermission("/home/quux", "read");
        pc.add(p1);
        throw new Exception("Failed...FilePermission added to readonly FilePermissionCollection.");
    } catch (SecurityException se) {
        System.out.println("FilePermissionCollection passed");
    }
}
Also used : FilePermission(java.io.FilePermission)

Example 13 with FilePermission

use of java.io.FilePermission in project wildfly by wildfly.

the class ServiceRefSevletTestCase method clientDeployment.

@Deployment(name = "servletClient", testable = false)
public static WebArchive clientDeployment() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, "ws-serviceref-example-servlet-client.war").addClasses(EndpointInterface.class, EndpointService.class, ServletClient.class).addAsWebInfResource(ServiceRefSevletTestCase.class.getPackage(), "web.xml", "web.xml").addAsWebInfResource(ServiceRefSevletTestCase.class.getPackage(), "jboss-web.xml", "jboss-web.xml");
    String wsdl = FileUtils.readFile(ServiceRefSevletTestCase.class, "TestService.wsdl");
    final Properties properties = new Properties();
    properties.putAll(System.getProperties());
    final String node0 = NetworkUtils.formatPossibleIpv6Address((String) properties.get("node0"));
    if (properties.containsKey("node0")) {
        properties.put("node0", node0);
    }
    war.addAsWebInfResource(new StringAsset(PropertiesValueResolver.replaceProperties(wsdl, properties)), "wsdl/TestService.wsdl");
    // all the following permissions are needed because EndpointService directly extends javax.xml.ws.Service class
    // and CXF guys are not willing to add more privileged blocks into their code, thus deployments need to have
    // the following permissions (note that the wsdl.properties permission is needed by wsdl4j)
    war.addAsManifestResource(createPermissionsXmlAsset(new FilePermission(System.getProperty("java.home") + File.separator + "lib" + File.separator + "wsdl.properties", "read"), new PropertyPermission("user.dir", "read"), new RuntimePermission("getClassLoader"), new RuntimePermission("org.apache.cxf.permission", "resolveUri"), new RuntimePermission("createClassLoader"), new RuntimePermission("accessDeclaredMembers"), new SocketPermission(node0 + ":8080", "connect,resolve")), "jboss-permissions.xml");
    return war;
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) PropertyPermission(java.util.PropertyPermission) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) SocketPermission(java.net.SocketPermission) Properties(java.util.Properties) FilePermission(java.io.FilePermission) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 14 with FilePermission

use of java.io.FilePermission in project wildfly by wildfly.

the class DeploymentHelper method getWebArchiveWithPermissions.

public WebArchive getWebArchiveWithPermissions(final String archiveName) {
    final String javaHome = TestSuiteEnvironment.getSystemProperty("java.home");
    final String serverHostPort = TestSuiteEnvironment.getServerAddress() + ":" + TestSuiteEnvironment.getHttpPort();
    final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archiveName + ".war").addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")).addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new ReflectPermission("suppressAccessChecks"), new ReflectPermission("accessDeclaredMembers"), // Permissions for port access
    new PropertyPermission("management.address", "read"), new PropertyPermission("node0", "read"), new PropertyPermission("jboss.http.port", "read"), new SocketPermission(serverHostPort, "connect,resolve"), // Permissions for the new client creation
    new RuntimePermission("accessDeclaredMembers"), new RuntimePermission("createClassLoader"), new RuntimePermission("getClassLoader"), new RuntimePermission("org.apache.cxf.permission"), new FilePermission(javaHome + File.separator + "lib" + File.separator + "wsdl.properties", "read"), new PropertyPermission("user.dir", "read"), new PropertyPermission("arquillian.debug", "read"), new FilePermission(System.getProperty("basedir") + File.separator + "target" + File.separator + "workdir" + File.separator + "xcatalog", "read")), "permissions.xml");
    return webArchive;
}
Also used : PropertyPermission(java.util.PropertyPermission) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) SocketPermission(java.net.SocketPermission) ReflectPermission(java.lang.reflect.ReflectPermission) FilePermission(java.io.FilePermission)

Example 15 with FilePermission

use of java.io.FilePermission in project android by JetBrains.

the class RenderSecurityManagerTest method testReadWrite.

@Test
public void testReadWrite() throws Exception {
    RenderSecurityManager manager = new RenderSecurityManager(null, null);
    try {
        manager.setActive(true, myCredential);
        manager.checkPermission(new FilePermission("/foo", "read,write"));
        fail("Should have thrown security exception");
    } catch (SecurityException exception) {
        assertEquals("Write access not allowed during rendering (/foo)", exception.toString());
    // pass
    } finally {
        manager.dispose(myCredential);
    }
}
Also used : FilePermission(java.io.FilePermission) Test(org.junit.Test)

Aggregations

FilePermission (java.io.FilePermission)88 IOException (java.io.IOException)16 File (java.io.File)14 URL (java.net.URL)14 SocketPermission (java.net.SocketPermission)13 Permission (java.security.Permission)13 Test (org.junit.Test)12 PermissionCollection (java.security.PermissionCollection)11 Permissions (java.security.Permissions)10 CodeSource (java.security.CodeSource)7 PropertyPermission (java.util.PropertyPermission)7 Path (java.nio.file.Path)6 Deployment (org.jboss.arquillian.container.test.api.Deployment)6 TestCondition (ext.framework.b.TestCondition)5 Policy (java.security.Policy)5 URLClassLoader (java.net.URLClassLoader)4 ProtectionDomain (java.security.ProtectionDomain)4 Properties (java.util.Properties)4 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)4 FileInputStream (java.io.FileInputStream)3