CompositeAuthorizationConfiguration extends CompositeConfiguration<AuthorizationConfiguration> implements AuthorizationConfiguration { @NotNull @Override public PermissionProvider getPermissionProvider(@NotNull final Root root, @NotNull final String workspaceName, @NotNull final Set<Principal> principals) { List<AuthorizationConfiguration> configurations = getConfigurations(); switch (configurations.size()) { case 0: throw new IllegalStateException(); case 1: return configurations.get(0).getPermissionProvider(root, workspaceName, principals); default: List<AggregatedPermissionProvider> aggrPermissionProviders = new ArrayList<>(configurations.size()); for (AuthorizationConfiguration conf : configurations) { PermissionProvider pProvider = conf.getPermissionProvider(root, workspaceName, principals); if (pProvider instanceof AggregatedPermissionProvider) { AggregatedPermissionProvider aggrProvider = (AggregatedPermissionProvider) pProvider; aggrPermissionProviders.add(aggrProvider); if (aggregationFilter.stop(aggrProvider, principals)) { break; } } else { log.debug("Ignoring permission provider of '{}': Not an AggregatedPermissionProvider", conf.getClass().getName()); } } PermissionProvider pp; switch (aggrPermissionProviders.size()) { case 0 : pp = EmptyPermissionProvider.getInstance(); break; case 1 : pp = aggrPermissionProviders.get(0); break; default : pp = CompositePermissionProvider.create(root, aggrPermissionProviders, getContext(), compositionType, getRootProvider(), getTreeProvider()); } return pp; } } CompositeAuthorizationConfiguration();  CompositeAuthorizationConfiguration(@NotNull SecurityProvider securityProvider); void withCompositionType(@Nullable String ct); void withAggregationFilter(@NotNull AggregationFilter aggregationFilter); @NotNull @Override AccessControlManager getAccessControlManager(@NotNull final Root root,
                                                        @NotNull final NamePathMapper namePathMapper); @NotNull @Override RestrictionProvider getRestrictionProvider(); @NotNull @Override PermissionProvider getPermissionProvider(@NotNull final Root root,
                                                    @NotNull final String workspaceName,
                                                    @NotNull final Set<Principal> principals);  }
@Test(expected = IllegalStateException.class) public void testEmptyGetPermissionProvider() { getCompositeConfiguration().getPermissionProvider(root, adminSession.getWorkspaceName(), Collections.<Principal>emptySet()); }
@Test public void testSingleGetPermissionProvider() { CompositeAuthorizationConfiguration cc = getCompositeConfiguration(createAuthorizationConfigurationImpl()); PermissionProvider pp = cc.getPermissionProvider(root, root.getContentSession().getWorkspaceName(), Collections.<Principal>emptySet()); assertFalse(pp instanceof CompositePermissionProvider); }
@Test public void testMultipleGetPermissionProvider() { CompositeAuthorizationConfiguration cc = getCompositeConfiguration( new OpenAuthorizationConfiguration(), createAuthorizationConfigurationImpl()); PermissionProvider pp = cc.getPermissionProvider(root, root.getContentSession().getWorkspaceName(), Collections.<Principal>emptySet()); assertFalse(pp instanceof CompositePermissionProvider); }
@Test public void testMultipleGetPermissionProvider2() { CompositeAuthorizationConfiguration cc = getCompositeConfiguration( createAuthorizationConfigurationImpl(), createAuthorizationConfigurationImpl()); PermissionProvider pp = cc.getPermissionProvider(root, root.getContentSession().getWorkspaceName(), Collections.<Principal>emptySet()); assertTrue(pp instanceof CompositePermissionProvider); }
@Test public void testMultipleGetPermissionProvider3() { CompositeAuthorizationConfiguration cc = getCompositeConfiguration( new OpenAuthorizationConfiguration(), new OpenAuthorizationConfiguration()); PermissionProvider pp = cc.getPermissionProvider(root, root.getContentSession().getWorkspaceName(), Collections.<Principal>emptySet()); assertFalse(pp instanceof CompositePermissionProvider); assertSame(EmptyPermissionProvider.getInstance(), pp); }
@Test public void testDefaultEvaluationFilter() { PermissionProvider pp = mock(PermissionProvider.class, withSettings().extraInterfaces(AggregatedPermissionProvider.class)); AuthorizationConfiguration ac1 = mock(AuthorizationConfiguration.class); AuthorizationConfiguration ac2 = mock(AuthorizationConfiguration.class); for (AuthorizationConfiguration ac : new AuthorizationConfiguration[] {ac1, ac2}) { when(ac.getPermissionProvider(any(Root.class), anyString(), any(Set.class))).thenReturn(pp); when(ac.getParameters()).thenReturn(ConfigurationParameters.EMPTY); when(ac.getContext()).thenReturn(Context.DEFAULT); } CompositeAuthorizationConfiguration cc = getCompositeConfiguration(ac1, ac2); PermissionProvider permissionProvider = cc.getPermissionProvider(root, adminSession.getWorkspaceName(), ImmutableSet.of(EveryonePrincipal.getInstance())); permissionProvider.refresh(); verify(pp, times(2)).refresh(); }