PrincipalBasedAccessControlManager extends AbstractAccessControlManager implements PolicyOwner, Constants { @Override public void setPolicy(String absPath, AccessControlPolicy policy) throws RepositoryException { PrincipalPolicyImpl pp = checkValidPolicy(absPath, policy); String oakPath = pp.getOakPath(); Tree tree = getTree(oakPath, Permissions.MODIFY_ACCESS_CONTROL, true); Tree policyTree = getPolicyTree(tree); if (policyTree.exists()) { policyTree.remove(); } TreeUtil.addMixin(tree, MIX_REP_PRINCIPAL_BASED_MIXIN, getRoot().getTree(NodeTypeConstants.NODE_TYPES_PATH), getRoot().getContentSession().getAuthInfo().getUserID()); policyTree = TreeUtil.addChild(tree, REP_PRINCIPAL_POLICY, NT_REP_PRINCIPAL_POLICY); policyTree.setOrderableChildren(true); policyTree.setProperty(Constants.REP_PRINCIPAL_NAME, pp.getPrincipal().getName()); int i = 0; RestrictionProvider restrictionProvider = mgrProvider.getRestrictionProvider(); for (PrincipalPolicyImpl.EntryImpl entry : pp.getEntries()) { String effectiveOakPath = Strings.nullToEmpty(entry.getOakPath()); Tree entryTree = TreeUtil.addChild(policyTree, "entry" + i++, NT_REP_PRINCIPAL_ENTRY); if (!Utils.hasModAcPermission(getPermissionProvider(), effectiveOakPath)) { throw new AccessDeniedException("Access denied."); } entryTree.setProperty(REP_EFFECTIVE_PATH, effectiveOakPath, Type.PATH); entryTree.setProperty(Constants.REP_PRIVILEGES, privilegeBitsProvider.getPrivilegeNames(entry.getPrivilegeBits()), Type.NAMES); restrictionProvider.writeRestrictions(oakPath, entryTree, entry.getRestrictions()); } } 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 testSetInvalidPolicy() throws Exception { PrincipalAccessControlList policy = mock(PrincipalAccessControlList.class); acMgr.setPolicy(validPrincipal.getPath(), policy); }
@Test(expected = AccessControlException.class) public void testSetPolicyPathMismatch() throws Exception { PrincipalPolicyImpl policy = createValidPolicy(); acMgr.setPolicy(policy.getOakPath(), policy); }
@Test(expected = AccessControlException.class) public void testSetPolicyNullPath() throws Exception { PrincipalAccessControlList policy = mock(PrincipalAccessControlList.class); acMgr.setPolicy(null, policy); }
@Test(expected = AccessControlException.class) public void testSetPolicyUnsupportedPath() throws Exception { String unsupportedJcrPath = getNamePathMapper().getJcrPath(PathUtils.getParentPath(SUPPORTED_PATH)); acMgr.setPolicy(unsupportedJcrPath, createValidPolicy()); }
@Test public void testSetPolicyNonExistingEffectivePath() throws Exception { PrincipalPolicyImpl policy = getPrincipalPolicyImpl(validPrincipal, acMgr); policy.addEntry(testJcrPath, privilegesFromNames(JCR_READ)); acMgr.setPolicy(policy.getPath(), policy); root.commit(); }
@Test public void testSetPolicyRemovedEffectivePath() throws Exception { setupContentTrees(TEST_OAK_PATH); root.commit(); PrincipalPolicyImpl policy = getPrincipalPolicyImpl(validPrincipal, acMgr); policy.addEntry(testJcrPath, privilegesFromNames(JCR_READ)); root.getTree(TEST_OAK_PATH).remove(); root.commit(); acMgr.setPolicy(policy.getPath(), policy); root.commit(); }
@Test public void testSetPolicy() throws Exception { PrincipalPolicyImpl policy = setupPrincipalBasedAccessControl(validPrincipal, PathUtils.ROOT_PATH, JCR_READ_ACCESS_CONTROL); addPrincipalBasedEntry(policy, null, JCR_WORKSPACE_MANAGEMENT); Tree policyTree = root.getTree(policy.getOakPath()).getChild(REP_PRINCIPAL_POLICY); assertTrue(policyTree.exists()); assertEquals(2, policyTree.getChildrenCount(10)); AccessControlPolicy[] policies = acMgr.getPolicies(validPrincipal); assertEquals(1, policies.length); assertEquals(2, ((PrincipalPolicyImpl)policies[0]).size()); assertEquals(0, acMgr.getApplicablePolicies(validPrincipal).length); }