Search in sources :

Example 86 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList in project jackrabbit-oak by apache.

the class L3_AccessControlListTest method testRemoveEntry.

public void testRemoveEntry() throws RepositoryException {
    assertTrue(AccessControlUtils.addAccessControlEntry(superuser, testRoot, testPrincipal, new String[] { Privilege.JCR_READ }, true));
    assertTrue(AccessControlUtils.addAccessControlEntry(superuser, testRoot, EveryonePrincipal.getInstance(), new String[] { Privilege.JCR_READ }, false));
    // EXERCISE remove the Everyone-ACE from the list and verify that the list still contains the entry for testPrincipal.
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(superuser, testRoot);
    assertNotNull(acl);
    assertEquals(1, acl.size());
}
Also used : JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 87 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList 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 88 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList 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 89 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList in project jackrabbit-oak by apache.

the class L2_AccessControlManagerTest method testRemovePolicy.

public void testRemovePolicy() throws RepositoryException {
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testRoot);
    // EXERCISE: explain why
    try {
        acMgr.removePolicy(testRoot, acl);
        fail("EXERCISE");
    } catch (AccessControlException e) {
    // success
    }
    AccessControlUtils.addAccessControlEntry(superuser, testRoot, testPrincipal, new String[] { Privilege.JCR_READ }, false);
    acl = AccessControlUtils.getAccessControlList(acMgr, testRoot);
    acMgr.removePolicy(testRoot, acl);
}
Also used : AccessControlException(javax.jcr.security.AccessControlException) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 90 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList in project jackrabbit-oak by apache.

the class L2_AccessControlManagerTest method testModifyPolicy.

public void testModifyPolicy() throws RepositoryException {
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testRoot);
    assertNotNull(acl);
    assertEquals(0, acl.getAccessControlEntries().length);
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ) });
    // EXERCISE
    int expectedLength = -1;
    assertEquals(expectedLength, acl.getAccessControlEntries().length);
    // EXERCISE
    int expectedSize = -1;
    assertEquals(expectedSize, acMgr.getApplicablePolicies(testRoot).getSize());
    // EXERCISE
    expectedLength = -1;
    assertEquals(expectedLength, acMgr.getPolicies(testRoot).length);
}
Also used : JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Aggregations

JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)165 AccessControlManager (javax.jcr.security.AccessControlManager)75 Privilege (javax.jcr.security.Privilege)56 AccessControlEntry (javax.jcr.security.AccessControlEntry)46 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)46 Test (org.junit.Test)40 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)32 Principal (java.security.Principal)29 Node (javax.jcr.Node)23 Session (javax.jcr.Session)17 Value (javax.jcr.Value)17 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)15 Tree (org.apache.jackrabbit.oak.api.Tree)15 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)13 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)12 AccessControlException (javax.jcr.security.AccessControlException)10 NodeImpl (org.apache.jackrabbit.core.NodeImpl)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 Group (org.apache.jackrabbit.api.security.user.Group)8