Search in sources :

Example 26 with NodeUtil

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

the class ValidatorNoProtectionTest method testRepExternalIdMultiple.

@Override
@Test
public void testRepExternalIdMultiple() throws Exception {
    Root systemRoot = getSystemRoot();
    NodeUtil n = new NodeUtil(systemRoot.getTree(testUserPath));
    n.setStrings(ExternalIdentityConstants.REP_EXTERNAL_ID, "id", "id2");
    systemRoot.commit();
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 27 with NodeUtil

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

the class ExternalIdentityValidatorTest method testRemoveRepExternalIdAsSystem.

@Test
public void testRemoveRepExternalIdAsSystem() throws Exception {
    Root systemRoot = getSystemRoot();
    try {
        NodeUtil n = new NodeUtil(systemRoot.getTree(externalUserPath));
        n.removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID);
        systemRoot.commit();
        fail("Removing rep:externalId is not allowed if rep:externalPrincipalNames is present.");
    } catch (CommitFailedException e) {
        // success
        assertEquals(73, e.getCode());
    } finally {
        systemRoot.refresh();
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 28 with NodeUtil

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

the class ExternalIdentityValidatorTest method testRepExternalIdMultiple.

@Test
public void testRepExternalIdMultiple() throws Exception {
    Root systemRoot = getSystemRoot();
    try {
        NodeUtil n = new NodeUtil(systemRoot.getTree(testUserPath));
        n.setStrings(ExternalIdentityConstants.REP_EXTERNAL_ID, "id", "id2");
        systemRoot.commit();
        fail("Creating rep:externalId as multiple STRING property must be detected.");
    } catch (CommitFailedException e) {
        // success
        assertEquals(75, e.getCode());
    } finally {
        systemRoot.refresh();
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 29 with NodeUtil

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

the class AccessControlValidatorTest method testInvalidRestriction.

@Test
public void testInvalidRestriction() throws Exception {
    NodeUtil restriction = createAcl().getChild(aceName).getChild(REP_RESTRICTIONS);
    restriction.setString("invalid", "value");
    try {
        root.commit();
        fail("Creating an unsupported restriction should fail.");
    } catch (CommitFailedException e) {
        // success
        assertTrue(e.isAccessControlViolation());
        assertThat(e.getMessage(), containsString("/testRoot/rep:policy"));
    }
}
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 30 with NodeUtil

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

the class TreeLocationTest method setUp.

@Before
public void setUp() throws Exception {
    Tree tree = root.getTree("/");
    tree.setProperty("a", 1);
    tree.setProperty("b", 2);
    tree.setProperty("c", 3);
    NodeUtil n = new NodeUtil(tree);
    n.addChild("x", JcrConstants.NT_UNSTRUCTURED);
    n.addChild("y", JcrConstants.NT_UNSTRUCTURED);
    n.addChild("z", JcrConstants.NT_UNSTRUCTURED).addChild("1", JcrConstants.NT_UNSTRUCTURED).addChild("2", JcrConstants.NT_UNSTRUCTURED).setString("p", "v");
    root.commit();
    nullLocation = TreeLocation.create(root).getParent();
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) 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