Search in sources :

Example 11 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class AbstractRepositoryOperationTest method testRepoPolicyAPI.

public void testRepoPolicyAPI() throws Exception {
    try {
        // initial state: no repo level policy
        AccessControlPolicy[] policies = acMgr.getPolicies(null);
        assertNotNull(policies);
        assertEquals(0, policies.length);
        AccessControlPolicy[] effective = acMgr.getEffectivePolicies(null);
        assertNotNull(effective);
        assertEquals(0, effective.length);
        AccessControlPolicyIterator it = acMgr.getApplicablePolicies(null);
        assertNotNull(it);
        assertTrue(it.hasNext());
        AccessControlPolicy acp = it.nextAccessControlPolicy();
        assertNotNull(acp);
        assertTrue(acp instanceof JackrabbitAccessControlPolicy);
        // modify the repo level policy
        modifyPrivileges(null, NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT.toString(), false);
        modifyPrivileges(null, NameConstants.JCR_NAMESPACE_MANAGEMENT.toString(), true);
        AccessControlPolicy[] plcs = acMgr.getPolicies(null);
        assertNotNull(plcs);
        assertEquals(1, plcs.length);
        assertTrue(plcs[0] instanceof AccessControlList);
        AccessControlList acl = (AccessControlList) plcs[0];
        AccessControlEntry[] aces = acl.getAccessControlEntries();
        assertNotNull(aces);
        assertEquals(2, aces.length);
        assertPrivilege(NameConstants.JCR_NAMESPACE_MANAGEMENT, true);
        assertPermission(Permission.NAMESPACE_MNGMT, true);
        assertPrivilege(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT, false);
        assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);
        effective = acMgr.getEffectivePolicies(null);
        assertNotNull(effective);
        assertEquals(1, effective.length);
        assertTrue(effective[0] instanceof AccessControlList);
        acl = (AccessControlList) effective[0];
        aces = acl.getAccessControlEntries();
        assertNotNull(aces);
        assertEquals(2, aces.length);
        // change the policy: removing the second entry in the access control list
        acl = (AccessControlList) acMgr.getPolicies(null)[0];
        AccessControlEntry toRemove = acl.getAccessControlEntries()[1];
        acl.removeAccessControlEntry(toRemove);
        acMgr.setPolicy(null, acl);
        superuser.save();
        acl = (AccessControlList) acMgr.getPolicies(null)[0];
        aces = acl.getAccessControlEntries();
        assertNotNull(aces);
        assertEquals(1, aces.length);
        assertPrivilege(NameConstants.JCR_NAMESPACE_MANAGEMENT, false);
        assertPermission(Permission.NAMESPACE_MNGMT, false);
        assertPrivilege(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT, false);
        assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);
    } catch (UnsupportedRepositoryOperationException e) {
        throw new NotExecutableException();
    } finally {
        // remove it again
        for (AccessControlPolicy plc : acMgr.getPolicies(null)) {
            acMgr.removePolicy(null, plc);
        }
        superuser.save();
        // back to initial state: no repo level policy
        AccessControlPolicy[] policies = acMgr.getPolicies(null);
        assertNotNull(policies);
        assertEquals(0, policies.length);
        AccessControlPolicy[] effective = acMgr.getEffectivePolicies(null);
        assertNotNull(effective);
        assertEquals(0, effective.length);
        AccessControlPolicyIterator it = acMgr.getApplicablePolicies(null);
        assertNotNull(it);
        assertTrue(it.hasNext());
        AccessControlPolicy acp = it.nextAccessControlPolicy();
        assertNotNull(acp);
        assertTrue(acp instanceof JackrabbitAccessControlPolicy);
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)

Example 12 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class AbstractWriteTest method testACItemsAreProtected.

