CompositeAccessControlManager extends AbstractAccessControlManager { @Override public AccessControlPolicy[] getPolicies(String absPath) throws RepositoryException { ImmutableList.Builder<AccessControlPolicy> policies = ImmutableList.builder(); for (AccessControlManager acMgr : acMgrs) { policies.add(acMgr.getPolicies(absPath)); } 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 testGetPolicies() throws Exception { int len = 0; AccessControlPolicy[] policies = acMgr.getPolicies(TEST_PATH); assertEquals(len, policies.length); acMgr.setPolicy(TEST_PATH, TestPolicy.INSTANCE); len++; policies = acMgr.getPolicies(TEST_PATH); assertEquals(len, policies.length); assertSame(TestPolicy.INSTANCE, policies[0]); AccessControlPolicyIterator it = acMgr.getApplicablePolicies(TEST_PATH); while (it.hasNext()) { AccessControlPolicy plc = it.nextAccessControlPolicy(); if (plc == TestPolicy.INSTANCE) { fail("TestPolicy should only be applicable at /test."); } else { acMgr.setPolicy(TEST_PATH, plc); len++; Set<AccessControlPolicy> policySet = ImmutableSet.copyOf(acMgr.getPolicies(TEST_PATH)); assertEquals(len, policySet.size()); assertTrue(policySet.contains(TestPolicy.INSTANCE)); assertTrue(policySet.contains(plc)); } } }
@Test public void testGetPoliciesByPrincipalNotPolicyOwner() throws Exception { AccessControlManager mgr = mock(AccessControlManager.class); CompositeAccessControlManager composite = createComposite(mgr); assertEquals(0, composite.getPolicies(EveryonePrincipal.getInstance()).length); verifyZeroInteractions(mgr); }
@Test public void testGetPoliciesByPrincipalNotJackrabbitAcMgr() throws Exception { JackrabbitAccessControlPolicy policy = mock(JackrabbitAccessControlPolicy.class); JackrabbitAccessControlManager mgr = mock(JackrabbitAccessControlManager.class); when(mgr.getPolicies(any(Principal.class))).thenReturn(new JackrabbitAccessControlPolicy[] {policy}).getMock(); CompositeAccessControlManager composite = createComposite(mgr); assertArrayEquals(new JackrabbitAccessControlPolicy[] {policy}, composite.getPolicies(EveryonePrincipal.getInstance())); verify(mgr, times(1)).getPolicies(EveryonePrincipal.getInstance()); }
@Test public void testGetPoliciesByPrincipal() throws Exception { JackrabbitAccessControlPolicy policy = mock(JackrabbitAccessControlPolicy.class); JackrabbitAccessControlManager mgr = mock(JackrabbitAccessControlManager.class, withSettings().extraInterfaces(PolicyOwner.class)); when(mgr.getPolicies(any(Principal.class))).thenReturn(new JackrabbitAccessControlPolicy[] {policy}).getMock(); CompositeAccessControlManager composite = createComposite(mgr); assertArrayEquals(new JackrabbitAccessControlPolicy[] {policy}, composite.getPolicies(EveryonePrincipal.getInstance())); verify(mgr, times(1)).getPolicies(EveryonePrincipal.getInstance()); }