Search in sources :

Example 51 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class AccessControlValidatorTest method testAddPolicyWithAcContent.

@Test
public void testAddPolicyWithAcContent() throws Exception {
    NodeUtil acl = createAcl();
    NodeUtil ace = acl.getChild(aceName);
    NodeUtil[] acContent = new NodeUtil[] { acl, ace, ace.getChild(REP_RESTRICTIONS) };
    for (NodeUtil node : acContent) {
        NodeUtil policy = node.addChild(REP_POLICY, NT_REP_ACL);
        try {
            root.commit();
            fail("Adding an ACL below access control content should fail");
        } catch (CommitFailedException e) {
            // success
            assertTrue(e.isConstraintViolation());
            assertThat(e.getMessage(), containsString("/testRoot/rep:policy"));
        } finally {
            policy.getTree().remove();
        }
    }
}
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 52 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class AccessControlValidatorTest method testAddAceWithAcContent.

@Test
public void testAddAceWithAcContent() throws Exception {
    NodeUtil acl = createAcl();
    NodeUtil ace = acl.getChild(aceName);
    NodeUtil[] acContent = new NodeUtil[] { ace, ace.getChild(REP_RESTRICTIONS) };
    for (NodeUtil node : acContent) {
        NodeUtil entry = node.addChild("invalidACE", NT_REP_DENY_ACE);
        try {
            root.commit();
            fail("Adding an ACE below an ACE or restriction should fail");
        } catch (CommitFailedException e) {
            // success
            assertTrue(e.isConstraintViolation());
            assertThat(e.getMessage(), containsString("/testRoot/rep:policy/validAce"));
        } finally {
            entry.getTree().remove();
        }
    }
}
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 53 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class AccessControlValidatorTest method testAddRestrictionWithAcContent.

@Test
public void testAddRestrictionWithAcContent() throws Exception {
    NodeUtil acl = createAcl();
    NodeUtil ace = acl.getChild(aceName);
    NodeUtil[] acContent = new NodeUtil[] { acl, ace.getChild(REP_RESTRICTIONS) };
    for (NodeUtil node : acContent) {
        NodeUtil entry = node.addChild("invalidRestriction", NT_REP_RESTRICTIONS);
        try {
            root.commit();
            fail("Adding an ACE below an ACE or restriction should fail");
        } catch (CommitFailedException e) {
            // success
            assertTrue(e.isConstraintViolation());
            assertThat(e.getMessage(), containsString("/testRoot/rep:policy"));
        } finally {
            entry.getTree().remove();
        }
    }
}
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 54 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class RepExternalIdTest method testUniqueConstraintNonUserNode.

@Test
public void testUniqueConstraintNonUserNode() throws Exception {
    try {
        SyncResult res = syncCtx.sync(idp.getUser(USER_ID));
        Tree nonUserTree = r.getTree("/");
        nonUserTree.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, res.getIdentity().getExternalIdRef().getString());
        r.commit();
        fail("Duplicate value for rep:externalId must be detected in the default setup.");
    } catch (CommitFailedException e) {
        // success: verify nature of the exception
        assertTrue(e.isConstraintViolation());
        assertEquals(30, e.getCode());
    } finally {
        r.refresh();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)

Example 55 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class RepExternalIdTest method testUniqueConstraint.

@Test
public void testUniqueConstraint() throws Exception {
    SyncResult res = syncCtx.sync(idp.getUser(USER_ID));
    try {
        Tree t = r.getTree(getTestUser().getPath());
        t.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, res.getIdentity().getExternalIdRef().getString());
        r.commit();
        fail("Duplicate value for rep:externalId must be detected in the default setup.");
    } catch (CommitFailedException e) {
        // success: verify nature of the exception
        assertTrue(e.isConstraintViolation());
        assertEquals(30, e.getCode());
    } finally {
        r.refresh();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)

Aggregations

CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)246 Test (org.junit.Test)166 Tree (org.apache.jackrabbit.oak.api.Tree)75 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)66 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)60 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)59 Root (org.apache.jackrabbit.oak.api.Root)48 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)42 RepositoryException (javax.jcr.RepositoryException)17 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)13 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)13 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)12 Nonnull (javax.annotation.Nonnull)10 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)10 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)10 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)10 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)9 ArrayList (java.util.ArrayList)8 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)8 UserManager (org.apache.jackrabbit.api.security.user.UserManager)7