Search in sources :

Example 46 with NodeImpl

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

the class ACLEditor method setPolicy.

/**
 * @see AccessControlEditor#setPolicy(String,AccessControlPolicy)
 */
public void setPolicy(String nodePath, AccessControlPolicy policy) throws AccessControlException, PathNotFoundException, RepositoryException {
    checkProtectsNode(nodePath);
    checkValidPolicy(nodePath, policy);
    ACLTemplate acl = (ACLTemplate) policy;
    NodeImpl acNode = getAcNode(nodePath);
    if (acNode == null) {
        throw new PathNotFoundException("No such node " + nodePath);
    }
    // write the entries to the node
    NodeImpl aclNode;
    if (acNode.hasNode(N_POLICY)) {
        aclNode = acNode.getNode(N_POLICY);
        // remove all existing aces
        for (NodeIterator aceNodes = aclNode.getNodes(); aceNodes.hasNext(); ) {
            NodeImpl aceNode = (NodeImpl) aceNodes.nextNode();
            removeItem(aceNode);
        }
    } else {
        /* doesn't exist yet -> create */
        aclNode = addNode(acNode, N_POLICY, NT_REP_ACL);
    }
    /* add all new entries defined on the template */
    AccessControlEntry[] aces = acl.getAccessControlEntries();
    for (AccessControlEntry ace1 : aces) {
        AccessControlEntryImpl ace = (AccessControlEntryImpl) ace1;
        // create the ACE node
        Name nodeName = getUniqueNodeName(aclNode, "entry");
        Name ntName = (ace.isAllow()) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
        NodeImpl aceNode = addNode(aclNode, nodeName, ntName);
        ValueFactory vf = session.getValueFactory();
        // write the rep:principalName property
        setProperty(aceNode, P_PRINCIPAL_NAME, vf.createValue(ace.getPrincipal().getName()));
        // ... and the rep:privileges property
        Privilege[] privs = ace.getPrivileges();
        Value[] vs = new Value[privs.length];
        for (int j = 0; j < privs.length; j++) {
            vs[j] = vf.createValue(privs[j].getName(), PropertyType.NAME);
        }
        setProperty(aceNode, P_PRIVILEGES, vs);
        // store the restrictions:
        Set<Name> restrNames = ace.getRestrictions().keySet();
        for (Name restrName : restrNames) {
            Value value = ace.getRestriction(restrName);
            setProperty(aceNode, restrName, value);
        }
    }
    // mark the parent modified.
    markModified((NodeImpl) aclNode.getParent());
}
Also used : NodeIterator(javax.jcr.NodeIterator) AccessControlEntryImpl(org.apache.jackrabbit.core.security.authorization.AccessControlEntryImpl) NodeImpl(org.apache.jackrabbit.core.NodeImpl) AccessControlEntry(javax.jcr.security.AccessControlEntry) ValueFactory(javax.jcr.ValueFactory) Name(org.apache.jackrabbit.spi.Name) Value(javax.jcr.Value) PathNotFoundException(javax.jcr.PathNotFoundException) Privilege(javax.jcr.security.Privilege)

Example 47 with NodeImpl

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

the class ACLEditor method editAccessControlPolicies.

/**
 * @see AccessControlEditor#editAccessControlPolicies(Principal)
 */
