Search in sources :

Example 51 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit-oak by apache.

the class LockOperation method performVoid.

@Override
public void performVoid() throws RepositoryException {
    session.refresh(true);
    NodeDelegate node = session.getNode(path);
    if (node != null) {
        performVoid(node);
    } else {
        throw new PathNotFoundException("Node " + path + " not found");
    }
}
Also used : PathNotFoundException(javax.jcr.PathNotFoundException) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)

Example 52 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit-oak by apache.

the class LockOperation method perform.

@Nonnull
@Override
public T perform() throws RepositoryException {
    session.refresh(true);
    NodeDelegate node = session.getNode(path);
    if (node != null) {
        return perform(node);
    } else {
        throw new PathNotFoundException("Node " + path + " not found");
    }
}
Also used : PathNotFoundException(javax.jcr.PathNotFoundException) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) Nonnull(javax.annotation.Nonnull)

Example 53 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit-oak by apache.

the class RandomizedReadTest method check.

public void check() throws Exception {
    boolean mustThrow;
    try {
        for (String path : tree.values()) {
            mustThrow = false;
            Session s1 = readSessions.get(0);
            try {
                Node n = s1.getNode(path);
                if (!path.equals(n.getPath())) {
                    Assert.fail("did not resolved the same node");
                }
            } catch (PathNotFoundException pnf) {
                mustThrow = true;
            }
            for (int i = 1; i < readSessions.size(); i++) {
                try {
                    Node n = readSessions.get(i).getNode(path);
                    if (mustThrow) {
                        Assert.fail("did not throw for path " + path);
                    }
                    if (!path.equals(n.getPath())) {
                        Assert.fail("did not resolved the same node");
                    }
                } catch (PathNotFoundException pnf) {
                    if (!mustThrow) {
                        Assert.fail("did throw for path " + path);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new Exception(e);
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 54 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit-oak by apache.

the class AccessControlManagementTest method testReadAccessControlWithoutPrivilege.

@Test
public void testReadAccessControlWithoutPrivilege() throws Exception {
    // re-grant READ in order to have an ACL-node
    Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
    JackrabbitAccessControlList tmpl = allow(path, privileges);
    String policyPath = tmpl.getPath() + "/rep:policy";
    // make sure the 'rep:policy' node has been created.
    assertTrue(superuser.itemExists(policyPath));
    /*
         Testuser must still have READ-only access only and must not be
         allowed to view the acl-node nor any item in the subtree that
         has been created.
        */
    assertFalse(testAcMgr.hasPrivileges(path, privilegesFromName(Privilege.JCR_READ_ACCESS_CONTROL)));
    assertFalse(testSession.itemExists(policyPath));
    assertFalse(testSession.nodeExists(policyPath));
    try {
        testSession.getNode(policyPath);
        fail("Accessing the rep:policy node must throw PathNotFoundException.");
    } catch (PathNotFoundException e) {
    // ok.
    }
    try {
        testAcMgr.getPolicies(tmpl.getPath());
        fail("test user must not have READ_AC privilege.");
    } catch (AccessDeniedException e) {
    // success
    }
    try {
        testAcMgr.getEffectivePolicies(tmpl.getPath());
        fail("test user must not have READ_AC privilege.");
    } catch (AccessDeniedException e) {
    // success
    }
    for (NodeIterator aceNodes = superuser.getNode(policyPath).getNodes(); aceNodes.hasNext(); ) {
        Node aceNode = aceNodes.nextNode();
        String aceNodePath = aceNode.getPath();
        assertFalse(testSession.nodeExists(aceNodePath));
        for (PropertyIterator it = aceNode.getProperties(); it.hasNext(); ) {
            assertFalse(testSession.propertyExists(it.nextProperty().getPath()));
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) PathNotFoundException(javax.jcr.PathNotFoundException) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Test(org.junit.Test)

Example 55 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project jackrabbit-oak by apache.

the class PropertyImpl method getNode.

@Override
@Nonnull
public Node getNode() throws RepositoryException {
    return perform(new PropertyOperation<Node>(dlg, "getNode") {

        @Nonnull
        @Override
        public Node perform() throws RepositoryException {
            // TODO: avoid nested calls
            Value value = getValue();
            switch(value.getType()) {
                case PropertyType.REFERENCE:
                case PropertyType.WEAKREFERENCE:
                    return getSession().getNodeByIdentifier(value.getString());
                case PropertyType.PATH:
                case PropertyType.NAME:
                    String path = value.getString();
                    if (path.startsWith("[") && path.endsWith("]")) {
                        // identifier path
                        String identifier = path.substring(1, path.length() - 1);
                        return getSession().getNodeByIdentifier(identifier);
                    } else {
                        try {
                            return (path.charAt(0) == '/') ? getSession().getNode(path) : getParent().getNode(path);
                        } catch (PathNotFoundException e) {
                            throw new ItemNotFoundException(path);
                        }
                    }
                case PropertyType.STRING:
                    try {
                        Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, getValueFactory());
                        return getSession().getNodeByIdentifier(refValue.getString());
                    } catch (ItemNotFoundException e) {
                        throw e;
                    } catch (RepositoryException e) {
                        // try if STRING value can be interpreted as PATH value
                        Value pathValue = ValueHelper.convert(value, PropertyType.PATH, getValueFactory());
                        path = pathValue.getString();
                        try {
                            return (path.charAt(0) == '/') ? getSession().getNode(path) : getParent().getNode(path);
                        } catch (PathNotFoundException e1) {
                            throw new ItemNotFoundException(pathValue.getString());
                        }
                    }
                default:
                    throw new ValueFormatException("Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE");
            }
        }
    });
}
Also used : Nonnull(javax.annotation.Nonnull) Node(javax.jcr.Node) Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException) Nonnull(javax.annotation.Nonnull)

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