报错内容
{
"error": "unauthorized",
"error_description": "No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken"
}
原因:没有指定userService类
错误地方:
@EnableWebSecurity
public class AuthWebServiceSecurityConfig extends WebSecurityConfigurerAdapter {
/**
* 对请求进行鉴权的配置
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
//.antMatchers().permitAll()
.anyRequest().authenticated()
.and()
// 暂时关闭CSRF校验,允许get请求登出
.csrf().disable();
}
}
修改:
@EnableWebSecurity
public class AuthWebServiceSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthUserDetailsService authUserDetailsService;
/**
* 对请求进行鉴权的配置
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
http.userDetailsService(authUserDetailsService);
http.authorizeRequests()
//.antMatchers().permitAll()
.anyRequest().authenticated()
.and()
// 暂时关闭CSRF校验,允许get请求登出
.csrf().disable();
}
}
其中 AuthUserDetailsService 为实现了UserDetailsService接口的实现类