Search in sources :

Example 41 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 42 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 43 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)

Example 44 with CommitFailedException

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

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

the class NamespaceEditor method propertyAdded.

@Override
public void propertyAdded(PropertyState after) throws CommitFailedException {
    String prefix = after.getName();
    // ignore jcr:primaryType
    if (JCR_PRIMARYTYPE.equals(prefix)) {
        return;
    }
    if (namespaces.hasProperty(prefix)) {
        throw new CommitFailedException(CommitFailedException.NAMESPACE, 1, "Namespace mapping already registered: " + prefix);
    } else if (isValidPrefix(prefix)) {
        if (after.isArray() || !STRING.equals(after.getType())) {
            throw new CommitFailedException(CommitFailedException.NAMESPACE, 2, "Invalid namespace mapping: " + prefix);
        } else if (prefix.toLowerCase(Locale.ENGLISH).startsWith("xml")) {
            throw new CommitFailedException(CommitFailedException.NAMESPACE, 3, "XML prefixes are reserved: " + prefix);
        } else if (containsValue(namespaces, after.getValue(STRING))) {
            throw modificationNotAllowed(prefix);
        }
    } else {
        throw new CommitFailedException(CommitFailedException.NAMESPACE, 4, "Not a valid namespace prefix: " + prefix);
    }
    modified = true;
}
Also used : CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

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