Search in sources :

Example 6 with PrincipalPermission

use of org.ow2.proactive.permissions.PrincipalPermission in project scheduling by ow2-proactive.

the class ClientsPolicy method getPermissions.

@Override
public PermissionCollection getPermissions(final ProtectionDomain domain) {
    try {
        readLock.lock();
        PermissionCollection permissions = new Permissions();
        // Look up permissions
        Principal[] principals = domain.getPrincipals();
        boolean identityPrincipal = false;
        if (principals != null) {
            for (Principal principal : principals) {
                if (principal instanceof IdentityPrincipal) {
                    identityPrincipal = true;
                    PermissionCollection pc = original.getPermissions(domain);
                    if (pc != null) {
                        Permission permission = new PrincipalPermission((IdentityPrincipal) principal);
                        // always adding identity permission
                        permissions.add(permission);
                        if (debug) {
                            // WARNING cannot use log4j as it may lead to recursive permission check
                            System.out.println(principal + " has " + permission);
                        }
                        for (Enumeration<Permission> en = pc.elements(); en.hasMoreElements(); ) {
                            permission = en.nextElement();
                            // boot class path, so they were not correctly resolved at JVM start up time
                            if (permission instanceof UnresolvedPermission) {
                                permission = resolvePermission((UnresolvedPermission) permission);
                                if (permission == null)
                                    continue;
                            }
                            // For IdentityPrincipal org.ow2.proactive.permissions.AllPermissions must be used
                            if (!permission.getClass().isAssignableFrom(AllPermission.class)) {
                                if (debug) {
                                    // WARNING cannot use log4j as it may lead to recursive permission check
                                    System.out.println(principal + " has " + permission);
                                }
                                permissions.add(permission);
                            }
                        }
                    }
                }
            }
        }
        if (!identityPrincipal) {
            return original.getPermissions(domain);
        }
        return permissions;
    } finally {
        readLock.unlock();
    }
}
Also used : UnresolvedPermission(java.security.UnresolvedPermission) PermissionCollection(java.security.PermissionCollection) UnresolvedPermission(java.security.UnresolvedPermission) MBeanPermission(javax.management.MBeanPermission) AllPermission(java.security.AllPermission) Permission(java.security.Permission) ClientPermission(org.ow2.proactive.permissions.ClientPermission) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) AuthPermission(javax.security.auth.AuthPermission) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) AllPermission(java.security.AllPermission) IdentityPrincipal(org.ow2.proactive.authentication.principals.IdentityPrincipal) IdentityPrincipal(org.ow2.proactive.authentication.principals.IdentityPrincipal) Principal(java.security.Principal)

Aggregations

PrincipalPermission (org.ow2.proactive.permissions.PrincipalPermission)6 Permission (java.security.Permission)3 IdentityPrincipal (org.ow2.proactive.authentication.principals.IdentityPrincipal)3 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Node (org.objectweb.proactive.core.node.Node)2 TokenPrincipal (org.ow2.proactive.authentication.principals.TokenPrincipal)2 UserNamePrincipal (org.ow2.proactive.authentication.principals.UserNamePrincipal)2 NodeSet (org.ow2.proactive.utils.NodeSet)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 AllPermission (java.security.AllPermission)1 PermissionCollection (java.security.PermissionCollection)1 Principal (java.security.Principal)1 UnresolvedPermission (java.security.UnresolvedPermission)1 ArrayList (java.util.ArrayList)1 MBeanPermission (javax.management.MBeanPermission)1 AuthPermission (javax.security.auth.AuthPermission)1 NodeInformation (org.objectweb.proactive.core.node.NodeInformation)1 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)1