Search in sources :

Example 11 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class CugValidatorTest method testMissingMixin.

@Test
public void testMissingMixin() throws Exception {
    NodeUtil cug = node.addChild(REP_CUG_POLICY, NT_REP_CUG_POLICY);
    cug.setStrings(REP_PRINCIPAL_NAMES, EveryonePrincipal.NAME);
    try {
        root.commit();
        fail();
    } catch (CommitFailedException e) {
        assertTrue(e.isAccessControlViolation());
        assertEquals(22, e.getCode());
    } finally {
        root.refresh();
    }
}
Also used : CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 12 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class CugUtilTest method testHasCugNodeState.

@Test
public void testHasCugNodeState() throws Exception {
    assertTrue(CugUtil.hasCug(getNodeState(root.getTree(SUPPORTED_PATH))));
    assertFalse(CugUtil.hasCug((NodeState) null));
    for (String path : new String[] { PathUtils.ROOT_PATH, INVALID_PATH, UNSUPPORTED_PATH, SUPPORTED_PATH + "/subtree", SUPPORTED_PATH2, SUPPORTED_PATH3 }) {
        assertFalse(CugUtil.hasCug(getNodeState(root.getTree(path))));
    }
    new NodeUtil(root.getTree(SUPPORTED_PATH2)).addChild(REP_CUG_POLICY, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    assertTrue(CugUtil.hasCug(getNodeState(root.getTree(SUPPORTED_PATH2))));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 13 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class NestedCugHookTest method testMoveToSupportedPath.

@Test
public void testMoveToSupportedPath() throws Exception {
    createCug(root, SUPPORTED_PATH3, EveryonePrincipal.NAME);
    Tree newTree = new NodeUtil(root.getTree(SUPPORTED_PATH3)).addChild("child", NT_OAK_UNSTRUCTURED).getTree();
    String path = newTree.getPath();
    createCug(path, getTestGroupPrincipal());
    root.commit();
    String destPath = PathUtils.concat(SUPPORTED_PATH, "moved");
    root.move(path, destPath);
    root.commit();
    assertNestedCugs(root, SUPPORTED_PATH3, true);
    assertNestedCugs(root, ROOT_PATH, false, SUPPORTED_PATH3, destPath);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 14 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class NestedCugHookTest method testMoveToUnsupportedPath.

@Test
public void testMoveToUnsupportedPath() throws Exception {
    createCug(root, SUPPORTED_PATH3, EveryonePrincipal.NAME);
    Tree newTree = new NodeUtil(root.getTree(SUPPORTED_PATH3)).addChild("child", NT_OAK_UNSTRUCTURED).getTree();
    String path = newTree.getPath();
    createCug(path, getTestGroupPrincipal());
    root.commit();
    String destPath = PathUtils.concat(UNSUPPORTED_PATH, "moved");
    root.move(path, destPath);
    root.commit();
    assertNestedCugs(root, SUPPORTED_PATH3, true);
    assertNestedCugs(root, ROOT_PATH, false, SUPPORTED_PATH3, destPath);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 15 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class NestedCugHookTest method testMoveToNested.

@Test
public void testMoveToNested() throws Exception {
    createCug(root, SUPPORTED_PATH2, EveryonePrincipal.NAME);
    createCug(root, SUPPORTED_PATH3, EveryonePrincipal.NAME);
    Tree newTree = new NodeUtil(root.getTree(SUPPORTED_PATH3)).addChild("child", NT_OAK_UNSTRUCTURED).getTree();
    String path = newTree.getPath();
    createCug(path, getTestGroupPrincipal());
    root.commit();
    String destPath = PathUtils.concat(SUPPORTED_PATH2, "moved");
    root.move(path, destPath);
    root.commit();
    assertNestedCugs(root, ROOT_PATH, false, SUPPORTED_PATH3, SUPPORTED_PATH2);
    assertNestedCugs(root, SUPPORTED_PATH3, true);
    assertNestedCugs(root, SUPPORTED_PATH2, true, destPath);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Aggregations

NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)183 Test (org.junit.Test)149 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)74 Tree (org.apache.jackrabbit.oak.api.Tree)67 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)59 Root (org.apache.jackrabbit.oak.api.Root)28 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)14 Before (org.junit.Before)14 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)13 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)13 AccessControlManager (javax.jcr.security.AccessControlManager)12 Principal (java.security.Principal)10 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)8 AccessControlException (javax.jcr.security.AccessControlException)7 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)7 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)6 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)6 Privilege (javax.jcr.security.Privilege)5 Restriction (org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction)5 AccessControlList (javax.jcr.security.AccessControlList)4