SecurityProviderBuilder { public SecurityProvider build() { InternalSecurityProvider securityProvider = new InternalSecurityProvider(); if (rootProvider == null) { rootProvider = new RootProviderService(); } if (treeProvider == null) { treeProvider = new TreeProviderService(); } if (authenticationConfiguration == null) { authenticationConfiguration = new AuthenticationConfigurationImpl(); } securityProvider.setAuthenticationConfiguration(initializeConfiguration(authenticationConfiguration, securityProvider, authenticationParams, rootProvider, treeProvider)); if (privilegeConfiguration == null) { privilegeConfiguration = new PrivilegeConfigurationImpl(); } securityProvider.setPrivilegeConfiguration(initializeConfiguration(privilegeConfiguration, securityProvider, privilegeParams, rootProvider, treeProvider)); if (userConfiguration == null) { userConfiguration = new UserConfigurationImpl(); } securityProvider.setUserConfiguration( initializeConfiguration(userConfiguration, securityProvider, userParams, rootProvider, treeProvider)); if (authorizationConfiguration == null) { CompositeAuthorizationConfiguration ac = new CompositeAuthorizationConfiguration(); ac.withCompositionType(configuration.getConfigValue("authorizationCompositionType", CompositeAuthorizationConfiguration.CompositionType.AND.toString())); ac.setDefaultConfig(initializeConfiguration(new AuthorizationConfigurationImpl(), securityProvider, rootProvider, treeProvider)); authorizationConfiguration = ac; } if (authorizationConfiguration instanceof CompositeAuthorizationConfiguration) { initializeConfigurations((CompositeAuthorizationConfiguration) authorizationConfiguration, securityProvider, authorizationParams, rootProvider, treeProvider); } else { initializeConfiguration(authorizationConfiguration, securityProvider, authorizationParams, rootProvider, treeProvider); } securityProvider.setAuthorizationConfiguration(authorizationConfiguration); if (principalConfiguration == null) { CompositePrincipalConfiguration pc = new CompositePrincipalConfiguration(); pc.setDefaultConfig(initializeConfiguration(new PrincipalConfigurationImpl(), securityProvider, rootProvider, treeProvider)); principalConfiguration = pc; } if (principalConfiguration instanceof CompositePrincipalConfiguration) { initializeConfigurations((CompositePrincipalConfiguration) principalConfiguration, securityProvider, principalParams, rootProvider, treeProvider); } else { initializeConfiguration(principalConfiguration, securityProvider, principalParams, rootProvider, treeProvider); } securityProvider.setPrincipalConfiguration(principalConfiguration); if (tokenConfiguration == null) { CompositeTokenConfiguration tc = new CompositeTokenConfiguration(); tc.setDefaultConfig(initializeConfiguration(new TokenConfigurationImpl(), securityProvider, rootProvider, treeProvider)); tokenConfiguration = tc; } if (tokenConfiguration instanceof CompositeTokenConfiguration) { initializeConfigurations((CompositeTokenConfiguration) tokenConfiguration, securityProvider, tokenParams, rootProvider, treeProvider); } else { initializeConfiguration(tokenConfiguration, securityProvider, tokenParams, rootProvider, treeProvider); } securityProvider.setTokenConfiguration(tokenConfiguration); if (whiteboard != null) { securityProvider.setWhiteboard(whiteboard); } return securityProvider; } private  SecurityProviderBuilder(); @NotNull static SecurityProviderBuilder newBuilder(); SecurityProviderBuilder with(@NotNull ConfigurationParameters configuration); SecurityProviderBuilder with(@NotNull AuthenticationConfiguration authenticationConfiguration,
            @NotNull ConfigurationParameters authenticationParams,
            @NotNull PrivilegeConfiguration privilegeConfiguration, @NotNull ConfigurationParameters privilegeParams,
            @NotNull UserConfiguration userConfiguration, @NotNull ConfigurationParameters userParams,
            @NotNull AuthorizationConfiguration authorizationConfiguration, @NotNull ConfigurationParameters authorizationParams,
            @NotNull PrincipalConfiguration principalConfiguration, @NotNull ConfigurationParameters principalParams,
            @NotNull TokenConfiguration tokenConfiguration, @NotNull ConfigurationParameters tokenParams); SecurityProvider build(); SecurityProviderBuilder withWhiteboard(@NotNull Whiteboard whiteboard); SecurityProviderBuilder withRootProvider(@NotNull RootProvider rootProvider); SecurityProviderBuilder withTreeProvider(@NotNull TreeProvider treeProvider);  }
@Test public void testDefault() { SecurityProvider sp = builder.build(); assertNotNull(sp.getConfiguration(AuthenticationConfiguration.class)); assertNotNull(sp.getConfiguration(AuthorizationConfiguration.class)); assertNotNull(sp.getConfiguration(PrincipalConfiguration.class)); assertNotNull(sp.getConfiguration(PrivilegeConfiguration.class)); assertNotNull(sp.getConfiguration(TokenConfiguration.class)); assertNotNull(sp.getConfiguration(UserConfiguration.class)); }