Search in sources :

Example 1 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit-oak by apache.

the class JackrabbitNodeState method createRootNodeState.

public static JackrabbitNodeState createRootNodeState(RepositoryContext context, String workspaceName, NodeState root, Map<String, String> uriToPrefix, boolean copyBinariesByReference, boolean skipOnError) throws RepositoryException {
    final Map<NodeId, JackrabbitNodeState> emptyMountPoints = ImmutableMap.of();
    final PersistenceManager versionPM = context.getInternalVersionManager().getPersistenceManager();
    final JackrabbitNodeState versionStorage = new JackrabbitNodeState(versionPM, root, uriToPrefix, VERSION_STORAGE_NODE_ID, "/jcr:system/jcr:versionStorage", null, emptyMountPoints, copyBinariesByReference, skipOnError);
    final JackrabbitNodeState activities = new JackrabbitNodeState(versionPM, root, uriToPrefix, ACTIVITIES_NODE_ID, "/jcr:system/jcr:activities", null, emptyMountPoints, copyBinariesByReference, skipOnError);
    PersistenceManager pm = context.getWorkspaceInfo(workspaceName).getPersistenceManager();
    final Map<NodeId, JackrabbitNodeState> mountPoints = ImmutableMap.of(VERSION_STORAGE_NODE_ID, versionStorage, ACTIVITIES_NODE_ID, activities);
    return new JackrabbitNodeState(pm, root, uriToPrefix, ROOT_NODE_ID, "/", workspaceName, mountPoints, copyBinariesByReference, skipOnError);
}
Also used : PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 2 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit-oak by apache.

the class JackrabbitNodeState method getChildNodeEntries.

