我想使用自定义身份验证提供程序将 spring 安全性(使用 Java 配置)添加到我的应用程序中,但是我无法使其工作。似乎 authenticationProvider 配置不正确,因为我无法调试到方法 authenticate(Authentication) 中,并且 println 不打印任何内容。每个请求都以 403 响应。
请任何人都可以帮助我解决这个问题,整个周末我都对此感到震惊。
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(new AuthenticationProvider(){
@Override
public Authentication authenticate(Authentication arg0) throws AuthenticationException {
System.out.println("authenticating...");
return arg0;
}
@Override
public boolean supports(Class<?> arg0) {
return true;
}
});
}
}