Search in sources :

Example 86 with AccessControlPolicy

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

the class L4_EffectivePoliciesTest method testSessionGetEffectivePolicies.

public void testSessionGetEffectivePolicies() throws Exception {
    // grant 'testUser' READ + WRITE privileges at the test root
    setupPolicy(testRoot, testPrivileges, testPrincipal);
    // grant 'testUser' READ + READ_AC privileges at child path
    Privilege[] privileges = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_READ_ACCESS_CONTROL);
    setupPolicy(childPath, privileges, testPrincipal);
    superuser.save();
    testSession = getTestSession();
    AccessControlManager testAcMgr = testSession.getAccessControlManager();
    AccessControlPolicy[] effective = testAcMgr.getEffectivePolicies(childPath);
    // EXERCISE
    int expectedLength = -1;
    assertEquals(expectedLength, effective.length);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Privilege(javax.jcr.security.Privilege)

Example 87 with AccessControlPolicy

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

the class L4_EffectivePoliciesTest method testSessionGetEffectivePoliciesByPrincipal.

public void testSessionGetEffectivePoliciesByPrincipal() throws Exception {
    Privilege[] privileges = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_READ_ACCESS_CONTROL);
    setupPolicy(testRoot, privileges, testPrincipal);
    setupPolicy(childPath, testPrivileges, EveryonePrincipal.getInstance());
    superuser.save();
    testSession = getTestSession();
    JackrabbitAccessControlManager testAcMgr = (JackrabbitAccessControlManager) testSession.getAccessControlManager();
    AccessControlPolicy[] effective = testAcMgr.getEffectivePolicies(Collections.singleton(testPrincipal));
    // EXERCISE
    int expectedLength = -1;
    assertEquals(expectedLength, effective.length);
// EXERCISE : explain the result
}
Also used : JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Privilege(javax.jcr.security.Privilege)

Example 88 with AccessControlPolicy

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

the class L2_AccessControlManagerTest method testRetrievePoliciesAtTestRoot.

public void testRetrievePoliciesAtTestRoot() throws RepositoryException {
    AccessControlPolicy[] policies = acMgr.getPolicies(testRoot);
    // EXERCISE
    int expectedLength = -1;
    assertEquals(expectedLength, policies.length);
    AccessControlPolicyIterator policyIterator = acMgr.getApplicablePolicies(testRoot);
    // EXERCISE
    int expectedSize = -1;
    assertEquals(expectedSize, policyIterator.getSize());
    // EXERCISE: look at the utility methods and explain the expected return value
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testRoot);
    JackrabbitAccessControlList acl2 = AccessControlUtils.getAccessControlList(superuser, testRoot);
    // EXERCISE: is this correct?
    assertEquals(acl, acl2);
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 89 with AccessControlPolicy

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

the class L2_AccessControlManagerTest method testSetPolicy.

public void testSetPolicy() throws RepositoryException {
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testRoot);
    assertTrue(acl.addEntry(testPrincipal, AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ), false));
    // EXERCISE: fix the test.
    assertFalse(acMgr.getApplicablePolicies(testRoot).hasNext());
    AccessControlPolicy[] policies = acMgr.getPolicies(testRoot);
    assertEquals(1, policies.length);
    assertTrue(policies[0] instanceof JackrabbitAccessControlList);
    JackrabbitAccessControlList acl2 = (JackrabbitAccessControlList) policies[0];
    assertFalse(acl2.isEmpty());
    assertEquals(1, acl2.size());
    AccessControlEntry ace = acl2.getAccessControlEntries()[0];
    assertTrue(ace instanceof JackrabbitAccessControlEntry);
    assertEquals(testPrincipal, ace.getPrincipal());
    assertFalse(((JackrabbitAccessControlEntry) ace).isAllow());
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 90 with AccessControlPolicy

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

the class L2_AccessControlManagerTest method testRetrievePoliciesAsReadOnlySession.

public void testRetrievePoliciesAsReadOnlySession() throws RepositoryException {
    testSession = superuser.getRepository().login(ExerciseUtility.getTestCredentials(testID));
    // EXERCISE: Fix the test and explain your fix.
    AccessControlPolicyIterator policyIterator = testSession.getAccessControlManager().getApplicablePolicies(testRoot);
    AccessControlPolicy[] policies = testSession.getAccessControlManager().getPolicies(testRoot);
}
Also used : 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