public void testACItemsAreProtected() throws NotExecutableException, RepositoryException {
    // 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) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 13 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class AbstractImportXmlTest method createReferenceableNode.

/**
     * Creates a node with given name below the testRootNode which will be
     * referenced by the node nodeName2 and returns the UUID assigned to the
     * created node.
     *
     * @param name
     * @return
     * @throws RepositoryException
     * @throws NotExecutableException if the created node is not referenceable
     * and cannot be made referenceable by adding mix:referenceable.
     */
public String createReferenceableNode(String name) throws RepositoryException, NotExecutableException {
    // remove a yet existing node at the target
    try {
        Node node = testRootNode.getNode(name);
        node.remove();
        session.save();
    } catch (PathNotFoundException pnfe) {
    // ok
    }
    // a referenceable node
    Node n1 = testRootNode.addNode(name, testNodeType);
    if (!n1.isNodeType(mixReferenceable) && !n1.canAddMixin(mixReferenceable)) {
        n1.remove();
        session.save();
        throw new NotExecutableException("node type " + testNodeType + " does not support mix:referenceable");
    }
    n1.addMixin(mixReferenceable);
    // make sure jcr:uuid is available
    testRootNode.getSession().save();
    return n1.getUUID();
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 14 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class AbstractImportXmlTest method isMixRefRespected.

//--------------------------------< helpers >-----------------------------------
/**
     * Tests if jcr:uuid property of mix:referenceable nodetype is respected.
     * This is believed as true when during import with uuidBehaviour
     * IMPORT_UUID_COLLISION_REMOVE_EXISTING a node with the same uuid as a node
     * to be imported will be deleted.
     *
     * @return
     * @throws RepositoryException
     * @throws IOException
     */
public boolean isMixRefRespected() throws RepositoryException, IOException {
    boolean respected = false;
    if (supportsNodeType(mixReferenceable)) {
        String uuid;
        try {
            uuid = createReferenceableNode(referenced);
        } catch (NotExecutableException e) {
            return false;
        }
        Document document = dom.newDocument();
        Element root = document.createElement(rootElem);
        root.setAttribute(XML_NS + ":jcr", NS_JCR_URI);
        root.setAttributeNS(NS_JCR_URI, jcrUUID, uuid);
        root.setAttributeNS(NS_JCR_URI, jcrMixinTypes, mixReferenceable);
        document.appendChild(root);
        importXML(refTargetNode.getPath(), document, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING, SESSION);
        session.save();
        // existing node with same uuid should now be deleted
        respected = !testRootNode.hasNode(referenced);
        // check if imported document node is referenceable
        Node rootNode = refTargetNode.getNode(rootElem);
        respected &= rootNode.isNodeType(mixReferenceable);
    }
    return respected;
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Element(org.w3c.dom.Element) Node(javax.jcr.Node) Document(org.w3c.dom.Document)

Example 15 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class AbstractPropertyTest method setUp.

/**
     * Sets up the fixture for the tests.
     */
protected void setUp() throws Exception {
    isReadOnly = true;
    super.setUp();
    session = getHelper().getReadOnlySession();
    prop = PropertyUtil.searchProp(session, session.getRootNode().getNode(testPath), getPropertyType(), getPropertyIsMultivalued());
    if (prop == null) {
        cleanUp();
        String msg = "Workspace does not contain a node with a " + PropertyType.nameFromValue(getPropertyType()) + " property.";
        throw new NotExecutableException(msg);
    }
    multiple = prop.getDefinition().isMultiple();
    Value val = PropertyUtil.getValue(prop);
    if (val == null) {
        cleanUp();
        String msg = PropertyType.nameFromValue(getPropertyType()) + " property does not contain a value";
        throw new NotExecutableException(msg);
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Value(javax.jcr.Value)

Aggregations

NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)381 Node (javax.jcr.Node)149 NodeType (javax.jcr.nodetype.NodeType)84 Value (javax.jcr.Value)81 RepositoryException (javax.jcr.RepositoryException)64 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)61 Session (javax.jcr.Session)59 Property (javax.jcr.Property)47 NodeDefinition (javax.jcr.nodetype.NodeDefinition)29 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)28 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)25 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)23 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)22 Test (org.junit.Test)22 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)21 User (org.apache.jackrabbit.api.security.user.User)19 Principal (java.security.Principal)18 NodeIterator (javax.jcr.NodeIterator)18 UserManager (org.apache.jackrabbit.api.security.user.UserManager)17 ItemExistsException (javax.jcr.ItemExistsException)16