CompositeAuthorizationConfiguration extends CompositeConfiguration<AuthorizationConfiguration> implements AuthorizationConfiguration { @NotNull @Override public RestrictionProvider getRestrictionProvider() { List<AuthorizationConfiguration> configurations = getConfigurations(); switch (configurations.size()) { case 0: return RestrictionProvider.EMPTY; case 1: return configurations.get(0).getRestrictionProvider(); default: Set<RestrictionProvider> rps = new LinkedHashSet<>(configurations.size()); for (AuthorizationConfiguration c : configurations) { RestrictionProvider rp = c.getRestrictionProvider(); if (RestrictionProvider.EMPTY != rp) { rps.add(rp); } } return CompositeRestrictionProvider.newInstance(rps); } } 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 public void testEmptyGetRestrictionProvider() { assertSame(RestrictionProvider.EMPTY, getCompositeConfiguration().getRestrictionProvider()); }
@Test public void testSingleRestrictionProvider() { CompositeAuthorizationConfiguration cc = getCompositeConfiguration(createAuthorizationConfigurationImpl()); RestrictionProvider rp = cc.getRestrictionProvider(); assertFalse(rp instanceof CompositeRestrictionProvider); }
@Test public void testMultipleRestrictionProvider() { AuthorizationConfiguration ac = createAuthorizationConfigurationImpl(); AuthorizationConfiguration ac2 = mock(AuthorizationConfiguration.class); when(ac2.getRestrictionProvider()).thenReturn(mock(RestrictionProvider.class)); when(ac2.getParameters()).thenReturn(ConfigurationParameters.EMPTY); CompositeAuthorizationConfiguration cc = getCompositeConfiguration(ac, ac2); RestrictionProvider rp = cc.getRestrictionProvider(); assertTrue(rp instanceof CompositeRestrictionProvider); }
@Test public void testRedundantRestrictionProvider() { AuthorizationConfiguration ac = createAuthorizationConfigurationImpl(); AuthorizationConfiguration ac2 = mock(AuthorizationConfiguration.class); when(ac2.getRestrictionProvider()).thenReturn(ac.getRestrictionProvider()); when(ac2.getParameters()).thenReturn(ConfigurationParameters.EMPTY); CompositeAuthorizationConfiguration cc = getCompositeConfiguration(ac, ac2); RestrictionProvider rp = cc.getRestrictionProvider(); assertFalse(rp instanceof CompositeRestrictionProvider); assertSame(ac.getRestrictionProvider(), rp); }
@Test public void testMultipleWithEmptyRestrictionProvider() { CompositeAuthorizationConfiguration cc = getCompositeConfiguration( createAuthorizationConfigurationImpl(), new OpenAuthorizationConfiguration() { @NotNull @Override public RestrictionProvider getRestrictionProvider() { return RestrictionProvider.EMPTY; } }); RestrictionProvider rp = cc.getRestrictionProvider(); assertFalse(rp instanceof CompositeRestrictionProvider); assertNotSame(RestrictionProvider.EMPTY, rp); }
@Test public void testOnlyEmptyRestrictionProvider() { AuthorizationConfiguration ac = new OpenAuthorizationConfiguration() { @NotNull @Override public RestrictionProvider getRestrictionProvider() { return RestrictionProvider.EMPTY; } }; CompositeAuthorizationConfiguration cc = getCompositeConfiguration(ac, ac); RestrictionProvider rp = cc.getRestrictionProvider(); assertFalse(rp instanceof CompositeRestrictionProvider); assertSame(RestrictionProvider.EMPTY, rp); }