Search in sources :

Example 81 with NodeId

use of org.apache.jackrabbit.core.id.NodeId 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 82 with NodeId

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

the class EntryCollector method collectEntries.

/**
     * Collect the ACEs effective at the given node applying the specified
     * filter.
     * 
     * @param node
     * @param filter
     * @return
     * @throws RepositoryException
     */
protected List<Entry> collectEntries(NodeImpl node, EntryFilter filter) throws RepositoryException {
    LinkedList<Entry> userAces = new LinkedList<Entry>();
    LinkedList<Entry> groupAces = new LinkedList<Entry>();
    if (node == null) {
        // repository level permissions
        NodeImpl root = (NodeImpl) systemSession.getRootNode();
        if (ACLProvider.isRepoAccessControlled(root)) {
            NodeImpl aclNode = root.getNode(N_REPO_POLICY);
            filterEntries(filter, Entry.readEntries(aclNode, null), userAces, groupAces);
        }
    } else {
        filterEntries(filter, getEntries(node).getACEs(), userAces, groupAces);
        NodeId next = node.getParentId();
        while (next != null) {
            Entries entries = getEntries(next);
            filterEntries(filter, entries.getACEs(), userAces, groupAces);
            next = entries.getNextId();
        }
    }
    List<Entry> entries = new ArrayList<Entry>(userAces.size() + groupAces.size());
    entries.addAll(userAces);
    entries.addAll(groupAces);
    return entries;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) NodeId(org.apache.jackrabbit.core.id.NodeId) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 83 with NodeId

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

the class IndexingConfigurationImplTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    n = testRootNode.addNode(nodeName1, ntUnstructured);
    n.addMixin(mixReferenceable);
    n.addMixin(mixTitle);
    session.save();
    nState = (NodeState) getSearchIndex().getContext().getItemStateManager().getItemState(new NodeId(n.getIdentifier()));
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 84 with NodeId

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

the class SearchIndexConsistencyCheckTest method testIndexContainsUnknownNode.

public void testIndexContainsUnknownNode() throws Exception {
    Session s = getHelper().getSuperuserSession();
    SearchManager searchManager = TestHelper.getSearchManager(s);
    SearchIndex searchIndex = (SearchIndex) searchManager.getQueryHandler();
    NodeId nodeId = new NodeId(0, 0);
    NodeState nodeState = new NodeState(nodeId, null, null, 1, false);
    Iterator<NodeId> remove = Collections.<NodeId>emptyList().iterator();
    Iterator<NodeState> add = Collections.singletonList(nodeState).iterator();
    searchIndex.updateNodes(remove, add);
    ConsistencyCheck consistencyCheck = searchIndex.runConsistencyCheck();
    List<ConsistencyCheckError> errors = consistencyCheck.getErrors();
    assertEquals("Expected 1 index consistency error", 1, errors.size());
    ConsistencyCheckError error = errors.iterator().next();
    assertEquals("Different node was reported to be unknown", error.id, nodeId);
    consistencyCheck.repair(false);
    assertFalse("Index was not repaired properly", searchIndexContainsNode(searchIndex, nodeId));
    assertTrue("Consistency check still reports errors", searchIndex.runConsistencyCheck().getErrors().isEmpty());
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) SearchManager(org.apache.jackrabbit.core.SearchManager) NodeId(org.apache.jackrabbit.core.id.NodeId) Session(javax.jcr.Session)

Example 85 with NodeId

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

the class IDFieldTest method testPerformance.

public void testPerformance() {
    NodeId id = NodeId.randomId();
    long time = System.currentTimeMillis();
    for (int i = 0; i < 1000 * 1000; i++) {
        new IDField(id);
    }
    time = System.currentTimeMillis() - time;
    System.out.println("IDField: " + time + " ms.");
    for (int i = 0; i < 50; i++) {
        createNodes(id.toString(), i % 2 == 0);
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId)

Aggregations

NodeId (org.apache.jackrabbit.core.id.NodeId)203 RepositoryException (javax.jcr.RepositoryException)68 NodeState (org.apache.jackrabbit.core.state.NodeState)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)48 Name (org.apache.jackrabbit.spi.Name)37 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)31 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)23 Path (org.apache.jackrabbit.spi.Path)23 ItemNotFoundException (javax.jcr.ItemNotFoundException)22 NodeImpl (org.apache.jackrabbit.core.NodeImpl)20 InternalValue (org.apache.jackrabbit.core.value.InternalValue)20 ArrayList (java.util.ArrayList)19 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 Session (javax.jcr.Session)13 HashMap (java.util.HashMap)12 ItemExistsException (javax.jcr.ItemExistsException)12