Search in sources :

Example 1 with Path

use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.

the class SessionImpl method getImportContentHandler.

/**
     * {@inheritDoc}
     */
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
    // check sanity of this session
    sanityCheck();
    NodeImpl parent;
    try {
        Path p = getQPath(parentAbsPath).getNormalizedPath();
        if (!p.isAbsolute()) {
            throw new RepositoryException("not an absolute path: " + parentAbsPath);
        }
        parent = getItemManager().getNode(p);
    } catch (NameException e) {
        String msg = parentAbsPath + ": invalid path";
        log.debug(msg);
        throw new RepositoryException(msg, e);
    } catch (AccessDeniedException ade) {
        throw new PathNotFoundException(parentAbsPath);
    }
    // verify that parent node is checked-out, not locked and not protected
    // by either node type constraints nor by some retention or hold.
    int options = ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CHECKED_OUT | ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD | ItemValidator.CHECK_RETENTION;
    context.getItemValidator().checkModify(parent, options, Permission.NONE);
    SessionImporter importer = new SessionImporter(parent, this, uuidBehavior, context.getWorkspace().getConfig().getImportConfig());
    return new ImportHandler(importer, this);
}
Also used : Path(org.apache.jackrabbit.spi.Path) AccessDeniedException(javax.jcr.AccessDeniedException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) ImportHandler(org.apache.jackrabbit.core.xml.ImportHandler) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) SessionImporter(org.apache.jackrabbit.core.xml.SessionImporter)

Example 2 with Path

use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.

the class QueryImpl method storeAsNode.

/**
     * @see Query#storeAsNode(String)
     */
public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
    NamePathResolver resolver = mgrProvider.getNamePathResolver();
    try {
        Path p = resolver.getQPath(absPath).getNormalizedPath();
        if (!p.isAbsolute()) {
            throw new RepositoryException(absPath + " is not an absolute path");
        }
        String jcrParent = resolver.getJCRPath(p.getAncestor(1));
        if (!session.itemExists(jcrParent)) {
            throw new PathNotFoundException(jcrParent);
        }
        String relPath = resolver.getJCRPath(p).substring(1);
        String ntName = resolver.getJCRName(NameConstants.NT_QUERY);
        Node queryNode = session.getRootNode().addNode(relPath, ntName);
        // set properties
        queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE), getLanguage());
        queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT), getStatement());
        node = queryNode;
        return node;
    } catch (NameException e) {
        throw new RepositoryException(e.getMessage(), e);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 3 with Path

use of org.apache.jackrabbit.spi.Path 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 4 with Path

use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.

the class DefaultAccessManager method hasPrivileges.

//-----------------------------------------------< AccessControlManager >---
/**
     * @see javax.jcr.security.AccessControlManager#hasPrivileges(String, Privilege[])
     */
public boolean hasPrivileges(String absPath, Privilege[] privileges) throws PathNotFoundException, RepositoryException {
    checkInitialized();
    checkValidNodePath(absPath);
    if (privileges == null || privileges.length == 0) {
        // null or empty privilege array -> return true
        log.debug("No privileges passed -> allowed.");
        return true;
    } else {
        Path p = getPath(absPath);
        return compiledPermissions.hasPrivileges(p, privileges);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path)

Example 5 with Path

use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.

the class UserAccessControlProviderTest method testNoNodeForPrincipal.

/**
     * @see <a href="https://issues.apache.org/jira/browse/JCR-2630">JCR-2630</a>
     */
public void testNoNodeForPrincipal() throws RepositoryException {
    final Principal testPrincipal = getTestPrincipal();
    String path = "/home/users/t/" + testPrincipal.getName();
    while (s.nodeExists(path)) {
        path += "_";
    }
    final String principalPath = path;
    List<Set<Principal>> principalSets = new ArrayList<Set<Principal>>();
    principalSets.add(Collections.<Principal>singleton(testPrincipal));
    principalSets.add(Collections.<Principal>singleton(new ItemBasedPrincipal() {

        public String getPath() {
            return principalPath;
        }

        public String getName() {
            return testPrincipal.getName();
        }
    }));
    Path rootPath = ((SessionImpl) s).getQPath("/");
    for (Set<Principal> principals : principalSets) {
        CompiledPermissions cp = provider.compilePermissions(principals);
        assertFalse(cp.canReadAll());
        assertFalse(cp.grants(rootPath, Permission.READ));
        assertTrue(cp.getPrivilegeSet(rootPath).isEmpty());
        assertSame(CompiledPermissions.NO_PERMISSION, cp);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) SessionImpl(org.apache.jackrabbit.core.SessionImpl) CompiledPermissions(org.apache.jackrabbit.core.security.authorization.CompiledPermissions) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)

Aggregations

Path (org.apache.jackrabbit.spi.Path)223 RepositoryException (javax.jcr.RepositoryException)73 Name (org.apache.jackrabbit.spi.Name)38 ItemNotFoundException (javax.jcr.ItemNotFoundException)26 NodeState (org.apache.jackrabbit.core.state.NodeState)24 PathNotFoundException (javax.jcr.PathNotFoundException)22 NodeId (org.apache.jackrabbit.core.id.NodeId)22 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)20 NamespaceException (javax.jcr.NamespaceException)16 ArrayList (java.util.ArrayList)13 AccessDeniedException (javax.jcr.AccessDeniedException)13 Node (javax.jcr.Node)12 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)11 NodeId (org.apache.jackrabbit.spi.NodeId)11 QValue (org.apache.jackrabbit.spi.QValue)10 MalformedPathException (org.apache.jackrabbit.spi.commons.conversion.MalformedPathException)10 IOException (java.io.IOException)9 ItemExistsException (javax.jcr.ItemExistsException)8