Search in sources :

Example 1 with PrivilegeManagerImpl

use of org.apache.jackrabbit.core.security.authorization.PrivilegeManagerImpl in project jackrabbit by apache.

the class Entry method readEntries.

static List<Entry> readEntries(NodeImpl aclNode, String path) throws RepositoryException {
    if (aclNode == null || !NT_REP_ACL.equals(aclNode.getPrimaryNodeTypeName())) {
        throw new IllegalArgumentException("Node must be of type 'rep:ACL'");
    }
    SessionImpl sImpl = (SessionImpl) aclNode.getSession();
    PrincipalManager principalMgr = sImpl.getPrincipalManager();
    PrivilegeManagerImpl privilegeMgr = (PrivilegeManagerImpl) ((JackrabbitWorkspace) sImpl.getWorkspace()).getPrivilegeManager();
    NodeId nodeId = aclNode.getParentId();
    List<Entry> entries = new ArrayList<Entry>();
    // load the entries:
    NodeIterator itr = aclNode.getNodes();
    while (itr.hasNext()) {
        NodeImpl aceNode = (NodeImpl) itr.nextNode();
        try {
            String principalName = aceNode.getProperty(P_PRINCIPAL_NAME).getString();
            boolean isGroupEntry = false;
            Principal princ = principalMgr.getPrincipal(principalName);
            if (princ != null) {
                isGroupEntry = (princ instanceof Group);
            }
            InternalValue[] privValues = aceNode.getProperty(P_PRIVILEGES).internalGetValues();
            Name[] privNames = new Name[privValues.length];
            for (int i = 0; i < privValues.length; i++) {
                privNames[i] = privValues[i].getName();
            }
            Value globValue = null;
            if (aceNode.hasProperty(P_GLOB)) {
                globValue = aceNode.getProperty(P_GLOB).getValue();
            }
            boolean isAllow = NT_REP_GRANT_ACE.equals(aceNode.getPrimaryNodeTypeName());
            Entry ace = new Entry(nodeId, principalName, isGroupEntry, privilegeMgr.getBits(privNames), isAllow, path, globValue);
            entries.add(ace);
        } catch (RepositoryException e) {
            log.debug("Failed to build ACE from content. {}", e.getMessage());
        }
    }
    return entries;
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) NodeIterator(javax.jcr.NodeIterator) Group(java.security.acl.Group) NodeImpl(org.apache.jackrabbit.core.NodeImpl) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Value(javax.jcr.Value) SessionImpl(org.apache.jackrabbit.core.SessionImpl) Principal(java.security.Principal) PrivilegeManagerImpl(org.apache.jackrabbit.core.security.authorization.PrivilegeManagerImpl)

Aggregations

Principal (java.security.Principal)1 Group (java.security.acl.Group)1 ArrayList (java.util.ArrayList)1 NodeIterator (javax.jcr.NodeIterator)1 RepositoryException (javax.jcr.RepositoryException)1 Value (javax.jcr.Value)1 PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)1 NodeImpl (org.apache.jackrabbit.core.NodeImpl)1 SessionImpl (org.apache.jackrabbit.core.SessionImpl)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 PrivilegeManagerImpl (org.apache.jackrabbit.core.security.authorization.PrivilegeManagerImpl)1 InternalValue (org.apache.jackrabbit.core.value.InternalValue)1 Name (org.apache.jackrabbit.spi.Name)1