Search in sources :

Example 41 with AccessControlPolicy

use of javax.jcr.security.AccessControlPolicy 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)

Example 42 with AccessControlPolicy

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

the class AccessControlPolicyTest method testNodeIsModifiedAfterRemovePolicy.

public void testNodeIsModifiedAfterRemovePolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanReadAc(path);
    checkCanModifyAc(path);
    Item item = superuser.getItem(path);
    if (acMgr.getPolicies(path).length == 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);
        } else {
            throw new NotExecutableException();
        }
    }
    // test transient behaviour of the removal
    try {
        AccessControlPolicy[] plcs = acMgr.getPolicies(path);
        if (plcs.length > 0) {
            acMgr.removePolicy(path, plcs[0]);
            assertTrue("After removing a policy the node must be marked modified.", item.isModified());
        }
    } finally {
        item.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 43 with AccessControlPolicy

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

the class AccessControlPolicyTest method testApplicablePoliciesAreDistintFromSetPolicies.

public void testApplicablePoliciesAreDistintFromSetPolicies() throws RepositoryException, NotExecutableException {
    checkCanReadAc(path);
    // call must succeed without exception
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    Set<AccessControlPolicy> acps = new HashSet<AccessControlPolicy>();
    while (it.hasNext()) {
        acps.add(it.nextAccessControlPolicy());
    }
    AccessControlPolicy[] policies = acMgr.getPolicies(path);
    for (int i = 0; i < policies.length; i++) {
        assertFalse("The applicable policies obtained should not be present among the policies obtained through AccessControlManager.getPolicies.", acps.contains(policies[i]));
    }
}
Also used : NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) HashSet(java.util.HashSet)

Example 44 with AccessControlPolicy

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

the class RSessionAccessControlPolicyTest method testSetInvalidPolicy.

public void testSetInvalidPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
    try {
        testAcMgr.setPolicy(path, new AccessControlPolicy() {

            public String getName() throws RepositoryException {
                return getClass().getName();
            }

            public String getDescription() throws RepositoryException {
                return "";
            }
        });
        fail("Invalid policy may not be set by a READ-only session.");
    } catch (AccessControlException e) {
    // success.
    }
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException)

Example 45 with AccessControlPolicy

use of javax.jcr.security.AccessControlPolicy 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)

Aggregations

AccessControlPolicy (javax.jcr.security.AccessControlPolicy)182 Test (org.junit.Test)67 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)66 AccessControlManager (javax.jcr.security.AccessControlManager)62 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)52 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)52 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)49 AccessControlEntry (javax.jcr.security.AccessControlEntry)40 AccessControlList (javax.jcr.security.AccessControlList)32 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)32 NamedAccessControlPolicy (javax.jcr.security.NamedAccessControlPolicy)28 Privilege (javax.jcr.security.Privilege)28 Principal (java.security.Principal)24 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)23 NodeImpl (org.apache.jackrabbit.core.NodeImpl)18 TestACL (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL)18 Node (javax.jcr.Node)17 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)17 Root (org.apache.jackrabbit.oak.api.Root)14 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)14