Search in sources :

Example 76 with NodeImpl

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

the class XALockManager method getLock.

/**
 * {@inheritDoc}
 */
public Lock getLock(NodeImpl node) throws LockException, RepositoryException {
    LockInfo info;
    if (isInXA()) {
        info = xaEnv.getLockInfo(node);
    } else {
        info = lockMgr.getLockInfo(node.getNodeId());
    }
    if (info == null) {
        throw new LockException("Node not locked: " + node);
    }
    SessionImpl session = (SessionImpl) node.getSession();
    NodeImpl holder = (NodeImpl) session.getItemManager().getItem(info.getId());
    return new XALockImpl(this, info, holder);
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) LockException(javax.jcr.lock.LockException) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 77 with NodeImpl

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

the class HierarchyConstraint method getBaseNodeId.

/**
 * Returns the id of the base node or <code>null</code> if there is no node
 * at the base path.
 *
 * @param context the evaluation context.
 * @return the id or <code>null</code> if it doesn't exist.
 */
protected final NodeId getBaseNodeId(EvaluationContext context) {
    if (id == null) {
        try {
            NodeImpl node = (NodeImpl) context.getSession().getNode(path);
            id = (NodeId) node.getId();
        } catch (RepositoryException e) {
            return null;
        }
    }
    return id;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) RepositoryException(javax.jcr.RepositoryException)

Example 78 with NodeImpl

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

the class VersionManagerImplBase method checkModify.

/**
 * Checks modify and permissions
 * @param state state to check
 * @param options options to check
 * @param permissions permissions to check
 * @throws RepositoryException if an error occurs
 */
protected void checkModify(NodeStateEx state, int options, int permissions) throws RepositoryException {
    NodeImpl node;
    try {
        node = session.getNodeById(state.getNodeId());
    } catch (RepositoryException e) {
        // ignore
        return;
    }
    context.getItemValidator().checkModify(node, options, permissions);
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) RepositoryException(javax.jcr.RepositoryException)

Example 79 with NodeImpl

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

the class AccessManagerTest method testCanReadNewId.

public void testCanReadNewId() throws Exception {
    Session s = getHelper().getReadOnlySession();
    try {
        NodeImpl n = (NodeImpl) testRootNode.addNode(nodeName1);
        PropertyImpl p = (PropertyImpl) n.setProperty(propertyName1, "somevalue");
        try {
            AccessManager acMgr = getAccessManager(s);
            acMgr.canRead(null, n.getId());
            fail("expected repositoryexception");
        } catch (RepositoryException e) {
        // success
        }
        try {
            AccessManager acMgr = getAccessManager(s);
            acMgr.canRead(null, p.getId());
            fail("expected repositoryexception");
        } catch (RepositoryException e) {
        // success
        }
    } finally {
        s.logout();
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 80 with NodeImpl

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

the class PentahoCompiledPermissionsImpl method canRead.

/**
 * Changed so that access to entryCollector is done outside of a <code>monitor</code> synchronized block.<br/>
 * Should be functionally equivalent to {@link CompiledPermissions#canRead(Path, ItemId)}
 *
 * @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 (readMonitor) {
    synchronized (monitor) {
        if (readCache.containsKey(id)) {
            return readCache.get(id);
        }
    }
    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 PentahoEntryFilterImpl(principalNames, id, session);
    } else {
        filter = new PentahoEntryFilterImpl(principalNames, path, session);
    }
    if (isAcItem) {
        /* item defines ac content -> regular evaluation */
        Result result = buildResult(node, isExistingNode, isAcItem, filter);
        canRead = result.grants(Permission.READ);
    } else {
        for (Object entry : entryCollector.collectEntries(node, filter)) {
            PrivilegeBits privilegeBits = null;
            boolean isAllow = false;
            if (entry instanceof PentahoEntry) {
                privilegeBits = ((PentahoEntry) entry).getPrivilegeBits();
                isAllow = ((PentahoEntry) entry).isAllow();
            } else {
                privilegeBits = ((Entry) entry).getPrivilegeBits();
                isAllow = ((Entry) entry).isAllow();
            }
            if (privilegeBits.includesRead()) {
                canRead = isAllow;
                break;
            }
        }
    }
    synchronized (monitor) {
        readCache.put(id, canRead);
    }
    // } // readMonitor
    return canRead;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) ItemManager(org.apache.jackrabbit.core.ItemManager) NodeId(org.apache.jackrabbit.core.id.NodeId) PrivilegeBits(org.apache.jackrabbit.core.security.authorization.PrivilegeBits) ItemId(org.apache.jackrabbit.core.id.ItemId)

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