PrincipalBasedAccessControlManager extends AbstractAccessControlManager implements PolicyOwner, Constants { @NotNull @Override public AccessControlPolicy[] getEffectivePolicies(@NotNull Set<Principal> principals) throws RepositoryException { if (canHandle(principals)) { Set<AccessControlPolicy> effective = new HashSet<>(principals.size()); for (Principal principal : principals) { AccessControlPolicy policy = createPolicy(principal, true); if (policy != null) { effective.add(policy); } } return effective.toArray(new AccessControlPolicy[0]); } else { return new JackrabbitAccessControlPolicy[0]; } } PrincipalBasedAccessControlManager(@NotNull MgrProvider mgrProvider,
                                       @NotNull FilterProvider filterProvider); @NotNull @Override JackrabbitAccessControlPolicy[] getApplicablePolicies(@NotNull Principal principal); @NotNull @Override JackrabbitAccessControlPolicy[] getPolicies(@NotNull Principal principal); @NotNull @Override AccessControlPolicy[] getEffectivePolicies(@NotNull Set<Principal> principals); @Override AccessControlPolicy[] getPolicies(String absPath); @Override AccessControlPolicy[] getEffectivePolicies(String absPath); @Override AccessControlPolicyIterator getApplicablePolicies(String absPath); @Override void setPolicy(String absPath, AccessControlPolicy policy); @Override void removePolicy(String absPath, AccessControlPolicy policy); @Override boolean defines(@Nullable String absPath, @NotNull AccessControlPolicy accessControlPolicy);  }
@Test(expected = AccessControlException.class) public void testGetEffectivePoliciesEmptyPrincipalName() throws Exception { acMgr.getEffectivePolicies(ImmutableSet.of(validPrincipal, new PrincipalImpl(""))); }
@Test public void testGetEffectivePoliciesNothingSet() throws Exception { assertEquals(0, acMgr.getEffectivePolicies(ImmutableSet.of(validPrincipal)).length); }
@Test public void testGetEffectivePolicies() throws Exception { PrincipalPolicyImpl policy = (PrincipalPolicyImpl) acMgr.getApplicablePolicies(validPrincipal)[0]; policy.addEntry(testContentJcrPath, privilegesFromNames(PrivilegeConstants.JCR_ALL)); acMgr.setPolicy(policy.getPath(), policy); AccessControlPolicy[] effective = acMgr.getEffectivePolicies(ImmutableSet.of(validPrincipal)); assertEquals(0, effective.length); root.commit(); effective = acMgr.getEffectivePolicies(ImmutableSet.of(validPrincipal)); assertEffectivePolicy(effective, 1); }
@Test public void testGetEffectivePoliciesRemovedPrincipal() throws Exception { setupPrincipalBasedAccessControl(validPrincipal, null, JCR_WORKSPACE_MANAGEMENT); root.commit(); String id = getTestSystemUser().getID(); Root latestRoot = adminSession.getLatestRoot(); getUserManager(latestRoot).getAuthorizable(validPrincipal).remove(); latestRoot.commit(); try { assertEquals(0, acMgr.getEffectivePolicies(ImmutableSet.of(validPrincipal)).length); } finally { root.refresh(); getUserManager(root).createSystemUser(id, INTERMEDIATE_PATH); root.commit(); } }
@Test public void testGetEffectivePoliciesMixedPrincipalSet() throws Exception { setupPrincipalBasedAccessControl(validPrincipal, testJcrPath, JCR_READ); root.commit(); Set<Principal> mixedPrincipalSet = ImmutableSet.of(validPrincipal, getTestUser().getPrincipal()); assertEquals(0, acMgr.getEffectivePolicies(mixedPrincipalSet).length); }
@Test public void testGetEffectivePoliciesRemovedPolicy() throws Exception { setupPrincipalBasedAccessControl(validPrincipal, null, JCR_WORKSPACE_MANAGEMENT); root.commit(); Root latestRoot = adminSession.getLatestRoot(); latestRoot.getTree(getNamePathMapper().getOakPath(validPrincipal.getPath())).getChild(REP_PRINCIPAL_POLICY).remove(); latestRoot.commit(); assertEquals(0, acMgr.getEffectivePolicies(ImmutableSet.of(validPrincipal)).length); }
@Test public void testGetEffectivePoliciesByPathNothingSet() throws Exception { setupContentTrees(TEST_OAK_PATH); assertEquals(0, acMgr.getEffectivePolicies(testContentJcrPath).length); assertEquals(0, acMgr.getEffectivePolicies((String) null).length); }
@Test public void testGetEffectivePoliciesByPathTransientPolicy() throws Exception { setupContentTrees(TEST_OAK_PATH); setupPrincipalBasedAccessControl(validPrincipal, testContentJcrPath, JCR_VERSION_MANAGEMENT); assertEquals(0, acMgr.getEffectivePolicies(testContentJcrPath).length); assertEquals(0, acMgr.getEffectivePolicies(testJcrPath).length); }
@Test(expected = PathNotFoundException.class) public void testGetEffectivePoliciesByNonExistingPath() throws Exception { PrincipalPolicyImpl policy = setupPrincipalBasedAccessControl(validPrincipal, testContentJcrPath, JCR_VERSION_MANAGEMENT); addPrincipalBasedEntry(policy, PathUtils.ROOT_PATH, JCR_READ); root.commit(); acMgr.getEffectivePolicies(testContentJcrPath); }
@Test public void testGetEffectivePoliciesByPath() throws Exception { setupContentTrees(TEST_OAK_PATH); PrincipalPolicyImpl policy = setupPrincipalBasedAccessControl(validPrincipal, testContentJcrPath, JCR_REMOVE_CHILD_NODES); addPrincipalBasedEntry(policy, PathUtils.ROOT_PATH, JCR_READ); root.commit(); assertEffectivePolicy(acMgr.getEffectivePolicies(testJcrPath), 2); assertEffectivePolicy(acMgr.getEffectivePolicies(testContentJcrPath), 2); assertEffectivePolicy(acMgr.getEffectivePolicies(PathUtils.ROOT_PATH), 1); }