Search in sources :

Example 26 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 27 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 28 with NodeImpl

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

the class UserImporter method start.

// ---------------------------------------------< ProtectedNodeImporter >---
/**
     * @see ProtectedNodeImporter#start(org.apache.jackrabbit.core.NodeImpl)
     */
public boolean start(NodeImpl protectedParent) throws RepositoryException {
    String repMembers = resolver.getJCRName(UserConstants.NT_REP_MEMBERS);
    if (repMembers.equals(protectedParent.getPrimaryNodeType().getName())) {
        NodeImpl groupNode = protectedParent;
        while (groupNode.getDepth() != 0 && repMembers.equals(groupNode.getPrimaryNodeType().getName())) {
            groupNode = (NodeImpl) groupNode.getParent();
        }
        Authorizable auth = userManager.getAuthorizable(groupNode);
        if (auth == null) {
            log.debug("Cannot handle protected node " + protectedParent + ". It nor one of its parents represent a valid Authorizable.");
            return false;
        } else {
            currentMembership = new Membership(auth.getID());
            return true;
        }
    } else {
        return false;
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Example 29 with NodeImpl

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

the class UserManagerImpl method createAdmin.

/**
     * Create the administrator user. If the node to be created collides
     * with an existing node (ItemExistsException) the existing node gets removed
     * and the admin user node is (re)created.
     * <p>
     * Collision with an existing node may occur under the following circumstances:
     *
     * <ul>
     * <li>The <code>usersPath</code> has been modified in the user manager
     * configuration after a successful repository start that already created
     * the administrator user.</li>
     * <li>The NodeId created by {@link #buildNodeId(String)} by coincidence
     * collides with another NodeId created during the regular node creation
     * process.</li>
     * </ul>
     *
     * @return The admin user.
     * @throws RepositoryException If an error occurs.
     */
private User createAdmin() throws RepositoryException {
    User admin;
    try {
        admin = createUser(adminId, adminId);
        if (!isAutoSave()) {
            session.save();
        }
        log.info("... created admin user with id \'" + adminId + "\' and default pw.");
    } catch (ItemExistsException e) {
        NodeImpl conflictingNode = session.getNodeById(buildNodeId(adminId));
        String conflictPath = conflictingNode.getPath();
        log.error("Detected conflicting node " + conflictPath + " of node type " + conflictingNode.getPrimaryNodeType().getName() + ".");
        // TODO move conflicting node of type rep:User instead of removing and recreating.
        conflictingNode.remove();
        log.info("Removed conflicting node at " + conflictPath);
        admin = createUser(adminId, adminId);
        if (!isAutoSave()) {
            session.save();
        }
        log.info("Resolved conflict and (re)created admin user with id \'" + adminId + "\' and default pw.");
    }
    return admin;
}
Also used : User(org.apache.jackrabbit.api.security.user.User) NodeImpl(org.apache.jackrabbit.core.NodeImpl) ItemExistsException(javax.jcr.ItemExistsException)

Example 30 with NodeImpl

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

the class UserManagerImpl method internalGetAuthorizable.

/**
     * @param id The user or group ID.
     * @return The authorizable with the given <code>id</code> or <code>null</code>.
     * @throws RepositoryException If an error occurs.
     */
private Authorizable internalGetAuthorizable(String id) throws RepositoryException {
    NodeId nodeId = buildNodeId(id);
    NodeImpl n = null;
    try {
        n = session.getNodeById(nodeId);
    } catch (ItemNotFoundException e) {
        boolean compatibleJR16 = config.getConfigValue(PARAM_COMPATIBLE_JR16, false);
        if (compatibleJR16) {
            // backwards-compatibility with JR < 2.0 user/group structure that doesn't
            // allow to determine existence of an authorizable from the id directly.
            // search for it the node belonging to that id
            n = (NodeImpl) authResolver.findNode(P_USERID, id, NT_REP_USER);
            if (n == null) {
                // no user -> look for group.
                // NOTE: JR < 2.0 always returned groupIDs that didn't contain any
                // illegal JCR chars. Since Group.getID() 'unescapes' the node
                // name additional escaping is required.
                Name nodeName = session.getQName(Text.escapeIllegalJcrChars(id));
                n = (NodeImpl) authResolver.findNode(nodeName, NT_REP_GROUP);
            }
        }
    // else: no matching node found -> ignore exception.
    }
    return getAuthorizable(n);
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) NodeId(org.apache.jackrabbit.core.id.NodeId) ItemNotFoundException(javax.jcr.ItemNotFoundException) Name(org.apache.jackrabbit.spi.Name)

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