Search in sources :

Example 51 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit-oak by apache.

the class AccessControlManagementTest method testSetNewPolicy.

/**
 * Test if a new applicable policy can be applied within a
 * sub-tree where AC-modification is allowed.
 *
 * @see <a href="https://issues.apache.org/jira/browse/JCR-2869">JCR-2869</a>
 */
@Test
public void testSetNewPolicy() throws Exception {
    /* grant 'testUser' rep:write, rep:readAccessControl and
           rep:modifyAccessControl privileges at 'path' */
    Privilege[] privileges = privilegesFromNames(new String[] { REP_WRITE, Privilege.JCR_READ_ACCESS_CONTROL, Privilege.JCR_MODIFY_ACCESS_CONTROL });
    allow(path, privileges);
    /*
         testuser must be allowed to set a new policy at a child node.
        */
    AccessControlPolicyIterator it = testAcMgr.getApplicablePolicies(childNPath);
    while (it.hasNext()) {
        AccessControlPolicy plc = it.nextAccessControlPolicy();
        testAcMgr.setPolicy(childNPath, plc);
        testSession.save();
        testAcMgr.removePolicy(childNPath, plc);
        testSession.save();
    }
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) Privilege(javax.jcr.security.Privilege) Test(org.junit.Test)

Example 52 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit-oak by apache.

the class AccessControlManagerImplTest method testGetApplicableRepoPolicies.

@Test
public void testGetApplicableRepoPolicies() throws Exception {
    AccessControlPolicyIterator itr = acMgr.getApplicablePolicies((String) null);
    assertNotNull(itr);
    assertTrue(itr.hasNext());
    AccessControlPolicy policy = itr.nextAccessControlPolicy();
    assertNotNull(policy);
    assertTrue(policy instanceof ACL);
    ACL acl = (ACL) policy;
    assertTrue(acl.isEmpty());
    assertNull(acl.getPath());
    assertFalse(itr.hasNext());
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 53 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.

the class EntryCollectorTest method getPolicy.

private ACLTemplate getPolicy(AccessControlManager acM, String path, Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException {
    // try applicable (new) ACLs first
    AccessControlPolicyIterator itr = acM.getApplicablePolicies(path);
    while (itr.hasNext()) {
        AccessControlPolicy policy = itr.nextAccessControlPolicy();
        if (policy instanceof ACLTemplate) {
            return (ACLTemplate) policy;
        }
    }
    // try if there is an acl that has been set before:
    AccessControlPolicy[] pcls = acM.getPolicies(path);
    for (AccessControlPolicy policy : pcls) {
        if (policy instanceof ACLTemplate) {
            return (ACLTemplate) policy;
        }
    }
    // no applicable or existing ACLTemplate to edit -> not executable.
    throw new NotExecutableException();
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 54 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.

the class EvaluationUtil method getPolicy.

static JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path, Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException {
    // try applicable (new) ACLs first
    AccessControlPolicyIterator itr = acM.getApplicablePolicies(path);
    while (itr.hasNext()) {
        AccessControlPolicy policy = itr.nextAccessControlPolicy();
        if (policy instanceof ACLTemplate) {
            return (ACLTemplate) policy;
        }
    }
    // try if there is an acl that has been set before:
    AccessControlPolicy[] pcls = acM.getPolicies(path);
    for (AccessControlPolicy policy : pcls) {
        if (policy instanceof ACLTemplate) {
            return (ACLTemplate) policy;
        }
    }
    // no applicable or existing ACLTemplate to edit -> not executable.
    throw new NotExecutableException();
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 55 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.

the class WriteTest method testApplicablePolicies.

public void testApplicablePolicies() throws RepositoryException {
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(childNPath);
    assertTrue(it.hasNext());
    // the same should be true, if the rep:AccessControllable mixin has
    // been manually added
    Node n = (Node) superuser.getItem(childNPath);
    n.addMixin(((SessionImpl) superuser).getJCRName(AccessControlConstants.NT_REP_ACCESS_CONTROLLABLE));
    it = acMgr.getApplicablePolicies(childNPath);
    assertTrue(it.hasNext());
}
Also used : Node(javax.jcr.Node) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Aggregations

AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)69 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)54 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)22 Test (org.junit.Test)16 NamedAccessControlPolicy (javax.jcr.security.NamedAccessControlPolicy)15 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)15 AccessControlList (javax.jcr.security.AccessControlList)14 AccessControlManager (javax.jcr.security.AccessControlManager)13 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)11 Node (javax.jcr.Node)7 Privilege (javax.jcr.security.Privilege)6 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)6 AccessControlEntry (javax.jcr.security.AccessControlEntry)5 Principal (java.security.Principal)3 HashSet (java.util.HashSet)3 Item (javax.jcr.Item)3 RepositoryException (javax.jcr.RepositoryException)3 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)3 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2