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