Search in sources :

Example 1 with RetentionRegistry

use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.

the class RetentionRegistryImplTest method testChangeRetentionPolicy.

public void testChangeRetentionPolicy() throws RepositoryException, NotExecutableException {
    SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
    RetentionRegistry re = s.getRetentionRegistry();
    try {
        retentionMgr.setRetentionPolicy(childN2.getPath(), getApplicableRetentionPolicy("test2"));
        superuser.save();
        retentionMgr.setRetentionPolicy(childN2.getPath(), getApplicableRetentionPolicy("test3"));
        superuser.save();
        assertTrue(re.hasEffectiveRetention(s.getQPath(childN2.getPath()), false));
    } finally {
        s.logout();
        retentionMgr.removeRetentionPolicy(childN2.getPath());
        superuser.save();
    }
}
Also used : RetentionRegistry(org.apache.jackrabbit.core.retention.RetentionRegistry)

Example 2 with RetentionRegistry

use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.

the class RetentionRegistryImplTest method testRemoveHold.

public void testRemoveHold() throws RepositoryException {
    SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
    RetentionRegistry re = s.getRetentionRegistry();
    try {
        Hold[] holds = retentionMgr.getHolds(childNPath);
        for (int i = 0; i < holds.length; i++) {
            retentionMgr.removeHold(childNPath, holds[i]);
            // hold must still be in effect.
            assertTrue(re.hasEffectiveHold(s.getQPath(childNPath), false));
        }
        superuser.save();
        assertFalse(re.hasEffectiveHold(s.getQPath(childNPath), false));
    } finally {
        s.logout();
    }
}
Also used : RetentionRegistry(org.apache.jackrabbit.core.retention.RetentionRegistry) Hold(javax.jcr.retention.Hold)

Example 3 with RetentionRegistry

use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.

the class RetentionRegistryImplTest method testSetRetentionPolicy.

public void testSetRetentionPolicy() throws RepositoryException, NotExecutableException {
    SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
    RetentionRegistry re = s.getRetentionRegistry();
    try {
        retentionMgr.setRetentionPolicy(childN2.getPath(), getApplicableRetentionPolicy("test2"));
        // retention must not be effective yet
        assertFalse(re.hasEffectiveRetention(s.getQPath(childN2.getPath()), false));
        superuser.save();
        assertTrue(re.hasEffectiveRetention(s.getQPath(childN2.getPath()), false));
    } finally {
        s.logout();
        retentionMgr.removeRetentionPolicy(childN2.getPath());
        superuser.save();
    }
}
Also used : RetentionRegistry(org.apache.jackrabbit.core.retention.RetentionRegistry)

Example 4 with RetentionRegistry

use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.

the class BatchedItemOperations method checkAddNode.

//--------------------------------------< misc. high-level helper methods >
/**
     * Checks if adding a child node called <code>nodeName</code> of node type
     * <code>nodeTypeName</code> to the given parent node is allowed in the
     * current context.
     *
     * @param parentState
     * @param nodeName
     * @param nodeTypeName
     * @param options      bit-wise OR'ed flags specifying the checks that should be
     *                     performed; any combination of the following constants:
     *                     <ul>
     *                     <li><code>{@link #CHECK_ACCESS}</code>: make sure
     *                     current session is granted read &amp; write access on
     *                     parent node</li>
     *                     <li><code>{@link #CHECK_LOCK}</code>: make sure
     *                     there's no foreign lock on parent node</li>
     *                     <li><code>{@link #CHECK_CHECKED_OUT}</code>: make sure
     *                     parent node is checked-out</li>
     *                     <li><code>{@link #CHECK_CONSTRAINTS}</code>:
     *                     make sure no node type constraints would be violated</li>
     *                     <li><code>{@link #CHECK_HOLD}</code>: check for effective holds preventing the add operation</li>
     *                     <li><code>{@link #CHECK_RETENTION}</code>: check for effective retention policy preventing the add operation</li>
     *                     </ul>
     * @throws ConstraintViolationException
     * @throws AccessDeniedException
     * @throws VersionException
     * @throws LockException
     * @throws ItemNotFoundException
     * @throws ItemExistsException
     * @throws RepositoryException
     */
