Search in sources :

Example 1 with CommitFailedException

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

the class OakInitializer method initialize.

public static void initialize(@Nonnull NodeStore store, @Nonnull RepositoryInitializer initializer, @Nonnull IndexEditorProvider indexEditor) {
    try {
        NodeBuilder builder = store.getRoot().builder();
        initializer.initialize(builder);
        store.merge(builder, createHook(indexEditor), createCommitInfo());
    } catch (CommitFailedException e) {
        throw new RuntimeException(e);
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 2 with CommitFailedException

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

the class UniquePropertyTest method testUniqueness.

@Test
public void testUniqueness() throws Exception {
    Root root = new Oak().with(new OpenSecurityProvider()).with(new PropertyIndexEditorProvider()).with(new InitialContent()).createRoot();
    NodeUtil node = new NodeUtil(root.getTree("/"));
    String uuid = UUID.randomUUID().toString();
    node.setString(JcrConstants.JCR_UUID, uuid);
    root.commit();
    NodeUtil child = new NodeUtil(root.getTree("/")).addChild("another", "rep:User");
    child.setString(JcrConstants.JCR_UUID, uuid);
    try {
        root.commit();
        fail("Duplicate jcr:uuid should be detected.");
    } catch (CommitFailedException e) {
    // expected
    }
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) Root(org.apache.jackrabbit.oak.api.Root) Oak(org.apache.jackrabbit.oak.Oak) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 3 with CommitFailedException

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

the class TokenValidatorTest method testManuallyModifyExpirationDate.

@Test
public void testManuallyModifyExpirationDate() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    NodeUtil tokenTree = new NodeUtil(getTokenTree(info));
    try {
        tokenTree.setDate(TOKEN_ATTRIBUTE_EXPIRY, new Date().getTime());
        root.commit();
        fail("The token expiry must not manually be changed");
    } catch (CommitFailedException e) {
        assertEquals(63, e.getCode());
    }
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Date(java.util.Date) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 4 with CommitFailedException

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

the class TokenValidatorTest method testTokensNodeAtInvalidPathBelowUser.

@Test
public void testTokensNodeAtInvalidPathBelowUser() throws Exception {
    Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath());
    NodeUtil userNode = new NodeUtil(userTree);
    NodeUtil n = null;
    try {
        // Invalid node type of '.tokens' node
        n = userNode.addChild("test", JcrConstants.NT_UNSTRUCTURED);
        n.addChild(TOKENS_NODE_NAME, TOKENS_NT_NAME);
        root.commit();
        fail("The token parent node must be located below the user home node.");
    } catch (CommitFailedException e) {
        assertEquals(68, e.getCode());
    } finally {
        if (n != null) {
            n.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 5 with CommitFailedException

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

the class TokenValidatorTest method testPlaintextTokenKey.

@Test
public void testPlaintextTokenKey() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    NodeUtil tokenTree = new NodeUtil(getTokenTree(info));
    try {
        tokenTree.setString(TOKEN_ATTRIBUTE_KEY, "anotherValue");
        root.commit(CommitMarker.asCommitAttributes());
        fail("The token key must not be plaintext.");
    } catch (CommitFailedException e) {
        assertEquals(66, e.getCode());
    }
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) 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)261 Test (org.junit.Test)173 Tree (org.apache.jackrabbit.oak.api.Tree)76 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)67 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)66 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)59 Root (org.apache.jackrabbit.oak.api.Root)48 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)45 RepositoryException (javax.jcr.RepositoryException)17 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)14 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)13 Nonnull (javax.annotation.Nonnull)12 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)12 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)12 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)11 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)10 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)10 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)10 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)9 ArrayList (java.util.ArrayList)8