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);
}
}
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);
}
}
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;
}
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);
}
}
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;
}
}
Aggregations