Search in sources :

Example 56 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 57 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)

Example 58 with NodeUtil

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

the class CacheValidatorProviderTest method testChangePrimaryType.

@Test
public void testChangePrimaryType() throws RepositoryException {
    for (Authorizable a : authorizables) {
        try {
            NodeUtil node = new NodeUtil(getAuthorizableTree(a));
            NodeUtil cache = node.addChild("childNode", JcrConstants.NT_UNSTRUCTURED);
            root.commit();
            cache.setName(JcrConstants.JCR_PRIMARYTYPE, CacheConstants.NT_REP_CACHE);
            cache.setLong(CacheConstants.REP_EXPIRATION, 1);
            root.commit();
            fail("Changing primary type of residual node below an user/group to rep:Cache must fail.");
        } catch (CommitFailedException e) {
            assertTrue(e.isConstraintViolation());
            assertEquals(34, e.getCode());
        } finally {
            root.refresh();
        }
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 59 with NodeUtil

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

the class CacheValidatorProviderTest method testNestedCache.

@Test
public void testNestedCache() throws Exception {
    NodeUtil cache = new NodeUtil(getCache(getTestUser()));
    try {
        NodeUtil c = cache.getOrAddChild(CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE);
        c.setLong(CacheConstants.REP_EXPIRATION, 223);
        root.commit(CacheValidatorProvider.asCommitAttributes());
        fail("Creating nested cache must fail.");
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(34, e.getCode());
    } finally {
        root.refresh();
    }
}
Also used : CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 60 with NodeUtil

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

the class CacheValidatorProviderTest method testCreateCacheByName.

@Test
public void testCreateCacheByName() throws RepositoryException {
    for (Authorizable a : authorizables) {
        try {
            NodeUtil node = new NodeUtil(getAuthorizableTree(a));
            node.addChild(CacheConstants.REP_CACHE, JcrConstants.NT_UNSTRUCTURED);
            root.commit();
            fail("Creating rep:cache node below a user or group must fail.");
        } catch (CommitFailedException e) {
            assertTrue(e.isConstraintViolation());
            assertEquals(34, e.getCode());
        } finally {
            root.refresh();
        }
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) 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