AccessControlManagerImpl extends AbstractAccessControlManager implements PolicyOwner { @NotNull @Override public AccessControlPolicyIterator getApplicablePolicies(@Nullable String absPath) throws RepositoryException { String oakPath = getOakPath(absPath); Tree tree = getTree(oakPath, Permissions.READ_ACCESS_CONTROL, true); AccessControlPolicy policy = null; Tree aclTree = getAclTree(oakPath, tree); if (aclTree == null) { if (tree.hasChild(Util.getAclName(oakPath))) { log.warn("Colliding policy child without node being access controllable ({}).", absPath); } else { String mixinName = Util.getMixinName(oakPath); if (ntMgr.isNodeType(tree, mixinName) || ntMgr.getEffectiveNodeType(tree).supportsMixin(mixinName)) { policy = new NodeACL(oakPath); } else { log.warn("Node {} cannot be made access controllable.", absPath); } } } if (policy == null) { return AccessControlPolicyIteratorAdapter.EMPTY; } else { return new AccessControlPolicyIteratorAdapter(Collections.singleton(policy)); } } AccessControlManagerImpl(@NotNull Root root, @NotNull NamePathMapper namePathMapper,
                                    @NotNull SecurityProvider securityProvider); @NotNull @Override AccessControlPolicy[] getPolicies(@Nullable String absPath); @NotNull @Override AccessControlPolicy[] getEffectivePolicies(@Nullable String absPath); @NotNull @Override AccessControlPolicyIterator getApplicablePolicies(@Nullable String absPath); @Override void setPolicy(@Nullable String absPath, @NotNull AccessControlPolicy policy); @Override void removePolicy(@Nullable String absPath, @NotNull AccessControlPolicy policy); @NotNull @Override JackrabbitAccessControlPolicy[] getApplicablePolicies(@NotNull Principal principal); @NotNull @Override JackrabbitAccessControlPolicy[] getPolicies(@NotNull Principal principal); @NotNull @Override AccessControlPolicy[] getEffectivePolicies(@NotNull Set<Principal> principals); @Override boolean defines(String absPath, @NotNull AccessControlPolicy accessControlPolicy);  }
@Test public void testGetApplicablePolicies() throws Exception { AccessControlPolicyIterator itr = acMgr.getApplicablePolicies(testPath); assertNotNull(itr); assertTrue(itr.hasNext()); AccessControlPolicy policy = itr.nextAccessControlPolicy(); assertNotNull(policy); assertTrue(policy instanceof ACL); ACL acl = (ACL) policy; assertTrue(acl.isEmpty()); assertEquals(testPath, acl.getPath()); assertFalse(itr.hasNext()); }
@Test public void testGetApplicablePoliciesOnAccessControllable() throws Exception { Tree node = root.getTree(testPath); node.setProperty(JcrConstants.JCR_MIXINTYPES, ImmutableList.of(MIX_REP_ACCESS_CONTROLLABLE), Type.NAMES); AccessControlPolicyIterator itr = acMgr.getApplicablePolicies(testPath); assertNotNull(itr); assertTrue(itr.hasNext()); }
@Test public void testGetApplicableRepoPolicies() throws Exception { AccessControlPolicyIterator itr = acMgr.getApplicablePolicies((String) null); assertNotNull(itr); assertTrue(itr.hasNext()); AccessControlPolicy policy = itr.nextAccessControlPolicy(); assertNotNull(policy); assertTrue(policy instanceof ACL); ACL acl = (ACL) policy; assertTrue(acl.isEmpty()); assertNull(acl.getPath()); assertFalse(itr.hasNext()); }
@Test public void testGetApplicablePoliciesWithCollidingNode() throws Exception { Tree testTree = root.getTree(testPath); TreeUtil.addChild(testTree, REP_POLICY, JcrConstants.NT_UNSTRUCTURED); AccessControlPolicyIterator itr = acMgr.getApplicablePolicies(testPath); assertNotNull(itr); assertFalse(itr.hasNext()); }
@Test(expected = PathNotFoundException.class) public void testApplicablePoliciesForPropertyPath() throws Exception { String propertyPath = "/jcr:primaryType"; acMgr.getApplicablePolicies(propertyPath); }
@Test(expected = PathNotFoundException.class) public void testGetApplicablePoliciesNonExistingNodePath() throws Exception { String nonExistingPath = "/not/existing"; acMgr.getApplicablePolicies(nonExistingPath); }
@Test public void testGetApplicablePoliciesForAcContentPaths() throws Exception { for (String path : getAcContentPaths()) { try { acMgr.getApplicablePolicies(path); fail("Getting applicable policies for access control content should fail."); } catch (AccessControlException e) { } } }
@Test(expected = AccessControlException.class) public void testGetApplicablePoliciesNullPrincipal() throws Exception { acMgr.getApplicablePolicies((Principal) null); }
@Test public void testGetApplicablePoliciesByPrincipal() throws Exception { List<Principal> principals = ImmutableList.of(testPrincipal, EveryonePrincipal.getInstance()); for (Principal principal : principals) { AccessControlPolicy[] applicable = acMgr.getApplicablePolicies(principal); assertPolicies(applicable, 1); assertTrue(applicable[0] instanceof ACL); } }
@Test public void testGetApplicablePoliciesByPrincipal2() throws Exception { setupPolicy(testPath); AccessControlPolicy[] applicable = acMgr.getApplicablePolicies(testPrincipal); assertPolicies(applicable, 1); assertTrue(applicable[0] instanceof ACL); root.commit(); assertPolicies(acMgr.getApplicablePolicies(testPrincipal), 0); }