PrincipalBasedAccessControlManager extends AbstractAccessControlManager implements PolicyOwner, Constants { @NotNull @Override public JackrabbitAccessControlPolicy[] getPolicies(@NotNull Principal principal) throws RepositoryException { JackrabbitAccessControlPolicy policy = null; if (canHandle(principal)) { policy = createPolicy(principal, false); } return (policy == null) ? new JackrabbitAccessControlPolicy[0] : new JackrabbitAccessControlPolicy[]{policy}; } 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 testGetPoliciesNullPrincipal() throws Exception { acMgr.getPolicies((Principal) null); }
@Test(expected = AccessControlException.class) public void testGetPoliciesEmptyPrincipalName() throws Exception { acMgr.getPolicies(new PrincipalImpl("")); }
@Test public void testGetPoliciesPrincipalNotHandled() throws Exception { PrincipalBasedAccessControlManager mgr = createAccessControlManager(root, mockFilterProvider(false)); assertEquals(0, mgr.getPolicies(validPrincipal).length); }
@Test public void testGetPoliciesAccessControlledTree() throws Exception { Tree tree = root.getTree(getNamePathMapper().getOakPath(validPrincipal.getPath())); TreeUtil.addMixin(tree, MIX_REP_PRINCIPAL_BASED_MIXIN, root.getTree(NodeTypeConstants.NODE_TYPES_PATH), "uid"); assertEquals(0, acMgr.getPolicies(validPrincipal).length); }
@Test public void testGetPoliciesByPath() throws RepositoryException { assertEquals(0, acMgr.getPolicies(validPrincipal.getPath()).length); }
@Test(expected = PathNotFoundException.class) public void testGetPoliciesByNonExistingPath() throws RepositoryException { acMgr.getPolicies(testContentJcrPath); }
@Test public void testGetPolicyWithNonAceChild() throws Exception { setupContentTrees(TEST_OAK_PATH); PrincipalPolicyImpl policy = setupPrincipalBasedAccessControl(validPrincipal, testContentJcrPath, JCR_RETENTION_MANAGEMENT); addPrincipalBasedEntry(policy, PathUtils.ROOT_PATH, JCR_READ); Tree policyTree = root.getTree(getNamePathMapper().getOakPath(policy.getPath())).getChild(REP_PRINCIPAL_POLICY); TreeUtil.addChild(policyTree, "nonAceChild", NodeTypeConstants.NT_OAK_UNSTRUCTURED); policy = (PrincipalPolicyImpl) acMgr.getPolicies(validPrincipal)[0]; assertEquals(2, policy.size()); }
@Test public void testGetPolicyMissingMixinType() throws Exception { setupContentTrees(TEST_OAK_PATH); PrincipalPolicyImpl policy = setupPrincipalBasedAccessControl(validPrincipal, testContentJcrPath, JCR_LOCK_MANAGEMENT); addPrincipalBasedEntry(policy, PathUtils.ROOT_PATH, JCR_READ); Tree policyTree = root.getTree(getNamePathMapper().getOakPath(policy.getPath())); policyTree.removeProperty(JcrConstants.JCR_MIXINTYPES); assertEquals(0, acMgr.getPolicies(validPrincipal).length); }