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