Search in sources :

Example 76 with FilePermission

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

the class RenderSecurityManagerTest method testExecute.

@Test
public void testExecute() throws Exception {
    RenderSecurityManager manager = new RenderSecurityManager(null, null);
    try {
        manager.setActive(true, myCredential);
        manager.checkPermission(new FilePermission("/foo", "execute"));
        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)

Example 77 with FilePermission

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

the class RenderSecurityManagerTest method testTempDir.

@Test
public void testTempDir() throws Exception {
    RenderSecurityManager manager = new RenderSecurityManager(null, null);
    try {
        manager.setActive(true, myCredential);
        String temp = System.getProperty("java.io.tmpdir");
        assertNotNull(temp);
        manager.checkPermission(new FilePermission(temp, "read,write"));
        manager.checkPermission(new FilePermission(temp + separator, "read,write"));
        temp = new File(temp).getCanonicalPath();
        manager.checkPermission(new FilePermission(temp, "read,write"));
    } finally {
        manager.dispose(myCredential);
    }
}
Also used : FilePermission(java.io.FilePermission) File(java.io.File) Test(org.junit.Test)

Example 78 with FilePermission

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

the class URLClassLoader method getPermissions.

/**
     * Gets all permissions for the specified {@code codesource}. First, this
     * method retrieves the permissions from the system policy. If the protocol
     * is "file:/" then a new permission, {@code FilePermission}, granting the
     * read permission to the file is added to the permission collection.
     * Otherwise, connecting to and accepting connections from the URL is
     * granted.
     *
     * @param codesource
     *            the code source object whose permissions have to be known.
     * @return the list of permissions according to the code source object.
     */
@Override
protected PermissionCollection getPermissions(final CodeSource codesource) {
    PermissionCollection pc = super.getPermissions(codesource);
    URL u = codesource.getLocation();
    if (u.getProtocol().equals("jar")) {
        try {
            // Create a URL for the resource the jar refers to
            u = ((JarURLConnection) u.openConnection()).getJarFileURL();
        } catch (IOException e) {
        // This should never occur. If it does continue using the jar
        // URL
        }
    }
    if (u.getProtocol().equals("file")) {
        String path = u.getFile();
        String host = u.getHost();
        if (host != null && host.length() > 0) {
            path = "//" + host + path;
        }
        if (File.separatorChar != '/') {
            path = path.replace('/', File.separatorChar);
        }
        if (isDirectory(u)) {
            pc.add(new FilePermission(path + "-", "read"));
        } else {
            pc.add(new FilePermission(path, "read"));
        }
    } else {
        String host = u.getHost();
        if (host.length() == 0) {
            host = "localhost";
        }
        pc.add(new SocketPermission(host, "connect, accept"));
    }
    return pc;
}
Also used : PermissionCollection(java.security.PermissionCollection) IOException(java.io.IOException) FilePermission(java.io.FilePermission)

Example 79 with FilePermission

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

the class PrintJob2D method throwPrintToFile.

private void throwPrintToFile() {
    SecurityManager security = System.getSecurityManager();
    FilePermission printToFilePermission = null;
    if (security != null) {
        if (printToFilePermission == null) {
            printToFilePermission = new FilePermission("<<ALL FILES>>", "read,write");
        }
        security.checkPermission(printToFilePermission);
    }
}
Also used : FilePermission(java.io.FilePermission)

Example 80 with FilePermission

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

the class UnixFileSystemProvider method readSymbolicLink.

@Override
public Path readSymbolicLink(Path obj1) throws IOException {
    UnixPath link = UnixPath.toUnixPath(obj1);
    // permission check
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        FilePermission perm = new FilePermission(link.getPathForPermissionCheck(), SecurityConstants.FILE_READLINK_ACTION);
        sm.checkPermission(perm);
    }
    try {
        byte[] target = readlink(link);
        return new UnixPath(link.getFileSystem(), target);
    } catch (UnixException x) {
        if (x.errno() == UnixConstants.EINVAL)
            throw new NotLinkException(link.getPathForExceptionMessage());
        x.rethrowAsIOException(link);
        // keep compiler happy
        return null;
    }
}
Also used : 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