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");
}
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();
}
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;
}
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) {
}
}
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));
}
}
Aggregations