Search in sources :

Example 61 with AccessControlPolicyIterator

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

the class AccessControlPolicyTest method testRemoveTransientlyAddedPolicy.

public void testRemoveTransientlyAddedPolicy() throws RepositoryException, AccessDeniedException {
    AccessControlPolicy[] ex = acMgr.getPolicies(path);
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    while (it.hasNext()) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        acMgr.setPolicy(path, policy);
        acMgr.removePolicy(path, policy);
        String msg = "transiently added AND removing a policy must revert " + "the changes made. " + "ACMgr.getPolicies must then return the original value.";
        assertEquals(msg, Arrays.asList(ex), Arrays.asList(acMgr.getPolicies(path)));
    }
}
Also used : NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 62 with AccessControlPolicyIterator

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

the class AccessControlPolicyTest method testNodeIsModifiedAfterSecondSetPolicy.

public void testNodeIsModifiedAfterSecondSetPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanModifyAc(path);
    // make sure a policy has been explicitely set.
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    if (it.hasNext()) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        acMgr.setPolicy(path, policy);
        superuser.save();
        // remember for tearDown
        addedPolicies.put(path, policy);
    } else {
        throw new NotExecutableException();
    }
    // call 'setPolicy' a second time -> Node must be modified.
    it = acMgr.getApplicablePolicies(path);
    try {
        if (it.hasNext()) {
            Item item = superuser.getItem(path);
            AccessControlPolicy policy = it.nextAccessControlPolicy();
            acMgr.setPolicy(path, policy);
            assertTrue("After setting a policy the node must be marked modified.", item.isModified());
        } else {
            throw new NotExecutableException();
        }
    } finally {
        // revert changes
        superuser.refresh(false);
    }
}
Also used : Item(javax.jcr.Item) NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 63 with AccessControlPolicyIterator

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

the class AccessControlPolicyTest method testGetPolicyAfterSet.

public void testGetPolicyAfterSet() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanReadAc(path);
    checkCanModifyAc(path);
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    if (it.hasNext()) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        acMgr.setPolicy(path, policy);
        AccessControlPolicy[] policies = acMgr.getPolicies(path);
        for (int i = 0; i < policies.length; i++) {
            if (policy.equals(policies[i])) {
                // ok
                return;
            }
        }
        fail("GetPolicies must at least return the policy that has been set before.");
    } else {
        throw new NotExecutableException();
    }
}
Also used : NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 64 with AccessControlPolicyIterator

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

the class AccessControlPolicyTest method testSetAllPolicies.

public void testSetAllPolicies() throws RepositoryException, NotExecutableException {
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    if (!it.hasNext()) {
        throw new NotExecutableException();
    }
    while (it.hasNext()) {
        acMgr.setPolicy(path, it.nextAccessControlPolicy());
    }
    // all policies have been set -> no additional applicable policies.
    it = acMgr.getApplicablePolicies(path);
    assertFalse("After having set all applicable policies AccessControlManager.getApplicablePolicies should return an empty iterator.", it.hasNext());
    assertEquals("After having set all applicable policies AccessControlManager.getApplicablePolicies should return an empty iterator.", 0, it.getSize());
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 65 with AccessControlPolicyIterator

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

the class AccessControlManagerImplTest method testRemovePolicyAfterASetPoliciesCall.

/**
 * This should be able to return the policies that has been transiently added
 * to the node at testRoot, as the getPolicies api specifies that the method should
 * take the transient changes into account.
 * @throws Exception
 */
public void testRemovePolicyAfterASetPoliciesCall() throws Exception {
    try {
        AccessControlPolicyIterator policies = acMgr.getApplicablePolicies(testRoot);
        while (policies.hasNext()) {
            AccessControlList acl = (AccessControlListImpl) policies.nextAccessControlPolicy();
            // GRANT read privilege
            acl.addAccessControlEntry(getUnknownPrincipal(), privilegesFromName(Privilege.JCR_READ));
            acMgr.setPolicy(testRoot, acl);
            AccessControlPolicy[] transientPolicy = acMgr.getPolicies(testRoot);
            acMgr.removePolicy(testRoot, transientPolicy[0]);
            assertEquals(0, acMgr.getPolicies(testRoot).length);
        }
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) 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