refresh_token 失败 提示No AuthenticationProvider found

springboot oauth2 refresh_token失败提示

{

    "error": "unauthorized",

    "error_description": "No AuthenticationProvider found for org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken"

}

在spring cloud security 配置文件里添加

WebSecurityConfigurerAdapter里添加如下代码
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userService).passwordEncoder(passwordEncoder());

    //添加refresh_token 时的PreAuthenticatedAuthenticationProvider
   auth.authenticationProvider(preAuthenticatedAuthenticationProvider());
}
/**
 * 构造refresh_token 时的PreAuthenticatedAuthenticationProvider
 * @return
 */
@Bean
public PreAuthenticatedAuthenticationProvider preAuthenticatedAuthenticationProvider(){

  //  log.info("Configuring pre authentication provider");

    UserDetailsByNameServiceWrapper wrapper =
            new UserDetailsByNameServiceWrapper(
                    userService);

    PreAuthenticatedAuthenticationProvider it = new PreAuthenticatedAuthenticationProvider();
    it.setPreAuthenticatedUserDetailsService(wrapper);

    return it;
}

你可能感兴趣的:(spring,java)