Search in sources :

Example 81 with CommitFailedException

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

the class UserPrincipalProviderWithCacheTest method testChangeCache.

@Test
public void testChangeCache() throws Exception {
    PrincipalProvider pp = createPrincipalProvider(systemRoot);
    pp.getPrincipals(userId);
    root.refresh();
    List<PropertyState> props = new ArrayList();
    props.add(PropertyStates.createProperty(CacheConstants.REP_EXPIRATION, 25));
    props.add(PropertyStates.createProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, EveryonePrincipal.NAME));
    props.add(PropertyStates.createProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED));
    props.add(PropertyStates.createProperty("residualProp", "anyvalue"));
    // changing cache with (normally) sufficiently privileged session must not succeed
    for (PropertyState ps : props) {
        try {
            Tree cache = getCacheTree(root);
            cache.setProperty(ps);
            root.commit();
            fail("Attempt to modify the cache tree must fail.");
        } catch (CommitFailedException e) {
        // success
        } finally {
            root.refresh();
        }
    }
    // changing cache with system session must not succeed either
    for (PropertyState ps : props) {
        try {
            Tree cache = getCacheTree(systemRoot);
            cache.setProperty(ps);
            systemRoot.commit();
            fail("Attempt to modify the cache tree must fail.");
        } catch (CommitFailedException e) {
        // success
        } finally {
            systemRoot.refresh();
        }
    }
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) ArrayList(java.util.ArrayList) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractPrincipalProviderTest(org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest) Test(org.junit.Test)

Example 82 with CommitFailedException

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

the class UserManagerImplTest method testEnforceAuthorizableFolderHierarchy.

@Test
public void testEnforceAuthorizableFolderHierarchy() throws RepositoryException, CommitFailedException {
    User user = userMgr.createUser(testUserId, null);
    root.commit();
    NodeUtil userNode = new NodeUtil(root.getTree(user.getPath()));
    NodeUtil folder = userNode.addChild("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
    String path = folder.getTree().getPath();
    // authNode - authFolder -> create User
    try {
        Principal p = new PrincipalImpl("test2");
        userMgr.createUser(p.getName(), p.getName(), p, path);
        root.commit();
        fail("Users may not be nested.");
    } catch (CommitFailedException e) {
    // success
    } finally {
        Authorizable a = userMgr.getAuthorizable("test2");
        if (a != null) {
            a.remove();
            root.commit();
        }
    }
    NodeUtil someContent = userNode.addChild("mystuff", JcrConstants.NT_UNSTRUCTURED);
    path = someContent.getTree().getPath();
    try {
        // authNode - anyNode -> create User
        try {
            Principal p = new PrincipalImpl("test3");
            userMgr.createUser(p.getName(), p.getName(), p, path);
            root.commit();
            fail("Users may not be nested.");
        } catch (CommitFailedException e) {
        // success
        } finally {
            Authorizable a = userMgr.getAuthorizable("test3");
            if (a != null) {
                a.remove();
                root.commit();
            }
        }
        // authNode - anyNode - authFolder -> create User
        folder = someContent.addChild("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
        // this time save node structure
        root.commit();
        try {
            Principal p = new PrincipalImpl("test4");
            userMgr.createUser(p.getName(), p.getName(), p, folder.getTree().getPath());
            root.commit();
            fail("Users may not be nested.");
        } catch (CommitFailedException e) {
        // success
        } finally {
            root.refresh();
            Authorizable a = userMgr.getAuthorizable("test4");
            if (a != null) {
                a.remove();
                root.commit();
            }
        }
    } finally {
        root.refresh();
        Tree t = root.getTree(path);
        if (t.exists()) {
            t.remove();
            root.commit();
        }
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 83 with CommitFailedException

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

the class SameNameSiblingTest method createNodeStore.

@Override
protected NodeStore createNodeStore(NodeStoreFixture fixture) throws RepositoryException {
    try {
        NodeStore nodeStore = super.createNodeStore(fixture);
        NodeBuilder root = nodeStore.getRoot().builder();
        NodeBuilder sns = root.setChildNode("sns");
        sns.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME);
        for (String sibling : asList(SIBLING, SIBLINGS)) {
            if (!sibling.endsWith("[1]")) {
                sns.setChildNode(sibling).setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME);
            }
        }
        nodeStore.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
        return nodeStore;
    } catch (CommitFailedException e) {
        throw new RepositoryException(e);
    }
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) RepositoryException(javax.jcr.RepositoryException) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 84 with CommitFailedException

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

the class LuceneIndexEditor method childNodeDeleted.

@Override
public Editor childNodeDeleted(String name, NodeState before) throws CommitFailedException {
    PathFilter.Result filterResult = getPathFilterResult(name);
    if (filterResult == PathFilter.Result.EXCLUDE) {
        return null;
    }
    if (!isDeleted) {
        // tree deletion is handled on the parent node
        String path = concat(getPath(), name);
        try {
            LuceneIndexWriter writer = context.getWriter();
            // Remove all index entries in the removed subtree
            writer.deleteDocuments(path);
            this.context.indexUpdate();
        } catch (IOException e) {
            CommitFailedException ce = new CommitFailedException("Lucene", 5, "Failed to remove the index entries of" + " the removed subtree " + path + "for index " + context.getIndexingContext().getIndexPath(), e);
            context.getIndexingContext().indexUpdateFailed(ce);
            throw ce;
        }
    }
    MatcherState ms = getMatcherState(name, before);
    if (!ms.isEmpty()) {
        return new LuceneIndexEditor(this, name, ms, filterResult, true);
    }
    // no need to recurse down the removed subtree
    return null;
}
Also used : PathFilter(org.apache.jackrabbit.oak.plugins.index.PathFilter) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) IOException(java.io.IOException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 85 with CommitFailedException

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

the class LuceneIndexEditor method addOrUpdate.

private boolean addOrUpdate(String path, NodeState state, boolean isUpdate) throws CommitFailedException {
    try {
        Document d = makeDocument(path, state, isUpdate);
        if (d != null) {
            if (log.isTraceEnabled()) {
                log.trace("[{}] Indexed document for {} is {}", getIndexName(), path, d);
            }
            context.indexUpdate();
            context.getWriter().updateDocument(path, d);
            return true;
        }
    } catch (IOException e) {
        CommitFailedException ce = new CommitFailedException("Lucene", 3, "Failed to index the node " + path, e);
        context.getIndexingContext().indexUpdateFailed(ce);
        throw ce;
    } catch (IllegalArgumentException ie) {
        log.warn("Failed to index the node [{}]", path, ie);
    }
    return false;
}
Also used : IOException(java.io.IOException) Document(org.apache.lucene.document.Document) 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