use of java.io.FilePermission in project hadoop by apache.
the class TestJavaSandboxLinuxContainerRuntime method testDeny.
@Test
public void testDeny() throws Exception {
FilePermission denyPermission = new FilePermission(denyFile.getAbsolutePath(), "read");
exception.expect(java.security.AccessControlException.class);
securityManager.checkPermission(denyPermission);
}
use of java.io.FilePermission in project hadoop by apache.
the class TestJavaSandboxLinuxContainerRuntime method testGrant.
@Test
public void testGrant() throws Exception {
FilePermission grantPermission = new FilePermission(grantFile.getAbsolutePath(), "read");
securityManager.checkPermission(grantPermission);
}
use of java.io.FilePermission in project android by JetBrains.
the class RenderSecurityManagerTest method testEnterExitSafeRegion.
@Test
public void testEnterExitSafeRegion() throws Exception {
RenderSecurityManager manager = new RenderSecurityManager(null, null);
Object credential = new Object();
try {
manager.setActive(true, credential);
boolean token = RenderSecurityManager.enterSafeRegion(credential);
manager.checkPermission(new FilePermission("/foo", "execute"));
RenderSecurityManager.exitSafeRegion(token);
assertNotNull(RenderSecurityManager.getCurrent());
boolean tokenOuter = RenderSecurityManager.enterSafeRegion(credential);
assertNull(RenderSecurityManager.getCurrent());
boolean tokenInner = RenderSecurityManager.enterSafeRegion(credential);
assertNull(RenderSecurityManager.getCurrent());
manager.checkPermission(new FilePermission("/foo", "execute"));
assertNull(RenderSecurityManager.getCurrent());
manager.checkPermission(new FilePermission("/foo", "execute"));
RenderSecurityManager.exitSafeRegion(tokenInner);
assertNull(RenderSecurityManager.getCurrent());
RenderSecurityManager.exitSafeRegion(tokenOuter);
assertNotNull(RenderSecurityManager.getCurrent());
// Wrong credential
Object wrongCredential = new Object();
try {
token = RenderSecurityManager.enterSafeRegion(wrongCredential);
manager.checkPermission(new FilePermission("/foo", "execute"));
RenderSecurityManager.exitSafeRegion(token);
fail("Should have thrown exception");
} catch (SecurityException e) {
// pass
}
// Try turning off the security manager
try {
manager.setActive(false, wrongCredential);
} catch (SecurityException e) {
// pass
}
try {
manager.setActive(false, null);
} catch (SecurityException e) {
// pass
}
try {
manager.dispose(wrongCredential);
} catch (SecurityException e) {
// pass
}
// Try looking up the secret
try {
Field field = RenderSecurityManager.class.getField("sCredential");
field.setAccessible(true);
Object secret = field.get(null);
manager.dispose(secret);
fail("Shouldn't be able to find our way to the credential");
} catch (Exception e) {
// pass
assertEquals("java.lang.NoSuchFieldException: sCredential", e.toString());
}
} finally {
manager.dispose(credential);
}
}
use of java.io.FilePermission in project android by JetBrains.
the class RenderSecurityManagerTest method testDelete.
@Test
public void testDelete() throws Exception {
RenderSecurityManager manager = new RenderSecurityManager(null, null);
try {
manager.setActive(true, myCredential);
manager.checkPermission(new FilePermission("/foo", "delete"));
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 testAppTempDir.
@Test
public void testAppTempDir() throws Exception {
RenderSecurityManager manager = new RenderSecurityManager(null, null);
try {
manager.setAppTempDir("/random/path/");
manager.setActive(true, myCredential);
manager.checkPermission(new FilePermission("/random/path/myfile.tmp", "read,write"));
} finally {
manager.dispose(myCredential);
}
}
Aggregations