Search in sources :

Example 86 with PermissionCollection

use of java.security.PermissionCollection in project scout.rt by eclipse.

the class SharedAccessControlServiceTest method testClearCache.

/**
 * Test method for
 * {@link org.eclipse.scout.rt.shared.services.common.security.AbstractAccessControlService#clearCache()}.
 */
@Test
public void testClearCache() throws ProcessingException {
    PermissionCollection p1 = m_accessControlService.getPermissions();
    PermissionCollection p2 = m_accessControlService.getPermissions();
    assertSame(p1, p2);
    m_accessControlService.clearCache();
    PermissionCollection p3 = m_accessControlService.getPermissions();
    assertNotSame(p1, p3);
}
Also used : PermissionCollection(java.security.PermissionCollection) Test(org.junit.Test)

Example 87 with PermissionCollection

use of java.security.PermissionCollection in project scout.rt by eclipse.

the class SharedAccessControlServiceTest method testGetPermissions.

/**
 * Test method for
 * {@link org.eclipse.scout.rt.shared.services.common.security.AbstractAccessControlService#getPermissions()}.
 */
@Test
public void testGetPermissions() {
    PermissionCollection permissions = m_accessControlService.getPermissions();
    assertNotNull(permissions);
}
Also used : PermissionCollection(java.security.PermissionCollection) Test(org.junit.Test)

Example 88 with PermissionCollection

use of java.security.PermissionCollection in project scout.rt by eclipse.

the class SharedAccessControlServiceTest method testClearCacheOfUserIds.

/**
 * Test method for
 * {@link org.eclipse.scout.rt.shared.services.common.security.AbstractAccessControlService#clearCacheOfUserIds(java.util.Collection)}
 * .
 */
@Test
public void testClearCacheOfUserIds() throws ProcessingException {
    PermissionCollection p1 = m_accessControlService.getPermissions();
    PermissionCollection p2 = m_accessControlService.getPermissions();
    assertSame(p1, p2);
    m_accessControlService.clearCache(Collections.<String>emptyList());
    PermissionCollection p3 = m_accessControlService.getPermissions();
    assertSame(p1, p3);
    m_accessControlService.clearCache(Collections.<String>singletonList(null));
    PermissionCollection p4 = m_accessControlService.getPermissions();
    assertSame(p1, p4);
    m_accessControlService.clearCache(Collections.singletonList(TEST_USER));
    PermissionCollection p5 = m_accessControlService.getPermissions();
    PermissionCollection p6 = m_accessControlService.getPermissions();
    assertNotSame(p1, p5);
    assertNotSame(p1, p6);
    assertSame(p5, p6);
}
Also used : PermissionCollection(java.security.PermissionCollection) Test(org.junit.Test)

Example 89 with PermissionCollection

use of java.security.PermissionCollection in project tomcat by apache.

the class WebappClassLoaderBase method getPermissions.

/**
 * Get the Permissions for a CodeSource.  If this instance
 * of WebappClassLoaderBase is for a web application context,
 * add read FilePermission for the appropriate resources.
 *
 * @param codeSource where the code was loaded from
 * @return PermissionCollection for CodeSource
 */
@Override
protected PermissionCollection getPermissions(CodeSource codeSource) {
    String codeUrl = codeSource.getLocation().toString();
    PermissionCollection pc;
    if ((pc = loaderPC.get(codeUrl)) == null) {
        pc = super.getPermissions(codeSource);
        if (pc != null) {
            for (Permission p : permissionList) {
                pc.add(p);
            }
            loaderPC.put(codeUrl, pc);
        }
    }
    return pc;
}
Also used : PermissionCollection(java.security.PermissionCollection) FilePermission(java.io.FilePermission) Permission(java.security.Permission)

Example 90 with PermissionCollection

use of java.security.PermissionCollection in project tomcat by apache.

the class WebappClassLoaderBase method check.

@Override
public boolean check(Permission permission) {
    if (!Globals.IS_SECURITY_ENABLED) {
        return true;
    }
    Policy currentPolicy = Policy.getPolicy();
    if (currentPolicy != null) {
        URL contextRootUrl = resources.getResource("/").getCodeBase();
        CodeSource cs = new CodeSource(contextRootUrl, (Certificate[]) null);
        PermissionCollection pc = currentPolicy.getPermissions(cs);
        if (pc.implies(permission)) {
            return true;
        }
    }
    return false;
}
Also used : Policy(java.security.Policy) PermissionCollection(java.security.PermissionCollection) CodeSource(java.security.CodeSource) URL(java.net.URL) Certificate(java.security.cert.Certificate)

Aggregations

PermissionCollection (java.security.PermissionCollection)107 Permission (java.security.Permission)39 Permissions (java.security.Permissions)29 CodeSource (java.security.CodeSource)25 FilePermission (java.io.FilePermission)20 ProtectionDomain (java.security.ProtectionDomain)19 AllPermission (java.security.AllPermission)16 Policy (java.security.Policy)15 URL (java.net.URL)14 File (java.io.File)10 IOException (java.io.IOException)10 Certificate (java.security.cert.Certificate)8 AccessControlContext (java.security.AccessControlContext)7 PropertyPermission (java.util.PropertyPermission)7 Test (org.junit.Test)7 SocketPermission (java.net.SocketPermission)6 Method (java.lang.reflect.Method)5 Principal (java.security.Principal)5 PrivilegedActionException (java.security.PrivilegedActionException)5 URLClassLoader (java.net.URLClassLoader)4