Search in sources :

Example 26 with AccessControlPolicyIterator

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

the class AccessControlPolicyTest method testGetApplicablePolicies.

public void testGetApplicablePolicies() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanReadAc(path);
    // call must succeed without exception
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    assertNotNull("The iterator of applicable policies must not be null", it);
}
Also used : AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 27 with AccessControlPolicyIterator

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

the class AccessControlPolicyTest method testRemovePolicyIsTransient.

public void testRemovePolicyIsTransient() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanReadAc(path);
    checkCanModifyAc(path);
    AccessControlPolicy[] currentPolicies = acMgr.getPolicies(path);
    int size = currentPolicies.length;
    AccessControlPolicy toRemove;
    if (size == 0) {
        // no policy to remove ->> apply one
        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);
            toRemove = policy;
            currentPolicies = acMgr.getPolicies(path);
            size = currentPolicies.length;
        } else {
            throw new NotExecutableException();
        }
    } else {
        toRemove = currentPolicies[0];
    }
    // test transient behaviour of the removal
    acMgr.removePolicy(path, toRemove);
    assertEquals("After transient remove AccessControlManager.getPolicies must return less policies.", size - 1, acMgr.getPolicies(path).length);
    // revert changes
    superuser.refresh(false);
    assertEquals("Reverting a Policy removal must restore the original state.", Arrays.asList(currentPolicies), Arrays.asList(acMgr.getPolicies(path)));
}
Also used : NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 28 with AccessControlPolicyIterator

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

the class AccessControlPolicyTest method testSetPolicy.

public void testSetPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanModifyAc(path);
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    if (it.hasNext()) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        acMgr.setPolicy(path, policy);
    } 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 29 with AccessControlPolicyIterator

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

the class AccessControlPolicyTest method testResetPolicy.

public void testResetPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanReadAc(path);
    checkCanModifyAc(path);
    // make sure that at least a single policy has been set.
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    if (it.hasNext()) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        acMgr.setPolicy(path, policy);
    }
    // access the policies already present at path and test if updating
    // (resetting) the policies works as well.
    AccessControlPolicy[] policies = acMgr.getPolicies(path);
    for (int i = 0; i < policies.length; i++) {
        acMgr.setPolicy(path, policies[i]);
    }
}
Also used : NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 30 with AccessControlPolicyIterator

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

the class AccessControlPolicyTest method testRemovePolicy.

public void testRemovePolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanModifyAc(path);
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    if (it.hasNext()) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        acMgr.setPolicy(path, policy);
        acMgr.removePolicy(path, policy);
        AccessControlPolicy[] plcs = acMgr.getPolicies(path);
        for (int i = 0; i < plcs.length; i++) {
            if (plcs[i].equals(policy)) {
                fail("RemovePolicy must remove 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)

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