Search in sources :

Example 11 with CommitFailedException

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());
    }
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 12 with CommitFailedException

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());
        }
    }
}
Also used : CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 13 with CommitFailedException

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);
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 14 with CommitFailedException

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);
            }
        }
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 15 with CommitFailedException

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());
    }
}
Also used : 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