spring-boot: AuthenticationManager bean is missing when upgraded to Spring Boot 2.0.0.M6
Today I have upgraded one of my sample from Spring Boot 2.0.0.M4 to 2.0.0.M6.
https://github.com/hantsy/spring-microservice-sample
When starting up auth-service, it complains AuthentionManager bean is not existed in my AuthenticationController, I have to expose it manually in my security config.
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
Is there something changed in Spring Boot 2.0.0.M6?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (4 by maintainers)
AuthenticationManagerbean is required forpasswordgrant type in Spring Security OAuth2. The whole design ofAuthorizationServerConfigurer+ResourceServerConfigurerassumes that you never useWebSecurityConfigurerAdapterin oauth2-based app. However now the only way to get theAuthenticationManagerseems to be this:This is really confusing, because now, along with
ResourceServerConfigurer, you have two beans exposingconfigure(HttpSecurity http). Which one should I use, then? They are not compatible.This is the most obscure thing I’ve met so far in Spring Security OAuth2 and this is purely caused by not exposing
AuthenticationManagerautomatically.@l0co Yes,
AuthenticationManageris required for thepasswordgrant type in Spring Security OAuth2. It’s required as a constructor arg inResourceOwnerPasswordTokenGranter.This is not correct. You still need to configure your user’s either by providing an
AuthenticationManagerORAuthenticationProviderOR configuring viaAuthenticationManagerBuilder. This needs to happen in yourWebSecurityConfigurerAdapter. Spring Security OAuth2 simply uses theAuthenticationManagerthat is configured by yourWebSecurityConfigurerAdapter.Yes, you do need to expose the
AuthenticationManageras a@Beanvia theauthenticationManagerBean()override. However, I don’t see this being an overhead. It’s one simple override.I think you meant to say
AuthorizationServerConfigurerinstead ofResourceServerConfigurer? TheAuthorizationServerConfigurerneeds to be wired with theAuthenticationManagerin order to validate the user during thepasswordgrant flow. An example configuration would be:@l0co Does this clarify things?
@jgrandja Thanks for the clarification. It does clarify things, however I still think the design would be better if you didn’t have to create your own
AuthenticationManagerand have this bean ready to be used in the container.@wilkinsona I checked my initial workable version( built with Spring Boot 2.0.0.M2), it worked without exposing
AuthenticationManager.To my knowledge, nothing’s changed in this area between 2.0 M4 and 2.0 M6.
The auto-configured
AuthenticationManagerbean is backing off because of yourAuthUserDetailsService. This happens because Boot’sAuthenticationMangerConfigurationis conditional on missingAuthenticationManager,AuthenticationProvider, andUserDetailsServicebeans.If I modify your sample to be compatible with Boot 2.0 M4, it has the same failure at startup. You can use the condition evaluation report to diagnose this sort of problem (start with
--debug). It shows the auto-configured authentication manager backing off:I have the same problem as you,according to the document ,it looks like build a global AuthenticationManager, it will apply for all SecurityFilterChain. i don’t know how to get local AuthenticationManager in my service