Search in sources :

Example 61 with NodeUtil

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

the class CacheValidatorProviderTest method testCreateCacheBelowProfile.

@Test
public void testCreateCacheBelowProfile() throws Exception {
    try {
        NodeUtil node = new NodeUtil(getAuthorizableTree(getTestUser()));
        NodeUtil child = node.addChild("profile", NodeTypeConstants.NT_OAK_UNSTRUCTURED);
        child.addChild(CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE).setLong(CacheConstants.REP_EXPIRATION, 23);
        root.commit(CacheValidatorProvider.asCommitAttributes());
        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 : 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 62 with NodeUtil

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

the class CacheValidatorProviderTest method testCreateCacheByNodeType.

@Test
public void testCreateCacheByNodeType() throws RepositoryException {
    for (Authorizable a : authorizables) {
        try {
            NodeUtil node = new NodeUtil(getAuthorizableTree(a));
            NodeUtil cache = node.addChild("childNode", CacheConstants.NT_REP_CACHE);
            cache.setLong(CacheConstants.REP_EXPIRATION, 1);
            root.commit();
            fail("Creating node with nt rep:Cache 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)

Example 63 with NodeUtil

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

the class MembershipProviderTest method testNotIsDeclaredMemberMissingMembersProperty.

@Test
public void testNotIsDeclaredMemberMissingMembersProperty() throws Exception {
    Tree grTree = getTree(createGroup());
    Tree memberTree = getTree(createUser());
    NodeUtil memberList = new NodeUtil(grTree).addChild(REP_MEMBERS_LIST, NT_REP_MEMBER_REFERENCES_LIST);
    memberList.addChild("member1", NT_REP_MEMBER_REFERENCES).setStrings(REP_MEMBERS, getContentID("another"));
    assertFalse(mp.isDeclaredMember(grTree, memberTree));
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 64 with NodeUtil

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

the class MembershipProviderTest method testIsDeclaredMemberMissingMembersProperty.

@Test
public void testIsDeclaredMemberMissingMembersProperty() throws Exception {
    Tree grTree = getTree(createGroup());
    Tree memberTree = getTree(createUser());
    NodeUtil memberList = new NodeUtil(grTree).addChild(REP_MEMBERS_LIST, NT_REP_MEMBER_REFERENCES_LIST);
    memberList.addChild("member1", NT_REP_MEMBER_REFERENCES).setStrings(REP_MEMBERS, getContentID(memberTree));
    assertTrue(mp.isDeclaredMember(grTree, memberTree));
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 65 with NodeUtil

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

the class SystemUserImplTest method testCreateSystemUserWithOtherPath.

@Test
public void testCreateSystemUserWithOtherPath() throws Exception {
    String path = null;
    try {
        Tree t = root.getTree(UserConstants.DEFAULT_USER_PATH);
        NodeUtil systemUserTree = new NodeUtil(t).addChild("systemUser", UserConstants.NT_REP_SYSTEM_USER);
        systemUserTree.setString(UserConstants.REP_PRINCIPAL_NAME, "systemUser");
        systemUserTree.setString(UserConstants.REP_AUTHORIZABLE_ID, "systemUser");
        path = systemUserTree.getTree().getPath();
        root.commit();
        fail();
    } catch (CommitFailedException e) {
        // success
        assertTrue(e.isConstraintViolation());
    } finally {
        root.refresh();
        if (path != null) {
            Tree t = root.getTree(path);
            if (t.exists()) {
                t.remove();
                root.commit();
            }
        }
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) 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