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);
}
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
}
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);
}
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());
}
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);
}
Aggregations