Search in sources :

Example 76 with NodeUtil

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

the class TokenValidatorTest method testCreateReservedKeyProperty.

@Test
public void testCreateReservedKeyProperty() throws Exception {
    NodeUtil node = new NodeUtil(root.getTree("/")).addChild("testNode", JcrConstants.NT_UNSTRUCTURED);
    try {
        node.setString(TOKEN_ATTRIBUTE_KEY, "anyValue");
        root.commit(CommitMarker.asCommitAttributes());
        fail("The reserved token key property must not used with other node types.");
    } catch (CommitFailedException e) {
        assertEquals(60, e.getCode());
    } finally {
        node.getTree().remove();
        root.commit();
    }
}
Also used : CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 77 with NodeUtil

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

the class TokenValidatorTest method testManuallyCreateTokenParent.

@Test
public void testManuallyCreateTokenParent() throws Exception {
    Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath());
    NodeUtil node = new NodeUtil(userTree);
    node.addChild(TOKENS_NODE_NAME, TOKENS_NT_NAME);
    root.commit();
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 78 with NodeUtil

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

the class TokenValidatorTest method testCreateTokenAtInvalidLocationBelowTestNode.

@Test
public void testCreateTokenAtInvalidLocationBelowTestNode() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    Tree tokenTree = getTokenTree(info);
    assertNotNull(tokenProvider.getTokenInfo(info.getToken()));
    NodeUtil node = new NodeUtil(root.getTree("/")).addChild("testNode", JcrConstants.NT_UNSTRUCTURED);
    try {
        createTokenTree(info, node, TOKEN_NT_NAME);
        tokenTree.remove();
        root.commit(CommitMarker.asCommitAttributes());
        fail("Creating a new token not  at '/testNode' must fail.");
    } catch (CommitFailedException e) {
        assertEquals(64, e.getCode());
    } finally {
        node.getTree().remove();
        root.commit(CommitMarker.asCommitAttributes());
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 79 with NodeUtil

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

the class TokenValidatorTest method testCreateTokenAtInvalidLocationInsideUser.

@Test
public void testCreateTokenAtInvalidLocationInsideUser() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    Tree tokenTree = getTokenTree(info);
    assertNotNull(tokenProvider.getTokenInfo(info.getToken()));
    Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath());
    NodeUtil node = new NodeUtil(userTree).addChild("testNode", JcrConstants.NT_UNSTRUCTURED);
    try {
        createTokenTree(info, node, TOKEN_NT_NAME);
        tokenTree.remove();
        root.commit(CommitMarker.asCommitAttributes());
        fail("Creating a new token '" + node.getTree().getPath() + "' must fail.");
    } catch (CommitFailedException e) {
        assertEquals(65, e.getCode());
    } finally {
        node.getTree().remove();
        root.commit(CommitMarker.asCommitAttributes());
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 80 with NodeUtil

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

the class CugContextTest method before.

@Before
@Override
public void before() throws Exception {
    super.before();
    // add more child nodes
    NodeUtil n = new NodeUtil(root.getTree(SUPPORTED_PATH));
    n.addChild("a", NT_OAK_UNSTRUCTURED).addChild("b", NT_OAK_UNSTRUCTURED).addChild("c", NT_OAK_UNSTRUCTURED);
    n.addChild("aa", NT_OAK_UNSTRUCTURED).addChild("bb", NT_OAK_UNSTRUCTURED).addChild("cc", NT_OAK_UNSTRUCTURED);
    // create cugs
    createCug("/content/a", getTestUser().getPrincipal());
    // setup regular acl at /content
    AccessControlManager acMgr = getAccessControlManager(root);
    AccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/content");
    acl.addAccessControlEntry(getTestUser().getPrincipal(), privilegesFromNames(PrivilegeConstants.JCR_READ));
    acMgr.setPolicy("/content", acl);
    root.commit();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Before(org.junit.Before)

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