CugAccessControlManager extends AbstractAccessControlManager implements CugConstants, PolicyOwner { @Override public void removePolicy(String absPath, AccessControlPolicy policy) throws RepositoryException { String oakPath = getOakPath(absPath); if (isSupportedPath(oakPath)) { checkValidPolicy(absPath, policy); Tree tree = getTree(oakPath, Permissions.MODIFY_ACCESS_CONTROL, true); Tree cug = tree.getChild(REP_CUG_POLICY); if (!CugUtil.definesCug(cug)) { throw new AccessControlException("Unexpected primary type of node rep:cugPolicy."); } else { Set<String> mixins = Sets.newHashSet(TreeUtil.getNames(tree, NodeTypeConstants.JCR_MIXINTYPES)); if (mixins.remove(MIX_REP_CUG_MIXIN)) { tree.setProperty(JcrConstants.JCR_MIXINTYPES, mixins, NAMES); } else { log.debug("Cannot remove mixin type {}", MIX_REP_CUG_MIXIN); } cug.remove(); } } else { throw new AccessControlException("Unsupported path: " + absPath); } } CugAccessControlManager(@NotNull Root root,
                            @NotNull NamePathMapper namePathMapper,
                            @NotNull SecurityProvider securityProvider,
                            @NotNull Set<String> supportedPaths,
                            @NotNull CugExclude cugExclude, RootProvider rootProvider); @NotNull @Override Privilege[] getSupportedPrivileges(@Nullable String absPath); @Override AccessControlPolicy[] getPolicies(String absPath); @Override AccessControlPolicy[] getEffectivePolicies(String absPath); @Override AccessControlPolicyIterator getApplicablePolicies(String absPath); @Override void removePolicy(String absPath, AccessControlPolicy policy); @Override void setPolicy(String absPath, 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(@Nullable String absPath, @NotNull AccessControlPolicy accessControlPolicy);  }
@Test public void testRemovePolicy() throws Exception { CugPolicy cug = getApplicableCug(); cugAccessControlManager.setPolicy(SUPPORTED_PATH, cug); cugAccessControlManager.removePolicy(SUPPORTED_PATH, cugAccessControlManager.getPolicies(SUPPORTED_PATH)[0]); assertArrayEquals(new AccessControlPolicy[0], cugAccessControlManager.getPolicies(SUPPORTED_PATH)); }
@Test public void testRemoveInvalidPolicy() throws Exception { List<AccessControlPolicy> invalidPolicies = ImmutableList.of( new AccessControlPolicy() {}, (NamedAccessControlPolicy) () -> "name", InvalidCug.INSTANCE ); for (AccessControlPolicy policy : invalidPolicies) { try { cugAccessControlManager.removePolicy(SUPPORTED_PATH, policy); fail("Invalid cug policy must be detected."); } catch (AccessControlException e) { } } }
@Test(expected = AccessControlException.class) public void testRemoveInvalidCugNode() throws Exception { Tree supportedTree = root.getTree(SUPPORTED_PATH); TreeUtil.addChild(supportedTree, REP_CUG_POLICY, NodeTypeConstants.NT_OAK_UNSTRUCTURED); cugAccessControlManager.removePolicy(SUPPORTED_PATH, new CugPolicyImpl(SUPPORTED_PATH, NamePathMapper.DEFAULT, getPrincipalManager(root), ImportBehavior.BESTEFFORT, getExclude())); }
@Test(expected = PathNotFoundException.class) public void testRemovePolicyInvalidPath() throws Exception { cugAccessControlManager.removePolicy(INVALID_PATH, createCug(INVALID_PATH)); }
@Test(expected = AccessControlException.class) public void testRemovePolicyUnsupportedPath() throws Exception { cugAccessControlManager.removePolicy(UNSUPPORTED_PATH, createCug(UNSUPPORTED_PATH)); }
@Test(expected = AccessControlException.class) public void testRemovePolicyPathMismatch() throws Exception { cugAccessControlManager.removePolicy(SUPPORTED_PATH, createCug(SUPPORTED_PATH + "/subtree")); }