Search in sources :

Example 26 with JackrabbitAccessControlManager

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
}
Also used : JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy)

Example 27 with JackrabbitAccessControlManager

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);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)

Example 28 with JackrabbitAccessControlManager

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));
    }
}
Also used : JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)

Example 29 with JackrabbitAccessControlManager

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)));
}
Also used : JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)

Aggregations

JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)29 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)16 Principal (java.security.Principal)15 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)15 Privilege (javax.jcr.security.Privilege)11 Test (org.junit.Test)8 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)7 Root (org.apache.jackrabbit.oak.api.Root)7 AccessControlManager (javax.jcr.security.AccessControlManager)6 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)6 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)5 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)4 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)4 ImmutableList (com.google.common.collect.ImmutableList)3 Session (javax.jcr.Session)3 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)3 PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)3 UserManager (org.apache.jackrabbit.api.security.user.UserManager)3 PrincipalImpl (org.apache.jackrabbit.core.security.principal.PrincipalImpl)3