@Nonnull
@Override
public Iterable<MemoryChildNodeEntry> getChildNodeEntries() {
    List<MemoryChildNodeEntry> entries = newArrayListWithCapacity(nodes.size());
    for (Map.Entry<String, NodeId> entry : nodes.entrySet()) {
        String name = entry.getKey();
        final NodeState child = createChildNodeState(entry.getValue(), name);
        if (child != null) {
            entries.add(new MemoryChildNodeEntry(name, child));
        }
    }
    return entries;
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractNodeState(org.apache.jackrabbit.oak.spi.state.AbstractNodeState) NodeId(org.apache.jackrabbit.core.id.NodeId) MemoryChildNodeEntry(org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Nonnull(javax.annotation.Nonnull)

Example 3 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project pentaho-platform by pentaho.

the class PentahoCompiledPermissionsImpl method buildResult.

private Result buildResult(NodeImpl node, boolean isExistingNode, boolean isAcItem, EntryFilterImpl filter) throws RepositoryException {
    // retrieve all ACEs at path or at the direct ancestor of path that
    // apply for the principal names.
    NodeImpl n = ACLProvider.getNode(node, isAcItem);
    Iterator entries = entryCollector.collectEntries(n, filter).iterator();
    /*
     * Calculate privileges and permissions: Since the ACEs only define privileges on a node and do not allow to
     * add additional restrictions, the permissions can be determined without taking the given target name or
     * target item into account.
     */
    int allows = Permission.NONE;
    int denies = Permission.NONE;
    PrivilegeBits allowBits = PrivilegeBits.getInstance();
    PrivilegeBits denyBits = PrivilegeBits.getInstance();
    PrivilegeBits parentAllowBits = PrivilegeBits.getInstance();
    PrivilegeBits parentDenyBits = PrivilegeBits.getInstance();
    String parentPath = Text.getRelativeParent(filter.getPath(), 1);
    NodeId nodeId = (node == null) ? null : node.getNodeId();
    while (entries.hasNext()) {
        Object ace = entries.next();
        /*
       * Determine if the ACE also takes effect on the parent: Some permissions (e.g. add-node or removal) must be
       * determined from privileges defined for the parent. A 'local' entry defined on the target node never
       * effects the parent. For inherited ACEs determine if the ACE matches the parent path.
       */
        PrivilegeBits entryBits = null;
        boolean isLocal = false;
        boolean matchesParent = false;
        boolean isAllow = false;
        if (ace instanceof PentahoEntry) {
            entryBits = (((PentahoEntry) ace).getPrivilegeBits());
            isLocal = isExistingNode && ((PentahoEntry) ace).isLocal(nodeId);
            matchesParent = (!isLocal && ((PentahoEntry) ace).matches(parentPath));
            isAllow = ((PentahoEntry) ace).isAllow();
        } else {
            entryBits = ((Entry) ace).getPrivilegeBits();
            isLocal = isExistingNode && ((Entry) ace).isLocal(nodeId);
            matchesParent = (!isLocal && ((Entry) ace).matches(parentPath));
            isAllow = ((Entry) ace).isAllow();
        }
        // check specific case: "Inherit permissions" may have been unchecked, and node operation permissions may
        // have been granted directly to the item ( thus not requiring having those permissions defined for the parent )
        boolean isLocalAndDoesNotInheritPermissions = isLocal && isValidPentahoNode(node) && !isEntriesInheriting(node);
        if (matchesParent || isLocalAndDoesNotInheritPermissions) {
            if (isAllow) {
                parentAllowBits.addDifference(entryBits, parentDenyBits);
            } else {
                parentDenyBits.addDifference(entryBits, parentAllowBits);
            }
        }
        if (isAllow) {
            allowBits.addDifference(entryBits, denyBits);
            int permissions = PrivilegeRegistry.calculatePermissions(allowBits, parentAllowBits, true, isAcItem);
            allows |= Permission.diff(permissions, denies);
        } else {
            denyBits.addDifference(entryBits, allowBits);
            int permissions = PrivilegeRegistry.calculatePermissions(denyBits, parentDenyBits, false, isAcItem);
            denies |= Permission.diff(permissions, allows);
        }
    }
    return new Result(allows, denies, allowBits, denyBits);
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Iterator(java.util.Iterator) NodeId(org.apache.jackrabbit.core.id.NodeId) PrivilegeBits(org.apache.jackrabbit.core.security.authorization.PrivilegeBits)

Example 4 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project pentaho-platform by pentaho.

the class CachingPentahoEntryCollector method getNextID.

/**
 * Find the next access control ancestor in the hierarchy 'null' indicates that there is no ac-controlled ancestor.
 *
 * @param node The target node for which the cache needs to be updated.
 * @return The NodeId of the next access controlled ancestor in the hierarchy or null
 */
private NodeId getNextID(NodeImpl node) throws RepositoryException {
    NodeImpl n = node;
    NodeId nextId = null;
    while (nextId == null && !isRootId(n.getNodeId())) {
        NodeId parentId = n.getParentId();
        if (getCache().containsKey(parentId)) {
            nextId = parentId;
        } else {
            NodeImpl parent = (NodeImpl) n.getParent();
            if (hasEntries(parent)) {
                nextId = parentId;
            } else {
                // try next ancestor
                n = parent;
            }
        }
    }
    return nextId;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 5 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project pentaho-platform by pentaho.

the class CachingPentahoEntryCollector method getEntries.

// -----------------------------------------------------< EntryCollector >---
/**
 * @see EntryCollector#getEntries(org.apache.jackrabbit.core.NodeImpl)
 */
@Override
protected PentahoEntries getEntries(NodeImpl node) throws RepositoryException {
    NodeId nodeId = node.getNodeId();
    Entries entries = getCache().get(nodeId);
    if (entries == null) {
        // fetch entries and update the cache
        entries = updateCache(node);
    }
    return entries instanceof PentahoEntries ? (PentahoEntries) entries : new PentahoEntries(entries);
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId)

Aggregations

NodeId (org.apache.jackrabbit.core.id.NodeId)213 RepositoryException (javax.jcr.RepositoryException)70 NodeState (org.apache.jackrabbit.core.state.NodeState)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)48 Name (org.apache.jackrabbit.spi.Name)38 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)31 NodeImpl (org.apache.jackrabbit.core.NodeImpl)25 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)23 Path (org.apache.jackrabbit.spi.Path)23 ItemNotFoundException (javax.jcr.ItemNotFoundException)22 ArrayList (java.util.ArrayList)21 InternalValue (org.apache.jackrabbit.core.value.InternalValue)21 PropertyId (org.apache.jackrabbit.core.id.PropertyId)16 HashSet (java.util.HashSet)15 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)14 PropertyState (org.apache.jackrabbit.core.state.PropertyState)14 Node (javax.jcr.Node)13 Session (javax.jcr.Session)13 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)13