PrincipalBasedAccessControlManager extends AbstractAccessControlManager implements PolicyOwner, Constants { @Override public void removePolicy(String absPath, AccessControlPolicy policy) throws RepositoryException { PrincipalPolicyImpl pp = checkValidPolicy(absPath, policy); Tree policyTree = getPolicyTree(getTree(pp.getOakPath(), Permissions.MODIFY_ACCESS_CONTROL, true)); if (policyTree.exists()) { for (Tree child : policyTree.getChildren()) { if (Utils.isPrincipalEntry(child)) { PropertyState effectivePath = child.getProperty(REP_EFFECTIVE_PATH); if (effectivePath == null) { throw new AccessControlException("Missing mandatory property rep:effectivePath; cannot validate permissions to modify policy."); } else if (!Utils.hasModAcPermission(getPermissionProvider(), effectivePath.getValue(Type.PATH))) { throw new AccessDeniedException("Access denied."); } } } policyTree.remove(); } else { throw new AccessControlException("No policy to remove at " + absPath); } } 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 testRemoveInvalidPolicy() throws Exception { PrincipalAccessControlList policy = mock(PrincipalAccessControlList.class); acMgr.removePolicy(validPrincipal.getPath(), policy); }
@Test(expected = AccessControlException.class) public void testRemovePolicyPathMismatch() throws Exception { PrincipalPolicyImpl policy = createValidPolicy(); acMgr.removePolicy(PathUtils.getParentPath(policy.getPath()), policy); }
@Test(expected = AccessControlException.class) public void testRemovePolicyNullPath() throws Exception { PrincipalAccessControlList policy = mock(PrincipalAccessControlList.class); acMgr.removePolicy(null, policy); }
@Test(expected = AccessControlException.class) public void testRemovePolicyUnsupportedPath() throws Exception { String unsupportedJcrPath = getNamePathMapper().getJcrPath(PathUtils.getParentPath(SUPPORTED_PATH)); acMgr.removePolicy(unsupportedJcrPath, createValidPolicy()); }
@Test public void testRemovePolicy() throws Exception { PrincipalPolicyImpl policy = setupPrincipalBasedAccessControl(validPrincipal, getNamePathMapper().getJcrPath(UserConstants.DEFAULT_USER_PATH), PrivilegeConstants.REP_USER_MANAGEMENT); addPrincipalBasedEntry(policy, null, PrivilegeConstants.REP_PRIVILEGE_MANAGEMENT); acMgr.removePolicy(policy.getPath(), policy); assertEquals(0, acMgr.getPolicies(validPrincipal).length); assertEquals(1, acMgr.getApplicablePolicies(validPrincipal).length); assertFalse(root.getTree(policy.getOakPath()).hasChild(REP_PRINCIPAL_POLICY)); }