Search in sources :

Example 71 with FilePermission

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);
}
Also used : FilePermission(java.io.FilePermission) Test(org.junit.Test)

Example 72 with FilePermission

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);
}
Also used : FilePermission(java.io.FilePermission) Test(org.junit.Test)

Example 73 with FilePermission

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);
    }
}
Also used : Field(java.lang.reflect.Field) FilePermission(java.io.FilePermission) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Test(org.junit.Test)

Example 74 with FilePermission

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);
    }
}
Also used : FilePermission(java.io.FilePermission) Test(org.junit.Test)

Example 75 with FilePermission

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);
    }
}
Also used : FilePermission(java.io.FilePermission) Test(org.junit.Test)

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