Search in sources :

Example 21 with CommitFailedException

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

the class ExternalIdentityValidatorTest method testRemoveRepExternalIdWithoutPrincipalNames.

@Test
public void testRemoveRepExternalIdWithoutPrincipalNames() throws Exception {
    Root systemRoot = getSystemRoot();
    systemRoot.getTree(testUserPath).setProperty(ExternalIdentityConstants.REP_EXTERNAL_ID, "id");
    systemRoot.commit();
    root.refresh();
    try {
        root.getTree(testUserPath).removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID);
        root.commit();
        fail("Removal of rep:externalId must be detected in the default setup.");
    } catch (CommitFailedException e) {
        // success: verify nature of the exception
        assertTrue(e.isConstraintViolation());
        assertEquals(74, e.getCode());
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 22 with CommitFailedException

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

the class ExternalIdentityValidatorTest method testExternalPrincipalNamesSingle.

@Test
public void testExternalPrincipalNamesSingle() throws Exception {
    Root systemRoot = getSystemRoot();
    try {
        NodeUtil n = new NodeUtil(systemRoot.getTree(testUserPath));
        n.setString(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES, "id");
        systemRoot.commit();
        fail("Creating rep:externalPrincipalNames as single STRING property must be detected.");
    } catch (CommitFailedException e) {
        // success
        assertEquals(71, 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 23 with CommitFailedException

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

the class ExternalIdentityValidatorTest method testRepExternalIdType.

@Test
public void testRepExternalIdType() throws Exception {
    Root systemRoot = getSystemRoot();
    Tree userTree = systemRoot.getTree(testUserPath);
    java.util.Map<Type, Object> valMap = ImmutableMap.<Type, Object>of(Type.BOOLEAN, Boolean.TRUE, Type.LONG, new Long(1234), Type.NAME, "id");
    for (Type t : valMap.keySet()) {
        Object val = valMap.get(t);
        try {
            userTree.setProperty(ExternalIdentityConstants.REP_EXTERNAL_ID, val, t);
            systemRoot.commit();
            fail("Creating rep:externalId with type " + t + " must be detected.");
        } catch (CommitFailedException e) {
            // success
            assertEquals(75, e.getCode());
        } finally {
            systemRoot.refresh();
        }
    }
}
Also used : Type(org.apache.jackrabbit.oak.api.Type) Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 24 with CommitFailedException

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

the class ExternalIdentityValidatorTest method testModifyExternalPrincipalNames.

@Test
public void testModifyExternalPrincipalNames() throws Exception {
    Tree userTree = root.getTree(externalUserPath);
    try {
        userTree.setProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES, Lists.newArrayList("principalNames"), Type.STRINGS);
        root.commit();
        fail("Changing rep:externalPrincipalNames must be detected.");
    } catch (CommitFailedException e) {
        // success
        assertEquals(70, e.getCode());
    } finally {
        root.refresh();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 25 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException 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)

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