Add custom UserDetailsService to Spring Security OAuth2 app

后端 未结 4 1971
囚心锁ツ
囚心锁ツ 2020-12-16 16:57

How do I add the custom UserDetailsService below to this Spring OAuth2 sample?

The default user with default password is def

4条回答
  •  心在旅途
    2020-12-16 17:11

    For anyone got UserDetailsService is required error when doing refresh token, and you confirm you already have UserDetailsService bean.

    try add this:

    @Configuration
    public class GlobalSecurityConfig extends GlobalAuthenticationConfigurerAdapter {
        private UserDetailsService userDetailsService;
    
        public GlobalSecurityConfig(UserDetailsService userDetailsService) {
            this.userDetailsService = userDetailsService;
        }
    
        @Override
        public void init(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(userDetailsService);
        }
    }
    

    This is my try and error, maybe not work for you.

    By the way, if you give up "guess" which bean will pick by spring, you can extends AuthorizationServerConfigurerAdapter and WebSecurityConfigurerAdapter and config all stuff by yourself, but I think it's lose power of spring autoconfig. Why I need config everything if I just need customize some config?

提交回复
热议问题