报错内容
{
"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接口的实现类
文章讲述了在使用SpringSecurity时遇到的授权错误,原因是缺少指定的UserService。通过在配置类中注入实现了UserDetailsService接口的AuthUserDetailsService类,解决了授权问题,确保了认证流程的正常运行。

3431

被折叠的 条评论
为什么被折叠?



