PrincipalConfigurationImpl extends ConfigurationBase implements PrincipalConfiguration { @NotNull @Override public PrincipalProvider getPrincipalProvider(Root root, NamePathMapper namePathMapper) { UserConfiguration uc = getSecurityProvider().getConfiguration(UserConfiguration.class); PrincipalProvider principalProvider = uc.getUserPrincipalProvider(root, namePathMapper); if (principalProvider != null) { return principalProvider; } else { return new PrincipalProviderImpl(root, uc, namePathMapper); } } @SuppressWarnings("UnusedDeclaration")  PrincipalConfigurationImpl();  PrincipalConfigurationImpl(SecurityProvider securityProvider); @NotNull @Override PrincipalManager getPrincipalManager(Root root, NamePathMapper namePathMapper); @NotNull @Override PrincipalProvider getPrincipalProvider(Root root, NamePathMapper namePathMapper); @NotNull @Override String getName();  }
@Test(expected = IllegalStateException.class) public void testGetPrincipalProvider() { pc1.getPrincipalProvider(root, NamePathMapper.DEFAULT); }
@Test public void testGetPrincipalProvider2() { pc1.setSecurityProvider(getSecurityProvider()); PrincipalProvider pp = pc1.getPrincipalProvider(root, NamePathMapper.DEFAULT); assertNotNull(pp); assertEquals(getUserConfiguration().getUserPrincipalProvider(root, NamePathMapper.DEFAULT).getClass(), pp.getClass()); }
@Test public void testGetPrincipalProvider3() { PrincipalProvider pp = pc2.getPrincipalProvider(root, NamePathMapper.DEFAULT); assertNotNull(pp); assertEquals(getUserConfiguration().getUserPrincipalProvider(root, NamePathMapper.DEFAULT).getClass(), pp.getClass()); }
@Test public void testGetPrincipalProvider4() { PrincipalConfigurationImpl pc3 = new PrincipalConfigurationImpl(); final SecurityProvider sp = new SecurityProvider() { @NotNull @Override public ConfigurationParameters getParameters(@Nullable String name) { return ConfigurationParameters.EMPTY; } @NotNull @Override public Iterable<? extends SecurityConfiguration> getConfigurations() { return ImmutableList.of(); } @NotNull @Override public <T> T getConfiguration(@NotNull Class<T> configClass) { if (configClass.equals(UserConfiguration.class)) { return (T) new UserConfigurationImpl(this) { @Nullable @Override public PrincipalProvider getUserPrincipalProvider(@NotNull Root root, @NotNull NamePathMapper namePathMapper) { return null; } }; } else { throw new IllegalArgumentException(); } } }; pc3.setSecurityProvider(sp); PrincipalProvider pp = pc3.getPrincipalProvider(root, NamePathMapper.DEFAULT); assertTrue(pp instanceof PrincipalProviderImpl); }
@Test public void testGetPrincipalProvider5() { PrincipalProvider pp = EmptyPrincipalProvider.INSTANCE; PrincipalConfigurationImpl pc = new PrincipalConfigurationImpl() { @NotNull @Override public PrincipalProvider getPrincipalProvider(Root root, NamePathMapper namePathMapper) { return pp; } }; ConfigurationParameters params = ConfigurationParameters.EMPTY; pc.setParameters(params); SecurityProvider securityProvider = SecurityProviderBuilder.newBuilder().with(params).build(); CompositeConfiguration<PrincipalConfiguration> composite = (CompositeConfiguration) securityProvider .getConfiguration(PrincipalConfiguration.class); PrincipalConfiguration defConfig = composite.getDefaultConfig(); pc.setSecurityProvider(securityProvider); pc.setRootProvider(((ConfigurationBase) defConfig).getRootProvider()); pc.setTreeProvider(((ConfigurationBase) defConfig).getTreeProvider()); composite.addConfiguration(pc); composite.addConfiguration(defConfig); PrincipalProvider ppt = pc.getPrincipalProvider(root, NamePathMapper.DEFAULT); assertEquals(pp, ppt); }