public void checkAddNode(NodeState parentState, Name nodeName, Name nodeTypeName, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ItemExistsException, RepositoryException {
    Path parentPath = hierMgr.getPath(parentState.getNodeId());
    if ((options & CHECK_LOCK) == CHECK_LOCK) {
        // make sure there's no foreign lock on parent node
        verifyUnlocked(parentPath);
    }
    if ((options & CHECK_CHECKED_OUT) == CHECK_CHECKED_OUT) {
        // make sure parent node is checked-out
        verifyCheckedOut(parentPath);
    }
    if ((options & CHECK_ACCESS) == CHECK_ACCESS) {
        AccessManager accessMgr = context.getAccessManager();
        // make sure current session is granted read access on parent node
        if (!accessMgr.isGranted(parentPath, Permission.READ)) {
            throw new ItemNotFoundException(safeGetJCRPath(parentState.getNodeId()));
        }
        // make sure current session is granted write access on parent node
        if (!accessMgr.isGranted(parentPath, nodeName, Permission.ADD_NODE)) {
            throw new AccessDeniedException(safeGetJCRPath(parentState.getNodeId()) + ": not allowed to add child node");
        }
        // specified node type (and ev. mixins)
        if (!accessMgr.isGranted(parentPath, nodeName, Permission.NODE_TYPE_MNGMT)) {
            throw new AccessDeniedException(safeGetJCRPath(parentState.getNodeId()) + ": not allowed to add child node");
        }
    }
    if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
        QItemDefinition parentDef = context.getItemManager().getDefinition(parentState).unwrap();
        // make sure parent node is not protected
        if (parentDef.isProtected()) {
            throw new ConstraintViolationException(safeGetJCRPath(parentState.getNodeId()) + ": cannot add child node to protected parent node");
        }
        // make sure there's an applicable definition for new child node
        EffectiveNodeType entParent = getEffectiveNodeType(parentState);
        entParent.checkAddNodeConstraints(nodeName, nodeTypeName, context.getNodeTypeRegistry());
        QNodeDefinition newNodeDef = findApplicableNodeDefinition(nodeName, nodeTypeName, parentState);
        // check for name collisions
        if (parentState.hasChildNodeEntry(nodeName)) {
            // there's already a node with that name...
            // get definition of existing conflicting node
            ChildNodeEntry entry = parentState.getChildNodeEntry(nodeName, 1);
            NodeState conflictingState;
            NodeId conflictingId = entry.getId();
            try {
                conflictingState = (NodeState) stateMgr.getItemState(conflictingId);
            } catch (ItemStateException ise) {
                String msg = "internal error: failed to retrieve state of " + safeGetJCRPath(conflictingId);
                log.debug(msg);
                throw new RepositoryException(msg, ise);
            }
            QNodeDefinition conflictingTargetDef = context.getItemManager().getDefinition(conflictingState).unwrap();
            // check same-name sibling setting of both target and existing node
            if (!conflictingTargetDef.allowsSameNameSiblings() || !newNodeDef.allowsSameNameSiblings()) {
                throw new ItemExistsException("cannot add child node '" + nodeName.getLocalName() + "' to " + safeGetJCRPath(parentState.getNodeId()) + ": colliding with same-named existing node");
            }
        }
    }
    RetentionRegistry retentionReg = context.getSessionImpl().getRetentionRegistry();
    if ((options & CHECK_HOLD) == CHECK_HOLD) {
        if (retentionReg.hasEffectiveHold(parentPath, false)) {
            throw new RepositoryException("Unable to add node. Parent is affected by a hold.");
        }
    }
    if ((options & CHECK_RETENTION) == CHECK_RETENTION) {
        if (retentionReg.hasEffectiveRetention(parentPath, false)) {
            throw new RepositoryException("Unable to add node. Parent is affected by a retention.");
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) AccessManager(org.apache.jackrabbit.core.security.AccessManager) AccessDeniedException(javax.jcr.AccessDeniedException) NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) RepositoryException(javax.jcr.RepositoryException) RetentionRegistry(org.apache.jackrabbit.core.retention.RetentionRegistry) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) ItemExistsException(javax.jcr.ItemExistsException) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 5 with RetentionRegistry

