AuthenticationProviderConfigurer extends SecurityConfigurerAdapter<Void, ServiceProviderBuilder> { @Override public void configure(ServiceProviderBuilder builder) throws Exception { if (authenticationProviderBean == null) { if (authenticationProvider == null) { authenticationProvider = new SAMLAuthenticationProvider(); authenticationProvider.setExcludeCredential(Optional.ofNullable(excludeCredential). orElseGet(config::isExcludeCredential)); authenticationProvider.setForcePrincipalAsString(Optional.ofNullable(forcePrincipalAsString) .orElseGet(config::isForcePrincipalAsString)); authenticationProvider.setUserDetails(postProcess(Optional.ofNullable(userDetailsService) .orElseGet(SimpleSAMLUserDetailsService::new))); } builder.setSharedObject(SAMLAuthenticationProvider.class, authenticationProvider); } } AuthenticationProviderConfigurer(SAMLAuthenticationProvider provider);  AuthenticationProviderConfigurer(); @Override void init(ServiceProviderBuilder builder); @Override void configure(ServiceProviderBuilder builder); AuthenticationProviderConfigurer excludeCredential(boolean excludeCredential); AuthenticationProviderConfigurer forcePrincipalAsString(boolean forcePrincipalAsString); AuthenticationProviderConfigurer userDetailsService(SAMLUserDetailsService userDetailsService);  }
@Test public void configure() throws Exception { AuthenticationProviderConfigurer configurer = new AuthenticationProviderConfigurer(); configurer.init(builder); configurer.configure(builder); verify(builder).setSharedObject(eq(SAMLAuthenticationProvider.class), any(SAMLAuthenticationProvider.class)); }