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();
}
}
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;
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class UserPrincipalProvider method cacheGroups.
private void cacheGroups(@Nonnull Tree authorizableNode, @Nonnull Set<Group> groupPrincipals) {
try {
root.refresh();
Tree cache = authorizableNode.getChild(CacheConstants.REP_CACHE);
if (!cache.exists()) {
if (groupPrincipals.size() <= MEMBERSHIP_THRESHOLD) {
log.debug("Omit cache creation for user without group membership at " + authorizableNode.getPath());
return;
} else {
log.debug("Create new group membership cache at " + authorizableNode.getPath());
cache = TreeUtil.addChild(authorizableNode, CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE);
}
}
cache.setProperty(CacheConstants.REP_EXPIRATION, LongUtils.calculateExpirationTime(expiration));
String value = (groupPrincipals.isEmpty()) ? "" : Joiner.on(",").join(Iterables.transform(groupPrincipals, new Function<Group, String>() {
@Override
public String apply(Group input) {
return Text.escape(input.getName());
}
}));
cache.setProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, value);
root.commit(CacheValidatorProvider.asCommitAttributes());
log.debug("Cached group membership at " + authorizableNode.getPath());
} catch (AccessDeniedException e) {
log.debug("Failed to cache group membership", e.getMessage());
} catch (CommitFailedException e) {
log.debug("Failed to cache group membership", e.getMessage(), e);
} finally {
root.refresh();
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class NodeStoreDiffTest method testDiff.
/**
* This testcase demonstrates that diff logic in merge part traverses node path
* which are not affected by the commit
* @throws Exception
*/
@Test
public void testDiff() throws Exception {
createNodes("/oak:index/prop-a", "/oak:index/prop-b", "/etc/workflow");
//1. Make some other changes so as to bump root rev=3
createNodes("/fake/a");
createNodes("/fake/b");
//2 - Start change
NodeBuilder b2 = ns.getRoot().builder();
createNodes(b2, "/etc/workflow/instance1");
tds.reset();
//3. Merge which does a rebase
ns.merge(b2, new CommitHook() {
@Nonnull
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
NodeBuilder rb = after.builder();
createNodes(rb, "/oak:index/prop-a/a1");
//2.1 Commit some change under prop-
//This cause diff in lastRev of base node state in ModifiedNodeState for
//oak:index due to which when the base state is compared in ModifiedNodeState
//then it fetches the new DocumentNodeState whose lastRev is greater than this.base.lastRev
//but less then lastRev of the of readRevision. Where readRevision is the rev of root node when
//rebase was performed
// remember paths accessed so far
List<String> paths = Lists.newArrayList(tds.paths);
//This is not to be done in actual cases as CommitHooks are invoked in critical sections
//and creating nodes from within CommitHooks would cause deadlock. This is done here to ensure
//that changes are done when rebase has been performed and merge is about to happen
createNodes("/oak:index/prop-b/b1");
// reset accessed paths
tds.reset();
tds.paths.addAll(paths);
return rb.getNodeState();
}
}, CommitInfo.EMPTY);
//Assert that diff logic does not traverse to /oak:index/prop-b/b1 as
//its not part of commit
assertFalse(tds.paths.contains("/oak:index/prop-b/b1"));
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class AccessControlValidatorTest method testInvalidRestriction.
@Test
public void testInvalidRestriction() throws Exception {
NodeUtil restriction = createAcl().getChild(aceName).getChild(REP_RESTRICTIONS);
restriction.setString("invalid", "value");
try {
root.commit();
fail("Creating an unsupported restriction should fail.");
} catch (CommitFailedException e) {
// success
assertTrue(e.isAccessControlViolation());
assertThat(e.getMessage(), containsString("/testRoot/rep:policy"));
}
}
Aggregations