Search in sources :

Example 11 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class MembershipCache method collectDeclaredMembershipFromReferences.

/**
     * Collects the declared memberships for the given authorizable by resolving the week references to the authorizable.
     * If the lookup fails, <code>null</code> is returned. This most likely the case if the authorizable does not exit (yet)
     * in the  session that is used for the lookup.
     *
     * @param authorizableNodeIdentifier Identifier of the authorizable node
     * @param session the session to read from
     * @return a collection of group node ids or <code>null</code> if the lookup failed.
     * @throws RepositoryException if an error occurs
     */
private Collection<String> collectDeclaredMembershipFromReferences(String authorizableNodeIdentifier, Session session) throws RepositoryException {
    Set<String> pIds = new HashSet<String>();
    Set<String> nIds = new HashSet<String>();
    // Try to get membership information from references
    PropertyIterator refs = getMembershipReferences(authorizableNodeIdentifier, session);
    if (refs == null) {
        return null;
    }
    while (refs.hasNext()) {
        try {
            PropertyImpl pMember = (PropertyImpl) refs.nextProperty();
            NodeImpl nGroup = (NodeImpl) pMember.getParent();
            Set<String> groupNodeIdentifiers;
            if (P_MEMBERS.equals(pMember.getQName())) {
                // Found membership information in members property
                groupNodeIdentifiers = pIds;
            } else {
                // Found membership information in members node
                groupNodeIdentifiers = nIds;
                while (nGroup.isNodeType(NT_REP_MEMBERS)) {
                    nGroup = (NodeImpl) nGroup.getParent();
                }
            }
            if (nGroup.isNodeType(NT_REP_GROUP)) {
                groupNodeIdentifiers.add(nGroup.getIdentifier());
            } else {
                // weak-ref property 'rep:members' that doesn't reside under an
                // group node -> doesn't represent a valid group member.
                log.debug("Invalid member reference to '{}' -> Not included in membership set.", this);
            }
        } catch (ItemNotFoundException e) {
        // group node doesn't exist  -> -> ignore exception
        // and skip this reference from membership list.
        } catch (AccessDeniedException e) {
        // not allowed to see the group node -> ignore exception
        // and skip this reference from membership list.
        }
    }
    // Based on the user's setting return either of the found membership information
    return select(pIds, nIds);
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) NodeImpl(org.apache.jackrabbit.core.NodeImpl) PropertyIterator(javax.jcr.PropertyIterator) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) HashSet(java.util.HashSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

PropertyImpl (org.apache.jackrabbit.core.PropertyImpl)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)9 RepositoryException (javax.jcr.RepositoryException)6 PropertyIterator (javax.jcr.PropertyIterator)5 Value (javax.jcr.Value)4 NodeIterator (javax.jcr.NodeIterator)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 Path (org.apache.jackrabbit.spi.Path)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 Session (javax.jcr.Session)1 Event (javax.jcr.observation.Event)1 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)1 Name (org.apache.jackrabbit.spi.Name)1 StringValue (org.apache.jackrabbit.value.StringValue)1