CompositePrincipalConfiguration extends CompositeConfiguration<PrincipalConfiguration> implements PrincipalConfiguration { @NotNull @Override public PrincipalProvider getPrincipalProvider(final Root root, final NamePathMapper namePathMapper) { List<PrincipalConfiguration> configurations = getConfigurations(); switch (configurations.size()) { case 0: return EmptyPrincipalProvider.INSTANCE; case 1: return configurations.get(0).getPrincipalProvider(root, namePathMapper); default: List<PrincipalProvider> pps = new ArrayList<>(configurations.size()); for (PrincipalConfiguration principalConfig : configurations) { PrincipalProvider principalProvider = principalConfig.getPrincipalProvider(root, namePathMapper); if (!(principalProvider instanceof EmptyPrincipalProvider)) { pps.add(principalProvider); } } return CompositePrincipalProvider.of(pps); } } CompositePrincipalConfiguration();  CompositePrincipalConfiguration(@NotNull SecurityProvider securityProvider); @NotNull @Override PrincipalManager getPrincipalManager(Root root, NamePathMapper namePathMapper); @NotNull @Override PrincipalProvider getPrincipalProvider(final Root root, final NamePathMapper namePathMapper);  }
@Test public void testEmptyGetProvider() { PrincipalProvider pp = getComposite().getPrincipalProvider(root, NamePathMapper.DEFAULT); assertFalse(pp instanceof CompositePrincipalProvider); assertSame(EmptyPrincipalProvider.INSTANCE, pp); }
@Test public void testSingleGetProvider() { PrincipalConfiguration testConfig = new TestPrincipalConfiguration(); addConfiguration(testConfig); PrincipalProvider pp = getComposite().getPrincipalProvider(root, NamePathMapper.DEFAULT); assertFalse(pp instanceof CompositePrincipalProvider); assertEquals(testConfig.getPrincipalProvider(root, NamePathMapper.DEFAULT).getClass(), pp.getClass()); }
@Test public void testMultipleGetPrincipalProvider() throws Exception { addConfiguration(principalConfigurationMock); addConfiguration(new TestPrincipalConfiguration()); PrincipalProvider pp = getComposite().getPrincipalProvider(root, NamePathMapper.DEFAULT); assertTrue(pp instanceof CompositePrincipalProvider); assertSize(2, (CompositePrincipalProvider) pp); }
@Test public void testWithEmptyPrincipalProvider() throws Exception { addConfiguration(new TestEmptyConfiguration()); PrincipalProvider pp = getComposite().getPrincipalProvider(root, NamePathMapper.DEFAULT); assertSame(EmptyPrincipalProvider.INSTANCE, pp); addConfiguration(new TestPrincipalConfiguration()); pp = getComposite().getPrincipalProvider(root, NamePathMapper.DEFAULT); assertFalse(pp instanceof CompositePrincipalProvider); addConfiguration(principalConfigurationMock); pp = getComposite().getPrincipalProvider(root, NamePathMapper.DEFAULT); assertTrue(pp instanceof CompositePrincipalProvider); assertSize(2, (CompositePrincipalProvider) pp); addConfiguration(new TestEmptyConfiguration()); pp = getComposite().getPrincipalProvider(root, NamePathMapper.DEFAULT); assertTrue(pp instanceof CompositePrincipalProvider); assertSize(2, (CompositePrincipalProvider) pp); }