Search in sources :

Example 1 with ItemManager

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

the class CompiledPermissionsImpl method canRead.

/**
     * @see org.apache.jackrabbit.core.security.authorization.CompiledPermissions#canRead(Path, ItemId)
     */
public boolean canRead(Path path, ItemId itemId) throws RepositoryException {
    ItemId id = (itemId == null) ? session.getHierarchyManager().resolvePath(path) : itemId;
    // no extra check for existence as method may only be called for existing items.
    boolean isExistingNode = id.denotesNode();
    boolean canRead = false;
    synchronized (monitor) {
        if (readCache.containsKey(id)) {
            canRead = readCache.get(id);
        } else {
            ItemManager itemMgr = session.getItemManager();
            NodeId nodeId = (isExistingNode) ? (NodeId) id : ((PropertyId) id).getParentId();
            NodeImpl node = (NodeImpl) itemMgr.getItem(nodeId);
            boolean isAcItem = util.isAcItem(node);
            EntryFilterImpl filter;
            if (path == null) {
                filter = new EntryFilterImpl(principalNames, id, session);
            } else {
                filter = new EntryFilterImpl(principalNames, path, session);
            }
            if (isAcItem) {
                /* item defines ac content -> regular evaluation */
                Result result = buildResult(node, isExistingNode, isAcItem, filter);
                canRead = result.grants(Permission.READ);
            } else {
                /*
                     simplified evaluation focusing on READ permission. this allows
                     to omit evaluation of parent node permissions that are
                     required when calculating the complete set of permissions
                     (see special treatment of remove, create or ac-specific
                      permissions).
                     */
                for (Entry ace : entryCollector.collectEntries(node, filter)) {
                    if (ace.getPrivilegeBits().includesRead()) {
                        canRead = ace.isAllow();
                        break;
                    }
                }
            }
            readCache.put(id, canRead);
        }
    }
    return canRead;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) ItemManager(org.apache.jackrabbit.core.ItemManager) NodeId(org.apache.jackrabbit.core.id.NodeId) ItemId(org.apache.jackrabbit.core.id.ItemId)

Example 2 with ItemManager

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

the class CompiledPermissionsImpl method buildResult.

//------------------------------------< AbstractCompiledPermissions >---
/**
     * @see AbstractCompiledPermissions#buildResult(org.apache.jackrabbit.spi.Path)
     */
@Override
protected Result buildResult(Path absPath) throws RepositoryException {
    boolean existingNode = false;
    NodeImpl node;
    ItemManager itemMgr = session.getItemManager();
    try {
        ItemImpl item = itemMgr.getItem(absPath);
        if (item.isNode()) {
            node = (NodeImpl) item;
            existingNode = true;
        } else {
            node = (NodeImpl) item.getParent();
        }
    } catch (RepositoryException e) {
        // path points to a non-persisted item.
        // -> find the nearest persisted node starting from the root.
        Path.Element[] elems = absPath.getElements();
        NodeImpl parent = (NodeImpl) session.getRootNode();
        for (int i = 1; i < elems.length - 1; i++) {
            Name name = elems[i].getName();
            int index = elems[i].getIndex();
            if (!parent.hasNode(name, index)) {
                // last persisted node reached
                break;
            }
            parent = parent.getNode(name, index);
        }
        node = parent;
    }
    if (node == null) {
        // should never get here
        throw new ItemNotFoundException("Item out of hierarchy.");
    }
    boolean isAcItem = util.isAcItem(absPath);
    return buildResult(node, existingNode, isAcItem, new EntryFilterImpl(principalNames, absPath, session));
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeImpl(org.apache.jackrabbit.core.NodeImpl) ItemManager(org.apache.jackrabbit.core.ItemManager) ItemImpl(org.apache.jackrabbit.core.ItemImpl) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 3 with ItemManager

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

the class AddNodeOperation method perform.

public Node perform(SessionContext context) throws RepositoryException {
    ItemManager itemMgr = context.getItemManager();
    // Get the canonical path of the new node
    Path path;
    try {
        path = PathFactoryImpl.getInstance().create(node.getPrimaryPath(), context.getQPath(relPath), true);
    } catch (NameException e) {
        throw new RepositoryException("Failed to resolve path " + relPath + " relative to " + node, e);
    }
    // Check that the last path element is a simple name
    if (!path.denotesName() || path.getIndex() != Path.INDEX_UNDEFINED) {
        throw new RepositoryException("Invalid last path element for adding node " + relPath + " relative to " + node);
    }
    // Get the parent node instance
    NodeImpl parentNode;
    Path parentPath = path.getAncestor(1);
    try {
        parentNode = itemMgr.getNode(parentPath);
    } catch (PathNotFoundException e) {
        if (itemMgr.propertyExists(parentPath)) {
            throw new ConstraintViolationException("Unable to add a child node to property " + context.getJCRPath(parentPath));
        }
        throw e;
    } catch (AccessDeniedException ade) {
        throw new PathNotFoundException("Failed to resolve path " + relPath + " relative to " + node);
    }
    // Resolve node type name (if any)
    Name typeName = null;
    if (nodeTypeName != null) {
        typeName = context.getQName(nodeTypeName);
    }
    // Check that the given UUID (if any) does not already exist
    NodeId id = null;
    if (uuid != null) {
        id = new NodeId(uuid);
        if (itemMgr.itemExists(id)) {
            throw new ItemExistsException("A node with this UUID already exists: " + uuid);
        }
    }
    return parentNode.addNode(path.getName(), typeName, id);
}
Also used : Path(org.apache.jackrabbit.spi.Path) AccessDeniedException(javax.jcr.AccessDeniedException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeImpl(org.apache.jackrabbit.core.NodeImpl) ItemManager(org.apache.jackrabbit.core.ItemManager) ItemExistsException(javax.jcr.ItemExistsException) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Name(org.apache.jackrabbit.spi.Name)

Aggregations

ItemManager (org.apache.jackrabbit.core.ItemManager)3 NodeImpl (org.apache.jackrabbit.core.NodeImpl)3 RepositoryException (javax.jcr.RepositoryException)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 Name (org.apache.jackrabbit.spi.Name)2 Path (org.apache.jackrabbit.spi.Path)2 AccessDeniedException (javax.jcr.AccessDeniedException)1 ItemExistsException (javax.jcr.ItemExistsException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 ItemImpl (org.apache.jackrabbit.core.ItemImpl)1 ItemId (org.apache.jackrabbit.core.id.ItemId)1 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)1