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)
AuthenticationManager
bean is required forpassword
grant type in Spring Security OAuth2. The whole design ofAuthorizationServerConfigurer
+ResourceServerConfigurer
assumes that you never useWebSecurityConfigurerAdapter
in oauth2-based app. However now the only way to get theAuthenticationManager
seems 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
AuthenticationManager
automatically.@l0co Yes,
AuthenticationManager
is required for thepassword
grant 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
AuthenticationManager
ORAuthenticationProvider
OR configuring viaAuthenticationManagerBuilder
. This needs to happen in yourWebSecurityConfigurerAdapter
. Spring Security OAuth2 simply uses theAuthenticationManager
that is configured by yourWebSecurityConfigurerAdapter
.Yes, you do need to expose the
AuthenticationManager
as a@Bean
via theauthenticationManagerBean()
override. However, I don’t see this being an overhead. It’s one simple override.I think you meant to say
AuthorizationServerConfigurer
instead ofResourceServerConfigurer
? TheAuthorizationServerConfigurer
needs to be wired with theAuthenticationManager
in order to validate the user during thepassword
grant 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
AuthenticationManager
and 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
AuthenticationManager
bean is backing off because of yourAuthUserDetailsService
. This happens because Boot’sAuthenticationMangerConfiguration
is conditional on missingAuthenticationManager
,AuthenticationProvider
, andUserDetailsService
beans.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