use of org.apache.jackrabbit.api.security.JackrabbitAccessControlManager in project jackrabbit-oak by apache.
the class L4_EffectivePoliciesTest method testSessionGetEffectivePoliciesByPrincipalWithoutPrivileges.
public void testSessionGetEffectivePoliciesByPrincipalWithoutPrivileges() throws Exception {
setupPolicy(testRoot, testPrivileges, 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 org.apache.jackrabbit.api.security.JackrabbitAccessControlManager in project jackrabbit-oak by apache.
the class L2_AccessControlManagerTest method testGetAccessControlManager.
public void testGetAccessControlManager() throws RepositoryException {
// EXERCISE retrieve the access control manager using standard JCR API
AccessControlManager acMgr = null;
assertNotNull(acMgr);
// EXERCISE retrieve the jackrabbit access control manager using standard API, without risking a class-cast exception.
JackrabbitAccessControlManager jackrabbitAcMgr = null;
assertNotNull(jackrabbitAcMgr);
}
use of org.apache.jackrabbit.api.security.JackrabbitAccessControlManager in project jackrabbit-oak by apache.
the class L7_PrivilegeDiscoveryTest method testGetPrivilegesForPrincipals.
public void testGetPrivilegesForPrincipals() throws Exception {
JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) superuser.getAccessControlManager();
// 1. EXERCISE: expected privileges for the 'uPrincipal' only
Set<Principal> principals = ImmutableSet.of(uPrincipal);
Map<String, Set<Privilege>> expected = ImmutableMap.of(// EXERCISE
testRoot, // EXERCISE
null, // EXERCISE
testPath, // EXERCISE
null, // EXERCISE
childPath, // EXERCISE
null);
for (String path : expected.keySet()) {
Set<Privilege> expectedPrivs = expected.get(path);
Privilege[] privs = acMgr.getPrivileges(path, principals);
assertEquals(expectedPrivs, ImmutableSet.copyOf(privs));
}
// 2. EXERCISE: expected privileges for the 'gPrincipal' only
principals = ImmutableSet.of(gPrincipal);
expected = ImmutableMap.of(testRoot, null, testPath, null, childPath, null);
for (String path : expected.keySet()) {
Set<Privilege> expectedPrivs = expected.get(path);
Privilege[] privs = acMgr.getPrivileges(path, principals);
assertEquals(expectedPrivs, ImmutableSet.copyOf(privs));
}
// 3. EXERCISE: expected privileges for the 'uPrincipal' and 'gPrincipal'
principals = ImmutableSet.of(uPrincipal, gPrincipal);
expected = ImmutableMap.of(testRoot, null, testPath, null, childPath, null);
for (String path : expected.keySet()) {
Set<Privilege> expectedPrivs = expected.get(path);
Privilege[] privs = acMgr.getPrivileges(path, principals);
assertEquals(expectedPrivs, ImmutableSet.copyOf(privs));
}
// 4. EXERCISE: expected privileges for the 'uPrincipal', 'gPrincipal' + everyone
principals = ImmutableSet.of(uPrincipal, gPrincipal, EveryonePrincipal.getInstance());
expected = ImmutableMap.of(testRoot, null, testPath, null, childPath, null);
for (String path : expected.keySet()) {
Set<Privilege> expectedPrivs = expected.get(path);
Privilege[] privs = acMgr.getPrivileges(path, principals);
assertEquals(expectedPrivs, ImmutableSet.copyOf(privs));
}
}
use of org.apache.jackrabbit.api.security.JackrabbitAccessControlManager in project jackrabbit-oak by apache.
the class L7_PrivilegeDiscoveryTest method testHasPermissionVsHasPrivilege.
public void testHasPermissionVsHasPrivilege() throws Exception {
JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) userSession.getAccessControlManager();
// EXERCISE: fill in the correct boolean values and compare the difference
// between hasPermission and hasPrivilege. explain!
Boolean canAddNode = null;
assertEquals(canAddNode.booleanValue(), userSession.hasPermission(testPath, Session.ACTION_ADD_NODE));
Boolean canAddChild = null;
assertEquals(canAddChild.booleanValue(), userSession.hasPermission(testPath + "/newChild", Session.ACTION_ADD_NODE));
Boolean hasAddChildPrivilege = null;
assertEquals(hasAddChildPrivilege.booleanValue(), acMgr.hasPrivileges(testPath, AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_ADD_CHILD_NODES)));
Boolean canModifyProperty = null;
assertEquals(canModifyProperty.booleanValue(), userSession.hasPermission(propPath, Session.ACTION_SET_PROPERTY));
Boolean canAddProperty = null;
assertEquals(canAddProperty.booleanValue(), userSession.hasPermission(testPath + "/newProp", JackrabbitSession.ACTION_ADD_PROPERTY));
Boolean hasModifyPropertiesPrivilege = null;
assertEquals(hasModifyPropertiesPrivilege.booleanValue(), acMgr.hasPrivileges(propPath, AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_MODIFY_PROPERTIES)));
}
Aggregations