Search in sources :

Example 41 with Privilege

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

the class L3_PrecedenceRulesTest method testPrecedenceOfUserPrincipals.

public void testPrecedenceOfUserPrincipals() throws RepositoryException {
    Privilege[] readPrivs = AccessControlUtils.privilegesFromNames(superuser, Privilege.JCR_READ);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(superuser, testRoot);
    acl.addEntry(testPrincipal, readPrivs, false);
    acl.addEntry(testGroupPrincipal, readPrivs, true);
    superuser.getAccessControlManager().setPolicy(acl.getPath(), acl);
    superuser.save();
    // EXERCISE what is the expected result?
    testSession.refresh(false);
    // EXERCISE
    Boolean canRead = null;
    assertEquals(canRead.booleanValue(), testSession.nodeExists(testRoot));
    assertEquals(canRead.booleanValue(), testSession.nodeExists(childPath));
// EXERCISE: now change the permission setup such that the testSession has read access
// EXERCISE: how many ways to you find to achieve this?
}
Also used : Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 42 with Privilege

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

the class L3_AccessControlListTest method testReorderEntries.

public void testReorderEntries() throws Exception {
    Privilege[] read = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_READ_ACCESS_CONTROL);
    Privilege[] write = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_WRITE);
    acl.addAccessControlEntry(testPrincipal, read);
    acl.addEntry(testPrincipal, write, false);
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), write);
    AccessControlEntry[] entries = acl.getAccessControlEntries();
    assertEquals(3, entries.length);
    AccessControlEntry first = entries[0];
    AccessControlEntry second = entries[1];
    AccessControlEntry third = entries[2];
    // EXERCISE: reorder 'second' to the first position
    entries = acl.getAccessControlEntries();
    assertEquals(second, entries[0]);
    assertEquals(first, entries[1]);
    assertEquals(third, entries[2]);
    // EXERCISE reorder 'third' before 'first'
    entries = acl.getAccessControlEntries();
    assertEquals(second, entries[0]);
    assertEquals(third, entries[1]);
    assertEquals(first, entries[2]);
    // EXERCISE reorder 'second' to the end of the list
    entries = acl.getAccessControlEntries();
    assertEquals(third, entries[0]);
    assertEquals(first, entries[1]);
    assertEquals(second, entries[2]);
}
Also used : AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege)

Example 43 with Privilege

use of javax.jcr.security.Privilege 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 44 with Privilege

use of javax.jcr.security.Privilege 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 45 with Privilege

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

the class L2_AccessControlManagerTest method testPoliciesAtNullPath.

public void testPoliciesAtNullPath() throws RepositoryException {
    String testPath = null;
    // EXERCISE define the set of privs that can/must be granted at the 'null' path.
    Privilege[] privileges = null;
    AccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testPath);
    acl.addAccessControlEntry(testPrincipal, privileges);
    acMgr.setPolicy(testPath, acl);
    superuser.save();
// EXERCISE explain (or even verify) the expected result
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Privilege(javax.jcr.security.Privilege)

Aggregations

Privilege (javax.jcr.security.Privilege)336 Test (org.junit.Test)95 AccessControlManager (javax.jcr.security.AccessControlManager)94 Session (javax.jcr.Session)80 Principal (java.security.Principal)63 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)60 Node (javax.jcr.Node)54 AccessControlEntry (javax.jcr.security.AccessControlEntry)52 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)39 Value (javax.jcr.Value)31 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)31 HashMap (java.util.HashMap)28 AccessDeniedException (javax.jcr.AccessDeniedException)26 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)26 AccessControlList (javax.jcr.security.AccessControlList)25 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)25 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)24 ArrayList (java.util.ArrayList)23 HashSet (java.util.HashSet)21 AccessControlException (javax.jcr.security.AccessControlException)21