Search in sources :

Example 1 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.

the class AuthorizablePropertiesImpl method checkProtectedProperty.

private void checkProtectedProperty(@Nonnull Tree parent, @Nonnull PropertyState property) throws RepositoryException {
    ReadOnlyNodeTypeManager nodeTypeManager = authorizable.getUserManager().getNodeTypeManager();
    PropertyDefinition def = nodeTypeManager.getDefinition(parent, property, false);
    if (def.isProtected()) {
        throw new ConstraintViolationException("Attempt to set an protected property " + property.getName());
    }
}
Also used : ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ReadOnlyNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 2 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.

the class UserImportTest method testIncompleteUser.

@Test
public void testIncompleteUser() throws Exception {
    List<String> incompleteXml = new ArrayList<String>();
    incompleteXml.add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + "</sv:node>");
    incompleteXml.add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + "</sv:node>");
    Session s = getImportSession();
    for (String xml : incompleteXml) {
        Node target = s.getNode(getTargetPath());
        try {
            doImport(getTargetPath(), xml);
            // saving changes of the import -> must fail as mandatory prop is missing
            try {
                s.save();
                fail("Import must be incomplete. Saving changes must fail.");
            } catch (ConstraintViolationException e) {
            // success
            }
        } finally {
            s.refresh(false);
            if (target.hasNode("t")) {
                target.getNode("t").remove();
                s.save();
            }
        }
    }
}
Also used : Node(javax.jcr.Node) ArrayList(java.util.ArrayList) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 3 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.

the class AuthorizablePropertyTest method testRemoveSpecialGroupPropertiesDirectly.

@Test
public void testRemoveSpecialGroupPropertiesDirectly() throws RepositoryException, NotExecutableException {
    Node n = getNode(group, superuser);
    try {
        if (n.hasProperty(UserConstants.REP_PRINCIPAL_NAME)) {
            n.getProperty(UserConstants.REP_PRINCIPAL_NAME).remove();
            fail("Attempt to remove protected property rep:principalName should fail.");
        }
    } catch (ConstraintViolationException e) {
    // ok.
    }
    try {
        if (n.hasProperty(UserConstants.REP_MEMBERS)) {
            n.getProperty(UserConstants.REP_MEMBERS).remove();
            fail("Attempt to remove protected property rep:members should fail.");
        }
    } catch (ConstraintViolationException e) {
    // ok.
    }
}
Also used : Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Test(org.junit.Test)

Example 4 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.

the class AuthorizablePropertyTest method testRemoveSpecialUserPropertiesDirectly.

@Test
public void testRemoveSpecialUserPropertiesDirectly() throws RepositoryException, NotExecutableException {
    Node n = getNode(user, superuser);
    try {
        n.getProperty(UserConstants.REP_PASSWORD).remove();
        fail("Attempt to remove protected property rep:password should fail.");
    } catch (ConstraintViolationException e) {
    // ok.
    }
    try {
        if (n.hasProperty(UserConstants.REP_PRINCIPAL_NAME)) {
            n.getProperty(UserConstants.REP_PRINCIPAL_NAME).remove();
            fail("Attempt to remove protected property rep:principalName should fail.");
        }
    } catch (ConstraintViolationException e) {
    // ok.
    }
}
Also used : Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Test(org.junit.Test)

Example 5 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.

the class AccessControlManagementTest method testAcContentIsProtected.

@Test
public void testAcContentIsProtected() throws Exception {
    // search for a rep:policy node
    Node policyNode = findPolicyNode(superuser.getRootNode());
    if (policyNode == null) {
        throw new NotExecutableException("no policy node found.");
    }
    assertTrue("The rep:Policy node must be protected", policyNode.getDefinition().isProtected());
    try {
        policyNode.remove();
        fail("rep:Policy node must be protected.");
    } catch (ConstraintViolationException e) {
    // success
    }
    for (NodeIterator it = policyNode.getNodes(); it.hasNext(); ) {
        Node n = it.nextNode();
        if (n.isNodeType("rep:ACE")) {
            try {
                n.remove();
                fail("ACE node must be protected.");
            } catch (ConstraintViolationException e) {
            // success
            }
            break;
        }
    }
    try {
        policyNode.setProperty("test", "anyvalue");
        fail("rep:policy node must be protected.");
    } catch (ConstraintViolationException e) {
    // success
    }
    try {
        policyNode.addNode("test", "rep:ACE");
        fail("rep:policy node must be protected.");
    } catch (ConstraintViolationException e) {
    // success
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Test(org.junit.Test)

Aggregations

ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)180 Node (javax.jcr.Node)74 RepositoryException (javax.jcr.RepositoryException)40 Name (org.apache.jackrabbit.spi.Name)33 Value (javax.jcr.Value)31 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)28 Test (org.junit.Test)27 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)23 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)23 Session (javax.jcr.Session)18 ItemExistsException (javax.jcr.ItemExistsException)17 NodeState (org.apache.jackrabbit.core.state.NodeState)16 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)16 Property (javax.jcr.Property)14 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)14 ArrayList (java.util.ArrayList)13 NodeId (org.apache.jackrabbit.core.id.NodeId)13 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)13 NodeType (javax.jcr.nodetype.NodeType)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)12