PrincipalBasedAccessControlManager extends AbstractAccessControlManager implements PolicyOwner, Constants { @NotNull @Override public JackrabbitAccessControlPolicy[] getApplicablePolicies(@NotNull Principal principal) throws RepositoryException { if (canHandle(principal)) { String oakPath = filter.getOakPath(principal); Tree tree = getTree(oakPath, Permissions.READ_ACCESS_CONTROL, true); if (!tree.hasChild(REP_PRINCIPAL_POLICY)) { return new JackrabbitAccessControlPolicy[]{new PrincipalPolicyImpl(principal, oakPath, mgrProvider)}; } } 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 testGetApplicablePoliciesNullPrincipal() throws Exception { acMgr.getApplicablePolicies((Principal) null); }
@Test(expected = AccessControlException.class) public void testGetApplicablePoliciesEmptyPrincipalName() throws Exception { acMgr.getApplicablePolicies(new PrincipalImpl("")); }
@Test public void testGetApplicablePoliciesPrincipalNotHandled() throws Exception { PrincipalBasedAccessControlManager mgr = createAccessControlManager(root, mockFilterProvider(false)); assertEquals(0, mgr.getApplicablePolicies(validPrincipal).length); }
@Test public void testGetApplicablePoliciesPrincipalHandled() throws Exception { PrincipalBasedAccessControlManager mgr = createAccessControlManager(root, mockFilterProvider(true)); AccessControlPolicy[] applicable = mgr.getApplicablePolicies(validPrincipal); assertEquals(1, applicable.length); assertTrue(applicable[0] instanceof PrincipalPolicyImpl); }
@Test public void testGetApplicableByPath() throws RepositoryException { assertFalse(acMgr.getApplicablePolicies(validPrincipal.getPath()).hasNext()); }
@Test(expected = PathNotFoundException.class) public void testGetApplicableByNonExistingPath() throws RepositoryException { acMgr.getApplicablePolicies(testContentJcrPath); }