public JackrabbitAccessControlPolicy[] editAccessControlPolicies(Principal principal) throws RepositoryException {
    if (!session.getPrincipalManager().hasPrincipal(principal.getName())) {
        throw new AccessControlException("Cannot edit access control: " + principal.getName() + " isn't a known principal.");
    }
    String nPath = getPathToAcNode(principal);
    NodeImpl acNode;
    if (!session.nodeExists(nPath)) {
        acNode = createAcNode(nPath);
    } else {
        acNode = (NodeImpl) session.getNode(nPath);
    }
    if (!isAccessControlled(acNode)) {
        return new JackrabbitAccessControlPolicy[] { createTemplate(acNode) };
    } else {
        // no additional applicable policies present.
        return new JackrabbitAccessControlPolicy[0];
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)

Example 48 with NodeImpl

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

the class ACLEditor method getPolicies.

// ------------------------------------------------< AccessControlEditor >---
/**
 * @see AccessControlEditor#getPolicies(String)
 */
public AccessControlPolicy[] getPolicies(String nodePath) throws AccessControlException, PathNotFoundException, RepositoryException {
    checkProtectsNode(nodePath);
    NodeImpl aclNode = getAclNode(nodePath);
    if (aclNode == null) {
        return new AccessControlPolicy[0];
    } else {
        return new AccessControlPolicy[] { getACL(aclNode, nodePath) };
    }
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NodeImpl(org.apache.jackrabbit.core.NodeImpl)

Example 49 with NodeImpl

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

the class ACLEditor method setPolicy.

/**
 * @see AccessControlEditor#setPolicy(String,AccessControlPolicy)
 */
public void setPolicy(String nodePath, AccessControlPolicy policy) throws RepositoryException {
    checkProtectsNode(nodePath);
    checkValidPolicy(nodePath, policy);
    NodeImpl aclNode = getAclNode(nodePath);
    if (aclNode != null) {
        // remove all existing aces
        for (NodeIterator aceNodes = aclNode.getNodes(); aceNodes.hasNext(); ) {
            NodeImpl aceNode = (NodeImpl) aceNodes.nextNode();
            removeItem(aceNode);
        }
    } else {
        // create the acl node
        aclNode = (nodePath == null) ? createRepoAclNode() : createAclNode(nodePath);
    }
    AccessControlEntry[] entries = ((ACLTemplate) policy).getAccessControlEntries();
    for (AccessControlEntry entry : entries) {
        AccessControlEntryImpl ace = (AccessControlEntryImpl) entry;
        Name nodeName = getUniqueNodeName(aclNode, ace.isAllow() ? "allow" : "deny");
        Name ntName = (ace.isAllow()) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
        ValueFactory vf = session.getValueFactory();
        // create the ACE node
        NodeImpl aceNode = addNode(aclNode, nodeName, ntName);
        // write the rep:principalName property
        String principalName = ace.getPrincipal().getName();
        setProperty(aceNode, P_PRINCIPAL_NAME, vf.createValue(principalName));
        // ... and the rep:privileges property
        Privilege[] pvlgs = ace.getPrivileges();
        Value[] names = getPrivilegeNames(pvlgs, vf);
        setProperty(aceNode, P_PRIVILEGES, names);
        // store the restrictions:
        Set<Name> restrNames = ace.getRestrictions().keySet();
        for (Name restrName : restrNames) {
            Value value = ace.getRestriction(restrName);
            setProperty(aceNode, restrName, value);
        }
    }
    // mark the parent modified.
    markModified(((NodeImpl) aclNode.getParent()));
}
Also used : NodeIterator(javax.jcr.NodeIterator) AccessControlEntryImpl(org.apache.jackrabbit.core.security.authorization.AccessControlEntryImpl) NodeImpl(org.apache.jackrabbit.core.NodeImpl) AccessControlEntry(javax.jcr.security.AccessControlEntry) ValueFactory(javax.jcr.ValueFactory) Name(org.apache.jackrabbit.spi.Name) Value(javax.jcr.Value) Privilege(javax.jcr.security.Privilege)

Example 50 with NodeImpl

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

the class ACLEditor method removePolicy.

/**
 * @see AccessControlEditor#removePolicy(String,AccessControlPolicy)
 */
public synchronized void removePolicy(String nodePath, AccessControlPolicy policy) throws AccessControlException, RepositoryException {
    checkProtectsNode(nodePath);
    checkValidPolicy(nodePath, policy);
    NodeImpl aclNode = getAclNode(nodePath);
    if (aclNode != null) {
        removeItem(aclNode);
    } else {
        throw new AccessControlException("No policy to remove at " + nodePath);
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) AccessControlException(javax.jcr.security.AccessControlException)

Aggregations

NodeImpl (org.apache.jackrabbit.core.NodeImpl)161 RepositoryException (javax.jcr.RepositoryException)34 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)29 NodeId (org.apache.jackrabbit.core.id.NodeId)25 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)18 ArrayList (java.util.ArrayList)17 Value (javax.jcr.Value)16 Name (org.apache.jackrabbit.spi.Name)16 AccessControlEntry (javax.jcr.security.AccessControlEntry)15 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)13 AccessControlManager (javax.jcr.security.AccessControlManager)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 InputStream (java.io.InputStream)12 NodeIterator (javax.jcr.NodeIterator)12 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Principal (java.security.Principal)10 Node (javax.jcr.Node)10 ParsingContentHandler (org.apache.jackrabbit.commons.xml.ParsingContentHandler)10 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)9