Search in sources :

Example 6 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 7 with NodeImpl

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

the class RetentionManagerImpl method getHolds.

//---------------------------------------------------< RetentionManager >---
/**
     * @see RetentionManager#getHolds(String)
     */
public Hold[] getHolds(String absPath) throws PathNotFoundException, AccessDeniedException, RepositoryException {
    NodeImpl n = (NodeImpl) session.getNode(absPath);
    session.getAccessManager().checkPermission(session.getQPath(absPath), Permission.RETENTION_MNGMT);
    Hold[] holds;
    if (n.isNodeType(REP_RETENTION_MANAGEABLE) && n.hasProperty(REP_HOLD)) {
        holds = HoldImpl.createFromProperty(n.getProperty(REP_HOLD), n.getNodeId());
    } else {
        holds = new Hold[0];
    }
    return holds;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Hold(javax.jcr.retention.Hold)

Example 8 with NodeImpl

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

the class RetentionManagerImpl method getRetentionPolicy.

/**
     * @see RetentionManager#getRetentionPolicy(String) 
     */
public RetentionPolicy getRetentionPolicy(String absPath) throws PathNotFoundException, AccessDeniedException, RepositoryException {
    NodeImpl n = (NodeImpl) session.getNode(absPath);
    session.getAccessManager().checkPermission(session.getQPath(absPath), Permission.RETENTION_MNGMT);
    RetentionPolicy rPolicy = null;
    if (n.isNodeType(REP_RETENTION_MANAGEABLE) && n.hasProperty(REP_RETENTION_POLICY)) {
        String jcrName = n.getProperty(REP_RETENTION_POLICY).getString();
        rPolicy = new RetentionPolicyImpl(jcrName, n.getNodeId(), session);
    }
    return rPolicy;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) RetentionPolicy(javax.jcr.retention.RetentionPolicy)

Example 9 with NodeImpl

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

the class RetentionManagerImpl method removeHold.

/**
     * @see RetentionManager#removeHold(String, Hold) 
     */
public void removeHold(String absPath, Hold hold) throws PathNotFoundException, AccessDeniedException, LockException, VersionException, RepositoryException {
    NodeImpl n = (NodeImpl) session.getNode(absPath);
    if (hold instanceof HoldImpl && n.getNodeId().equals(((HoldImpl) hold).getNodeId()) && n.isNodeType(REP_RETENTION_MANAGEABLE) && n.hasProperty(REP_HOLD)) {
        PropertyImpl p = n.getProperty(REP_HOLD);
        Value[] vls = p.getValues();
        List<Value> newValues = new ArrayList<Value>(vls.length - 1);
        for (Value v : vls) {
            if (!hold.equals(HoldImpl.createFromValue(v, n.getNodeId(), session))) {
                newValues.add(v);
            }
        }
        if (newValues.size() < vls.length) {
            if (newValues.size() == 0) {
                removeItem(p);
            } else {
                setProperty(n, REP_HOLD, newValues.toArray(new Value[newValues.size()]));
            }
        } else {
            // no matching hold.
            throw new RepositoryException("Cannot remove '" + hold.getName() + "' at " + absPath + ".");
        }
    } else {
        // invalid hold or no hold at absPath
        throw new RepositoryException("Cannot remove '" + hold.getName() + "' at " + absPath + ".");
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Value(javax.jcr.Value) ArrayList(java.util.ArrayList) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) RepositoryException(javax.jcr.RepositoryException)

Example 10 with NodeImpl

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

the class RetentionManagerImpl method addHold.

/**
     * @see RetentionManager#addHold(String, String, boolean) 
     */
public Hold addHold(String absPath, String name, boolean isDeep) throws PathNotFoundException, AccessDeniedException, LockException, VersionException, RepositoryException {
    NodeImpl n = (NodeImpl) session.getNode(absPath);
    if (!n.isNodeType(REP_RETENTION_MANAGEABLE)) {
        n.addMixin(REP_RETENTION_MANAGEABLE);
    }
    HoldImpl hold = new HoldImpl(session.getQName(name), isDeep, n.getNodeId(), session);
    Value[] vls;
    if (n.hasProperty(REP_HOLD)) {
        Value[] vs = n.getProperty(REP_HOLD).getValues();
        // check if the same hold already exists
        for (Value v : vs) {
            if (hold.equals(HoldImpl.createFromValue(v, n.getNodeId(), session))) {
                throw new RepositoryException("Hold already exists.");
            }
        }
        vls = new Value[vs.length + 1];
        System.arraycopy(vs, 0, vls, 0, vs.length);
    } else {
        vls = new Value[1];
    }
    // add the value of the new hold
    vls[vls.length - 1] = hold.toValue(session.getValueFactory());
    setProperty(n, REP_HOLD, vls);
    return hold;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException)

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