Search in sources :

Example 61 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project sling by apache.

the class MockedResourceResolver method getResource.

@Override
public Resource getResource(String path) {
    Session session;
    try {
        session = getSession();
        session.getNode(path);
    } catch (PathNotFoundException e) {
        return null;
    } catch (RepositoryException e) {
        throw new RuntimeException("RepositoryException: " + e, e);
    }
    return new MockedResource(this, path, "nt:unstructured");
}
Also used : RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session)

Example 62 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project sling by apache.

the class VotingHandlerTest method resetRepo.

private void resetRepo() throws Exception {
    Session l = RepositoryProvider.instance().getRepository().loginAdministrative(null);
    try {
        l.getNode("/var");
        l.removeItem("/var");
    } catch (PathNotFoundException pnfe) {
    // well then we probably dont have to do any cleanup
    }
    l.save();
    l.logout();
}
Also used : PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session)

Example 63 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project sling by apache.

the class U method canWrite.

/** True if user can write to specified path. 
     *  @throws PathNotFoundException if the path doesn't exist */
public static boolean canWrite(Session session, String userId, String path) throws PathNotFoundException, RepositoryException {
    if (!session.itemExists(path)) {
        throw new PathNotFoundException(path);
    }
    final Session serviceSession = getServiceSession(session, userId);
    final String testNodeName = "test_" + UUID.randomUUID().toString();
    try {
        ((Node) serviceSession.getItem(path)).addNode(testNodeName);
        serviceSession.save();
    } catch (AccessDeniedException ade) {
        return false;
    } finally {
        serviceSession.logout();
    }
    return true;
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 64 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project sling by apache.

the class GeneralAclTest method readOnlyThenWriteThenDeny.

@Test
public void readOnlyThenWriteThenDeny() throws Exception {
    final Node tmp = U.adminSession.getRootNode().addNode("tmp_" + U.id);
    U.adminSession.save();
    final String path = tmp.getPath();
    try {
        s.getNode(path);
        fail("Expected read access to be initially denied:" + path);
    } catch (PathNotFoundException ignore) {
    }
    final String allowRead = "set ACL for " + U.username + "\n" + "allow jcr:read on " + path + "\n" + "end";
    U.parseAndExecute(allowRead);
    final Node n = s.getNode(path);
    try {
        n.setProperty("U.id", U.id);
        s.save();
        fail("Expected write access to be initially denied:" + path);
    } catch (AccessDeniedException ignore) {
    }
    s.refresh(false);
    final String allowWrite = "set ACL for " + U.username + "\n" + "allow jcr:write on " + path + "\n" + "end";
    U.parseAndExecute(allowWrite);
    n.setProperty("U.id", U.id);
    s.save();
    final String deny = "set ACL for " + U.username + "\n" + "deny jcr:all on " + path + "\n" + "end";
    U.parseAndExecute(deny);
    try {
        s.getNode(path);
        fail("Expected access to be denied again:" + path);
    } catch (PathNotFoundException ignore) {
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) Test(org.junit.Test)

Example 65 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project sling by apache.

the class MockSession method getNode.

@Override
public Node getNode(final String absPath) throws RepositoryException {
    checkLive();
    Item item = getItem(absPath);
    if (item instanceof Node) {
        return (Node) item;
    } else {
        throw new PathNotFoundException(String.format("No node found at: %s.", absPath));
    }
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Aggregations

PathNotFoundException (javax.jcr.PathNotFoundException)136 Node (javax.jcr.Node)58 RepositoryException (javax.jcr.RepositoryException)46 ItemNotFoundException (javax.jcr.ItemNotFoundException)24 Session (javax.jcr.Session)23 Path (org.apache.jackrabbit.spi.Path)22 AccessDeniedException (javax.jcr.AccessDeniedException)14 Property (javax.jcr.Property)14 Test (org.junit.Test)14 Item (javax.jcr.Item)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 NodeIterator (javax.jcr.NodeIterator)9 Value (javax.jcr.Value)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 Name (org.apache.jackrabbit.spi.Name)8 PropertyIterator (javax.jcr.PropertyIterator)7 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)7 HashSet (java.util.HashSet)6 ItemExistsException (javax.jcr.ItemExistsException)6 ValueFormatException (javax.jcr.ValueFormatException)6