Search in sources :

Example 71 with NodeUtil

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

the class AbstractAccessControlTest method before.

@Override
@Before
public void before() throws Exception {
    super.before();
    NodeUtil rootNode = new NodeUtil(root.getTree("/"), getNamePathMapper());
    rootNode.addChild("testPath", JcrConstants.NT_UNSTRUCTURED);
    root.commit();
    testPrincipal = getTestUser().getPrincipal();
    testPrivileges = privilegesFromNames(JCR_ADD_CHILD_NODES, JCR_LOCK_MANAGEMENT);
    privilegeManager = getPrivilegeManager(root);
    principalManager = getPrincipalManager(root);
    acl = createEmptyACL();
}
Also used : NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Before(org.junit.Before)

Example 72 with NodeUtil

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

the class TokenValidatorTest method testInvalidTokenParentNode.

@Test
public void testInvalidTokenParentNode() throws Exception {
    Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath());
    NodeUtil node = new NodeUtil(userTree).addChild("testNode", JcrConstants.NT_UNSTRUCTURED);
    try {
        // Invalid node type of '.tokens' node
        node.addChild(TOKENS_NODE_NAME, JcrConstants.NT_UNSTRUCTURED);
        root.commit(CommitMarker.asCommitAttributes());
        fail("Creating a new token '" + node.getTree().getPath() + "' must fail.");
    } catch (CommitFailedException e) {
        assertEquals(68, e.getCode());
    } finally {
        node.getTree().remove();
        root.commit(CommitMarker.asCommitAttributes());
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 73 with NodeUtil

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

the class TokenValidatorTest method testChangeRegularRepUnstructuredPrimaryType.

@Test
public void testChangeRegularRepUnstructuredPrimaryType() throws Exception {
    Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath());
    NodeUtil n = new NodeUtil(userTree).getOrAddChild("test", NodeTypeConstants.NT_REP_UNSTRUCTURED);
    root.commit();
    n.setName(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
    root.commit();
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 74 with NodeUtil

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

the class TokenValidatorTest method testChangeToReservedTokenNodeType.

@Test
public void testChangeToReservedTokenNodeType() throws Exception {
    String parentPath = getTestUser().getPath() + "/" + TokenConstants.TOKENS_NODE_NAME;
    String path = parentPath + "/node";
    try {
        Tree t = root.getTree(getTestUser().getPath()).addChild(TokenConstants.TOKENS_NODE_NAME);
        t.setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
        t.addChild("node").setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
        root.commit();
        NodeUtil node = new NodeUtil(root.getTree(path));
        node.setName(JcrConstants.JCR_PRIMARYTYPE, TokenConstants.TOKEN_NT_NAME);
        node.setString(JcrConstants.JCR_UUID, UUID.randomUUID().toString());
        node.setString(TokenConstants.TOKEN_ATTRIBUTE_KEY, PasswordUtil.buildPasswordHash("key"));
        node.setDate(TokenConstants.TOKEN_ATTRIBUTE_EXPIRY, new Date().getTime());
        root.commit(CommitMarker.asCommitAttributes());
    } catch (CommitFailedException e) {
        assertEquals(62, e.getCode());
    } finally {
        root.refresh();
        root.getTree(parentPath).remove();
        root.commit();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Date(java.util.Date) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 75 with NodeUtil

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

the class TokenValidatorTest method testModifyExpirationDate.

@Test
public void testModifyExpirationDate() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    NodeUtil tokenTree = new NodeUtil(getTokenTree(info));
    tokenTree.setDate(TOKEN_ATTRIBUTE_EXPIRY, new Date().getTime());
    root.commit(CommitMarker.asCommitAttributes());
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) Date(java.util.Date) 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