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();
}
}
}
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();
}
}
}
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);
}
}
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;
}
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;
}
Aggregations