CompositeAccessControlManager extends AbstractAccessControlManager { @Override public AccessControlPolicy[] getEffectivePolicies(String absPath) throws RepositoryException { ImmutableList.Builder<AccessControlPolicy> policies = ImmutableList.builder(); for (AccessControlManager acMgr : acMgrs) { policies.add(acMgr.getEffectivePolicies(absPath)); if (aggregationFilter.stop(acMgr, absPath)) { break; } } List<AccessControlPolicy> l = policies.build(); return l.toArray(new AccessControlPolicy[0]); } CompositeAccessControlManager(@NotNull Root root,
                                         @NotNull NamePathMapper namePathMapper,
                                         @NotNull SecurityProvider securityProvider,
                                         @NotNull List<AccessControlManager> acMgrs,
                                         @NotNull AggregationFilter aggregationFilter); @NotNull @Override Privilege[] getSupportedPrivileges(String absPath); @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); @NotNull @Override JackrabbitAccessControlPolicy[] getApplicablePolicies(@NotNull Principal principal); @NotNull @Override JackrabbitAccessControlPolicy[] getPolicies(@NotNull Principal principal); @NotNull @Override AccessControlPolicy[] getEffectivePolicies(@NotNull Set<Principal> principals);  }
@Test public void testGetEffectivePolicies() throws Exception { AccessControlPolicy[] effective = acMgr.getEffectivePolicies(TEST_PATH); assertEquals(0, effective.length); AccessControlPolicyIterator it = acMgr.getApplicablePolicies(TEST_PATH); while (it.hasNext()) { AccessControlPolicy plc = it.nextAccessControlPolicy(); if (plc instanceof AccessControlList) { ((AccessControlList) plc).addAccessControlEntry(EveryonePrincipal.getInstance(), privilegesFromNames(PrivilegeConstants.JCR_READ)); } acMgr.setPolicy(TEST_PATH, plc); } root.commit(); assertEquals(2, acMgr.getEffectivePolicies(TEST_PATH).length); Tree child = root.getTree(TEST_PATH).addChild("child"); child.setProperty(JcrConstants.JCR_PRIMARYTYPE, NodeTypeConstants.NT_OAK_UNSTRUCTURED); assertEquals(1, acMgr.getEffectivePolicies(child.getPath()).length); }
@Test public void testEffectivePoliciesByPrincipalNotJackrabbitAcMgr() throws Exception { AccessControlManager mgr = mock(AccessControlManager.class); Set<Principal> principalSet = ImmutableSet.of(EveryonePrincipal.getInstance()); CompositeAccessControlManager composite = createComposite(mgr); assertEquals(0, composite.getEffectivePolicies(principalSet).length); verifyZeroInteractions(mgr); }
@Test public void testEffectivePoliciesByPrincipal() throws Exception { JackrabbitAccessControlPolicy policy = mock(JackrabbitAccessControlPolicy.class); JackrabbitAccessControlManager mgr = mock(JackrabbitAccessControlManager.class, withSettings().extraInterfaces(PolicyOwner.class)); when(mgr.getEffectivePolicies(any(Set.class))).thenReturn(new JackrabbitAccessControlPolicy[] {policy}); Set<Principal> principalSet = ImmutableSet.of(EveryonePrincipal.getInstance()); CompositeAccessControlManager composite = createComposite(mgr); assertArrayEquals(new JackrabbitAccessControlPolicy[] {policy}, composite.getEffectivePolicies(principalSet)); verify(mgr, times(1)).getEffectivePolicies(principalSet); }