use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.

the class BatchedItemOperations method verifyCanWrite.

/**
     * Verifies that the node at <code>nodePath</code> is writable. The
     * following conditions must hold true:
     * <ul>
     * <li>the node must exist</li>
     * <li>the current session must be granted read &amp; write access on it</li>
     * <li>the node must not be locked by another session</li>
     * <li>the node must not be checked-in</li>
     * <li>the node must not be protected</li>
     * <li>the node must not be affected by a hold or a retention policy</li>
     * </ul>
     *
     * @param nodePath path of node to check
     * @throws PathNotFoundException        if no node exists at
     *                                      <code>nodePath</code> of the current
     *                                      session is not granted read access
     *                                      to the specified path
     * @throws AccessDeniedException        if write access to the specified
     *                                      path is not allowed
     * @throws ConstraintViolationException if the node at <code>nodePath</code>
     *                                      is protected
     * @throws VersionException             if the node at <code>nodePath</code>
     *                                      is checked-in
     * @throws LockException                if the node at <code>nodePath</code>
     *                                      is locked by another session
     * @throws RepositoryException          if another error occurs
     */
public void verifyCanWrite(Path nodePath) throws PathNotFoundException, AccessDeniedException, ConstraintViolationException, VersionException, LockException, RepositoryException {
    NodeState node = getNodeState(nodePath);
    // access rights
    // make sure current session is granted read access on node
    AccessManager accessMgr = context.getAccessManager();
    if (!accessMgr.isGranted(nodePath, Permission.READ)) {
        throw new PathNotFoundException(safeGetJCRPath(node.getNodeId()));
    }
    // TODO: removed check for 'WRITE' permission on node due to the fact,
    // TODO: that add_node and set_property permission are granted on the
    // TODO: items to be create/modified and not on their parent.
    // in any case, the ability to add child-nodes and properties is checked
    // while executing the corresponding operation.
    // locking status
    verifyUnlocked(nodePath);
    // node type constraints
    verifyNotProtected(nodePath);
    // versioning status
    verifyCheckedOut(nodePath);
    RetentionRegistry retentionReg = context.getSessionImpl().getRetentionRegistry();
    if (retentionReg.hasEffectiveHold(nodePath, false)) {
        throw new RepositoryException("Unable to write. Node is affected by a hold.");
    }
    if (retentionReg.hasEffectiveRetention(nodePath, false)) {
        throw new RepositoryException("Unable to write. Node is affected by a retention.");
    }
}
Also used : AccessManager(org.apache.jackrabbit.core.security.AccessManager) NodeState(org.apache.jackrabbit.core.state.NodeState) RetentionRegistry(org.apache.jackrabbit.core.retention.RetentionRegistry) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Aggregations

RetentionRegistry (org.apache.jackrabbit.core.retention.RetentionRegistry)9 RepositoryException (javax.jcr.RepositoryException)3 Hold (javax.jcr.retention.Hold)3 AccessManager (org.apache.jackrabbit.core.security.AccessManager)3 NodeState (org.apache.jackrabbit.core.state.NodeState)3 AccessDeniedException (javax.jcr.AccessDeniedException)2 ItemNotFoundException (javax.jcr.ItemNotFoundException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)2 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)2 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)2 Path (org.apache.jackrabbit.spi.Path)2 QItemDefinition (org.apache.jackrabbit.spi.QItemDefinition)2 ItemExistsException (javax.jcr.ItemExistsException)1 ReferentialIntegrityException (javax.jcr.ReferentialIntegrityException)1 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)1 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)1 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)1