Search in sources :

Example 21 with SessionImpl

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

the class CustomPrivilegeTest method testCustomPrivilege.

public void testCustomPrivilege() throws RepositoryException, FileSystemException {
    boolean isAbstract = false;
    Name name = ((SessionImpl) superuser).getQName("test");
    privilegeRegistry.registerDefinition(name, isAbstract, Collections.<Name>emptySet());
    PrivilegeManagerImpl pm = new PrivilegeManagerImpl(privilegeRegistry, resolver);
    String privName = resolver.getJCRName(name);
    Privilege priv = pm.getPrivilege(privName);
    assertEquals(privName, priv.getName());
    assertEquals(isAbstract, priv.isAbstract());
    assertFalse(priv.isAggregate());
    assertFalse(pm.getBits(priv).isEmpty());
    Privilege jcrWrite = pm.getPrivilege(Privilege.JCR_WRITE);
    assertFalse(pm.getBits(jcrWrite).equals(pm.getBits(priv, jcrWrite)));
}
Also used : SessionImpl(org.apache.jackrabbit.core.SessionImpl) Privilege(javax.jcr.security.Privilege) Name(org.apache.jackrabbit.spi.Name)

Example 22 with SessionImpl

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

the class LockManagerImpl method removeLockProperties.

/**
     *
     * @param node
     * @throws RepositoryException
     */
protected void removeLockProperties(NodeImpl node) throws RepositoryException {
    boolean success = false;
    SessionImpl editingSession = (SessionImpl) node.getSession();
    WorkspaceImpl wsp = (WorkspaceImpl) editingSession.getWorkspace();
    UpdatableItemStateManager stateMgr = wsp.getItemStateManager();
    try {
        acquireLockPropertiesLock();
        // add properties to content
        if (stateMgr.inEditMode()) {
            throw new RepositoryException("Unable to remove lock properties.");
        }
        stateMgr.edit();
        try {
            NodeId nodeId = node.getNodeId();
            NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
            if (nodeState.hasPropertyName(NameConstants.JCR_LOCKOWNER)) {
                PropertyState propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKOWNER));
                nodeState.removePropertyName(NameConstants.JCR_LOCKOWNER);
                stateMgr.destroy(propState);
                stateMgr.store(nodeState);
            }
            if (nodeState.hasPropertyName(NameConstants.JCR_LOCKISDEEP)) {
                PropertyState propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKISDEEP));
                nodeState.removePropertyName(NameConstants.JCR_LOCKISDEEP);
                stateMgr.destroy(propState);
                stateMgr.store(nodeState);
            }
            stateMgr.update();
            success = true;
        } catch (ItemStateException e) {
            throw new RepositoryException("Error while removing lock.", e);
        } finally {
            if (!success) {
                // failed to set lock meta-data content, cleanup
                stateMgr.cancel();
            }
        }
    } finally {
        releaseLockPropertiesLock();
    }
}
Also used : UpdatableItemStateManager(org.apache.jackrabbit.core.state.UpdatableItemStateManager) WorkspaceImpl(org.apache.jackrabbit.core.WorkspaceImpl) NodeState(org.apache.jackrabbit.core.state.NodeState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) PropertyState(org.apache.jackrabbit.core.state.PropertyState) PropertyId(org.apache.jackrabbit.core.id.PropertyId) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 23 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl 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)

Example 24 with SessionImpl

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

the class XALockManager method checkLock.

/**
     * {@inheritDoc}
     */
public void checkLock(Path path, Session session) throws LockException, RepositoryException {
    if (isInXA()) {
        SessionImpl sessionImpl = (SessionImpl) session;
        checkLock(sessionImpl.getItemManager().getNode(path));
    } else {
        lockMgr.checkLock(path, session);
    }
}
Also used : SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 25 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl 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)

Aggregations

SessionImpl (org.apache.jackrabbit.core.SessionImpl)63 RepositoryException (javax.jcr.RepositoryException)16 Node (javax.jcr.Node)12 Value (javax.jcr.Value)11 Name (org.apache.jackrabbit.spi.Name)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Session (javax.jcr.Session)9 NodeImpl (org.apache.jackrabbit.core.NodeImpl)8 NodeId (org.apache.jackrabbit.core.id.NodeId)8 Principal (java.security.Principal)7 DataStoreGarbageCollector (org.apache.jackrabbit.api.management.DataStoreGarbageCollector)7 NodeIterator (javax.jcr.NodeIterator)6 Privilege (javax.jcr.security.Privilege)6 UserManager (org.apache.jackrabbit.api.security.user.UserManager)6 Path (org.apache.jackrabbit.spi.Path)6 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)5 PathMap (org.apache.jackrabbit.spi.commons.name.PathMap)5 InvalidItemStateException (javax.jcr.InvalidItemStateException)4 LockException (javax.jcr.lock.LockException)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4