CompositeAccessControlManager extends AbstractAccessControlManager { @Override public AccessControlPolicyIterator getApplicablePolicies(String absPath) throws RepositoryException { List<AccessControlPolicyIterator> l = Lists.newArrayList(); for (AccessControlManager acMgr : acMgrs) { if (acMgr instanceof PolicyOwner) { l.add(acMgr.getApplicablePolicies(absPath)); } } return new AccessControlPolicyIteratorAdapter(Iterators.concat(l.toArray(new AccessControlPolicyIterator[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 testGetApplicablePolicies() throws Exception { AccessControlPolicyIterator it = acMgr.getApplicablePolicies("/"); while (it.hasNext()) { if (it.nextAccessControlPolicy() == TestPolicy.INSTANCE) { fail("TestPolicy should only be applicable at /test."); } } Set<AccessControlPolicy> applicable = ImmutableSet.copyOf(acMgr.getApplicablePolicies(TEST_PATH)); assertEquals(2, applicable.size()); assertTrue(applicable.contains(TestPolicy.INSTANCE)); }
@Test public void testGetApplicablePoliciesNotPolicyOwner() throws Exception { AccessControlPolicy policy = mock(AccessControlPolicy.class); AccessControlManager mgr = when(mock(AccessControlManager.class).getApplicablePolicies(anyString())).thenReturn(new AccessControlPolicyIteratorAdapter(ImmutableSet.of(policy))).getMock(); CompositeAccessControlManager composite = createComposite(mgr); AccessControlPolicyIterator it = composite.getApplicablePolicies(ROOT_PATH); assertFalse(it.hasNext()); verify(mgr, never()).getApplicablePolicies(ROOT_PATH); }
@Test public void testGetApplicablePoliciesByPrincipalNotOwnerPolicy() throws Exception { JackrabbitAccessControlPolicy policy = mock(JackrabbitAccessControlPolicy.class); JackrabbitAccessControlManager mgr = mock(JackrabbitAccessControlManager.class); when(mgr.getApplicablePolicies(any(Principal.class))).thenReturn(new JackrabbitAccessControlPolicy[] {policy}).getMock(); CompositeAccessControlManager composite = createComposite(mgr); JackrabbitAccessControlPolicy[] applicable = composite.getApplicablePolicies(EveryonePrincipal.getInstance()); assertEquals(0, applicable.length); verify(mgr, never()).getApplicablePolicies(EveryonePrincipal.getInstance()); }
@Test public void testGetApplicablePoliciesByPrincipalNotJackrabbitAcMgr() throws Exception { AccessControlManager mgr = mock(AccessControlManager.class, withSettings().extraInterfaces(PolicyOwner.class)); CompositeAccessControlManager composite = createComposite(mgr); JackrabbitAccessControlPolicy[] applicable = composite.getApplicablePolicies(EveryonePrincipal.getInstance()); assertEquals(0, applicable.length); verifyZeroInteractions(mgr); }
@Test public void testGetApplicablePoliciesByPrincipal() throws Exception { JackrabbitAccessControlPolicy policy = mock(JackrabbitAccessControlPolicy.class); JackrabbitAccessControlManager mgr = mock(JackrabbitAccessControlManager.class, withSettings().extraInterfaces(PolicyOwner.class)); when(mgr.getApplicablePolicies(any(Principal.class))).thenReturn(new JackrabbitAccessControlPolicy[] {policy}).getMock(); CompositeAccessControlManager composite = createComposite(mgr); JackrabbitAccessControlPolicy[] applicable = composite.getApplicablePolicies(EveryonePrincipal.getInstance()); assertArrayEquals(new JackrabbitAccessControlPolicy[] {policy}, applicable); verify(mgr, times(1)).getApplicablePolicies(EveryonePrincipal.getInstance()); }