use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TokenValidatorTest method testChangingTokenKey.
@Test
public void testChangingTokenKey() throws Exception {
TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
NodeUtil tokenTree = new NodeUtil(getTokenTree(info));
try {
tokenTree.setString(TOKEN_ATTRIBUTE_KEY, PasswordUtil.buildPasswordHash("anotherValue"));
root.commit(CommitMarker.asCommitAttributes());
fail("The token key must never be modified.");
} catch (CommitFailedException e) {
assertEquals(61, e.getCode());
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TokenValidatorTest method testTokensNodeBelowRoot.
@Test
public void testTokensNodeBelowRoot() throws Exception {
NodeUtil rootNode = new NodeUtil(root.getTree("/"));
NodeUtil n = null;
try {
// Invalid node type of '.tokens' node
n = rootNode.addChild(TOKENS_NODE_NAME, TOKENS_NT_NAME);
root.commit();
fail("The token parent node must be located below the configured user root.");
} catch (CommitFailedException e) {
assertEquals(64, e.getCode());
} finally {
if (n != null) {
n.getTree().remove();
root.commit(CommitMarker.asCommitAttributes());
}
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeRegistration method validateAndCompileType.
/**
* Validates and pre-compiles the named node type.
*
* @param types builder for the /jcr:system/jcr:nodeTypes node
* @param name name of the node type to validate and compile
* @throws CommitFailedException if type validation fails
*/
private void validateAndCompileType(NodeBuilder types, String name) throws CommitFailedException {
NodeBuilder type = types.child(name);
// - jcr:nodeTypeName (NAME) protected mandatory
PropertyState nodeTypeName = type.getProperty(JCR_NODETYPENAME);
if (nodeTypeName == null || !name.equals(nodeTypeName.getValue(NAME))) {
throw new CommitFailedException(CONSTRAINT, 34, "Unexpected " + JCR_NODETYPENAME + " in type " + name);
}
// Prepare the type node pre-compilation of the rep:NodeType info
Iterable<String> empty = emptyList();
type.setProperty(JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_NODE_TYPE, NAME);
type.removeProperty(REP_SUPERTYPES);
type.setProperty(REP_PRIMARY_SUBTYPES, empty, NAMES);
type.setProperty(REP_MANDATORY_PROPERTIES, empty, NAMES);
type.setProperty(REP_MANDATORY_CHILD_NODES, empty, NAMES);
type.setProperty(REP_PROTECTED_PROPERTIES, empty, NAMES);
type.setProperty(REP_PROTECTED_CHILD_NODES, empty, NAMES);
type.setProperty(REP_HAS_PROTECTED_RESIDUAL_PROPERTIES, false, BOOLEAN);
type.setProperty(REP_HAS_PROTECTED_RESIDUAL_CHILD_NODES, false, BOOLEAN);
type.setProperty(REP_NAMED_SINGLE_VALUED_PROPERTIES, empty, NAMES);
type.getChildNode(REP_NAMED_PROPERTY_DEFINITIONS).remove();
type.getChildNode(REP_RESIDUAL_PROPERTY_DEFINITIONS).remove();
type.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS).remove();
type.getChildNode(REP_RESIDUAL_CHILD_NODE_DEFINITIONS).remove();
// = nt:childNodeDefinition protected sns
for (String childNodeName : type.getChildNodeNames()) {
NodeState definition = type.child(childNodeName).getNodeState();
if (childNodeName.startsWith(JCR_PROPERTYDEFINITION)) {
validateAndCompilePropertyDefinition(type, name, definition);
} else if (childNodeName.startsWith(JCR_CHILDNODEDEFINITION)) {
validateAndCompileChildNodeDefinition(types, type, name, definition);
}
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeRegistration method validateAndCompileChildNodeDefinition.
private void validateAndCompileChildNodeDefinition(NodeBuilder types, NodeBuilder type, String typeName, NodeState definition) throws CommitFailedException {
// - jcr:name (NAME) protected
PropertyState name = definition.getProperty(JCR_NAME);
NodeBuilder definitions;
if (name != null) {
String childNodeName = name.getValue(NAME);
definitions = type.child(REP_NAMED_CHILD_NODE_DEFINITIONS);
definitions.setProperty(JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_NAMED_CHILD_NODE_DEFINITIONS, NAME);
definitions = definitions.child(childNodeName);
// - jcr:mandatory (BOOLEAN) protected mandatory
if (definition.getBoolean(JCR_MANDATORY)) {
addNameToList(type, REP_MANDATORY_CHILD_NODES, childNodeName);
}
// - jcr:protected (BOOLEAN) protected mandatory
if (definition.getBoolean(JCR_PROTECTED)) {
addNameToList(type, REP_PROTECTED_CHILD_NODES, childNodeName);
}
} else {
definitions = type.child(REP_RESIDUAL_CHILD_NODE_DEFINITIONS);
// - jcr:protected (BOOLEAN) protected mandatory
if (definition.getBoolean(JCR_PROTECTED)) {
type.setProperty(REP_HAS_PROTECTED_RESIDUAL_CHILD_NODES, true);
}
}
definitions.setProperty(JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_CHILD_NODE_DEFINITIONS, NAME);
// - jcr:requiredPrimaryTypes (NAME)
// = 'nt:base' protected mandatory multiple
PropertyState requiredTypes = definition.getProperty(JCR_REQUIREDPRIMARYTYPES);
if (requiredTypes != null) {
for (String key : requiredTypes.getValue(NAMES)) {
if (!types.hasChildNode(key)) {
throw new CommitFailedException("Constraint", 33, "Unknown required primary type " + key);
} else if (!definitions.hasChildNode(key)) {
definitions.setChildNode(key, definition).setProperty(JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_CHILD_NODE_DEFINITION, NAME).setProperty(REP_DECLARING_NODE_TYPE, typeName, NAME);
}
}
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeEditor method constraintViolation.
/**
* Throws or logs the specified constraint violation.
*
* @param code code of this violation
* @param message description of the violation
* @throws CommitFailedException the constraint violation
*/
private void constraintViolation(int code, String message) throws CommitFailedException {
String path = getPath();
path = path + '[' + effective + ']';
CommitFailedException exception = new CommitFailedException(CONSTRAINT, code, path + ": " + message);
if (strict) {
throw exception;
} else {
log.warn(exception.getMessage());
}
}
Aggregations