Spring oauth2 SimpleRuThenticationFailureHandler失败时两个重定向
出于某种原因,带有oauth2和自定义SimpleLauthenticationFailureHandler的spring在登录失败时重定向两次 它按预期调用,但带有位置头,因此我看到一个额外的重定向Spring oauth2 SimpleRuThenticationFailureHandler失败时两个重定向,spring,spring-security-oauth2,Spring,Spring Security Oauth2,出于某种原因,带有oauth2和自定义SimpleLauthenticationFailureHandler的spring在登录失败时重定向两次 它按预期调用,但带有位置头,因此我看到一个额外的重定向 @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { http.requestMatchers() .antMatchers("/login", "/oauth/
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
http.requestMatchers()
.antMatchers("/login", "/oauth/authorize")
.and()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/" + URLConstants.LOGIN)
.loginProcessingUrl("/" + URLConstants.LOGIN)
//.failureUrl("/login?error")
.failureHandler(authFailureHandler)
.permitAll();
和SimpleRuthenticationFailureHandler
@Component
public class AuthFailureHandler extends
SimpleUrlAuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
// some code
saveException(request, exception);
getRedirectStrategy().sendRedirect(request, response, "/login?error");
上面的onAuthenticationFailure代码调用的方法与onAuthenticationFailure中的原始代码几乎相同。我也试过了
super.onAuthenticationFailure(请求、响应、异常);
但我确实得到了相同的结果(额外的重定向)
如果我删除.failureHandler(authFailureHandler),那么代码将按预期工作。有什么想法吗
见附图片
额外重定向-使用SimpleRuthenticationFailureHandler
如预期-没有SimpleRuthenticationFailureHandler