Search in sources :

Example 66 with NodeImpl

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

the class EntryTest method testIsLocal.

public void testIsLocal() throws NotExecutableException, RepositoryException {
    acl = getPolicy(acMgr, testPath, testUser.getPrincipal());
    modifyPrivileges(testPath, Privilege.JCR_READ, true);
    NodeImpl aclNode = (NodeImpl) superuser.getNode(acl.getPath() + "/rep:policy");
    List<Entry> entries = Entry.readEntries(aclNode, testRootNode.getPath());
    assertTrue(!entries.isEmpty());
    assertEquals(1, entries.size());
    Entry entry = entries.iterator().next();
    // false since acl has been created from path only -> no id
    assertTrue(entry.isLocal(((NodeImpl) testRootNode).getNodeId()));
    // false since internal id is null -> will never match.
    assertFalse(entry.isLocal(NodeId.randomId()));
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl)

Example 67 with NodeImpl

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

the class LockManagerImpl method addLockToken.

/**
 * {@inheritDoc}
 */
public void addLockToken(SessionImpl session, String lt) throws LockException, RepositoryException {
    try {
        acquire();
        NodeId id = LockInfo.parseLockToken(lt);
        NodeImpl node = (NodeImpl) sysSession.getItemManager().getItem(id);
        Path path = node.getPrimaryPath();
        PathMap.Element<LockInfo> element = lockMap.map(path, true);
        if (element != null) {
            LockInfo info = element.get();
            if (info != null && !info.isLockHolder(session)) {
                if (info.getLockHolder() == null) {
                    info.setLockHolder(session);
                    if (info instanceof InternalLockInfo) {
                        session.addListener((InternalLockInfo) info);
                    }
                } else {
                    String msg = "Cannot add lock token: lock already held by other session.";
                    log.warn(msg);
                    info.throwLockException(msg, session);
                }
            }
        }
        // inform SessionLockManager
        getSessionLockManager(session).lockTokenAdded(lt);
    } catch (IllegalArgumentException e) {
        String msg = "Bad lock token: " + e.getMessage();
        log.warn(msg);
        throw new LockException(msg);
    } finally {
        release();
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeImpl(org.apache.jackrabbit.core.NodeImpl) LockException(javax.jcr.lock.LockException) NodeId(org.apache.jackrabbit.core.id.NodeId) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap)

Example 68 with NodeImpl

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

the class LockManagerImpl method removeLockToken.

/**
 * {@inheritDoc}
 */
public void removeLockToken(SessionImpl session, String lt) throws LockException, RepositoryException {
    try {
        acquire();
        NodeId id = LockInfo.parseLockToken(lt);
        NodeImpl node = (NodeImpl) sysSession.getItemManager().getItem(id);
        PathMap.Element<LockInfo> element = lockMap.map(node.getPrimaryPath(), true);
        if (element != null) {
            LockInfo info = element.get();
            if (info != null) {
                if (info.isLockHolder(session)) {
                    info.setLockHolder(null);
                } else if (info.getLockHolder() != null) {
                    String msg = "Cannot remove lock token: lock held by other session.";
                    log.warn(msg);
                    info.throwLockException(msg, session);
                }
            }
        }
        // inform SessionLockManager
        getSessionLockManager(session).lockTokenRemoved(lt);
    } catch (IllegalArgumentException e) {
        String msg = "Bad lock token: " + e.getMessage();
        log.warn(msg);
        throw new LockException(msg);
    } finally {
        release();
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) LockException(javax.jcr.lock.LockException) NodeId(org.apache.jackrabbit.core.id.NodeId) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap)

Example 69 with NodeImpl

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

the class LockManagerImpl method getLocks.

/**
 * {@inheritDoc}
 */
public Lock[] getLocks(SessionImpl session) throws RepositoryException {
    acquire();
    LockInfo[] infos = getLockInfos(session);
    try {
        Lock[] locks = new Lock[infos.length];
        for (int i = 0; i < infos.length; i++) {
            NodeImpl holder = (NodeImpl) session.getItemManager().getItem(infos[i].getId());
            locks[i] = new LockImpl(infos[i], holder);
        }
        return locks;
    } finally {
        release();
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Lock(javax.jcr.lock.Lock) XAReentrantLock(org.apache.jackrabbit.core.util.XAReentrantLock)

Example 70 with NodeImpl

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

the class LockManagerImpl method getLock.

/**
 * {@inheritDoc}
 */
public Lock getLock(NodeImpl node) throws LockException, RepositoryException {
    acquire();
    try {
        SessionImpl session = (SessionImpl) node.getSession();
        Path path = getPath(session, node.getId());
        PathMap.Element<LockInfo> element = lockMap.map(path, false);
        LockInfo info = element.get();
        if (info != null && (element.hasPath(path) || info.isDeep())) {
            NodeImpl lockHolder = (NodeImpl) session.getItemManager().getItem(info.getId());
            return new LockImpl(info, lockHolder);
        } else {
            throw new LockException("Node not locked: " + node);
        }
    } catch (ItemNotFoundException e) {
        throw new LockException("Node not locked: " + node);
    } finally {
        release();
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeImpl(org.apache.jackrabbit.core.NodeImpl) LockException(javax.jcr.lock.LockException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap) ItemNotFoundException(javax.jcr.ItemNotFoundException)

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