AccessControlManagerImpl extends AbstractAccessControlManager implements PolicyOwner { @Override public void removePolicy(@Nullable String absPath, @NotNull AccessControlPolicy policy) throws RepositoryException { String oakPath = getOakPath(absPath); Util.checkValidPolicy(oakPath, policy); Map<String, Principal> principalMap = new HashMap<>(); if (policy instanceof PrincipalACL) { PrincipalACL principalAcl = (PrincipalACL) policy; for (ACE ace : principalAcl.getEntries()) { String path = getNodePath(ace); Tree tree = getTree(path, Permissions.MODIFY_ACCESS_CONTROL, true); Tree aclTree = getAclTree(path, tree); if (aclTree == null) { throw new AccessControlException("Unable to retrieve policy node at " + path); } Iterator<Tree> children = aclTree.getChildren().iterator(); while (children.hasNext()) { Tree child = children.next(); if (ace.equals(createACE(path, child, principalAcl.rProvider, principalMap))) { child.remove(); } } if (!aclTree.getChildren().iterator().hasNext()) { aclTree.remove(); } } } else { Tree tree = getTree(oakPath, Permissions.MODIFY_ACCESS_CONTROL, true); Tree aclTree = getAclTree(oakPath, tree); if (aclTree != null) { aclTree.remove(); } else { throw new AccessControlException("No policy to remove at " + absPath); } } } 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 testRemovePolicy() throws Exception { ACL acl = setupPolicy(testPath); acMgr.removePolicy(testPath, acl); assertPolicies(acMgr.getPolicies(testPath), 0); assertTrue(acMgr.getApplicablePolicies(testPath).hasNext()); }
@Test public void testRemoveInvalidPolicy() throws Exception { ACL acl = setupPolicy(testPath); try { acMgr.removePolicy(testPath, new TestACL(testPath, getRestrictionProvider(), getNamePathMapper())); fail("Invalid policy -> removal must fail"); } catch (AccessControlException e) { } ACL repoAcl = setupPolicy(null); try { acMgr.removePolicy(testPath, repoAcl); fail("Setting invalid policy must fail"); } catch (AccessControlException e) { } try { acMgr.removePolicy(null, acl); fail("Setting invalid policy must fail"); } catch (AccessControlException e) { } }
@Test public void testRemovePolicyInvalidPath() { for (String invalid : getInvalidPaths()) { try { AccessControlPolicy acl = createPolicy(invalid); acMgr.removePolicy(invalid, acl); fail("Removing access control policy with invalid path should fail"); } catch (RepositoryException e) { } } }
@Test(expected = PathNotFoundException.class) public void testRemovePolicyPropertyPath() throws Exception { String path = "/jcr:primaryType"; AccessControlPolicy acl = createPolicy(path); acMgr.removePolicy(path, acl); }
@Test(expected = PathNotFoundException.class) public void testRemovePolicyNonExistingNodePath() throws Exception { String path = "/non/existing"; AccessControlPolicy acl = createPolicy(path); acMgr.removePolicy(path, acl); }
@Test public void testRemovePolicyAcContent() throws Exception { for (String acPath : getAcContentPaths()) { try { AccessControlPolicy acl = createPolicy(acPath); acMgr.removePolicy(acPath, acl); fail("Removing access control policy to access control content should fail"); } catch (AccessControlException e) { } } }
@Test(expected = AccessControlException.class) public void testRemovePolicyAtDifferentPath() throws Exception { setupPolicy(testPath); ACL acl = TestUtility.getApplicablePolicy(acMgr, PathUtils.ROOT_PATH); acMgr.removePolicy(testPath, acl); }