diff --git a/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java index 35942589079..40197dcd24f 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java @@ -26,6 +26,7 @@ import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.core.log.LogMessage; +import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.authentication.password.CompromisedPasswordChecker; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; @@ -69,11 +70,18 @@ public void configure(AuthenticationManagerBuilder auth) throws Exception { List> userDetailsServices = getBeansWithName(UserDetailsService.class); if (auth.isConfigured()) { if (!userDetailsServices.isEmpty()) { - this.logger.warn("Global AuthenticationManager configured with an AuthenticationProvider bean. " - + "UserDetailsService beans will not be used for username/password login. " - + "Consider removing the AuthenticationProvider bean. " - + "Alternatively, consider using the UserDetailsService in a manually instantiated " - + "DaoAuthenticationProvider."); + List> userDetailsAuthenticationProviders = getBeansWithName( + AbstractUserDetailsAuthenticationProvider.class); + boolean wired = (userDetailsAuthenticationProviders.size() == userDetailsServices.size()); + // we should check every UserDetailsService is actually wired + // but getUserDetailsService() is not exposed + if (!wired) { + this.logger.warn("Global AuthenticationManager configured with an AuthenticationProvider bean. " + + "UserDetailsService beans will not be used for username/password login. " + + "Consider removing the AuthenticationProvider bean. " + + "Alternatively, consider using the UserDetailsService in a manually instantiated " + + "DaoAuthenticationProvider."); + } } return; }