Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 自定义AuthenticationFailureHandler未按预期工作_Java_Spring_Spring Mvc_Spring Boot_Spring Security - Fatal编程技术网

Java 自定义AuthenticationFailureHandler未按预期工作

Java 自定义AuthenticationFailureHandler未按预期工作,java,spring,spring-mvc,spring-boot,spring-security,Java,Spring,Spring Mvc,Spring Boot,Spring Security,安全配置中已注册的处理程序: .formLogin().loginPage(/login).failureHandler(新的CustomAuthenticationFailureHandler()) 我的自定义失败处理程序: 公共类CustomAuthenticationFailureHandler实现AuthenticationFailureHandler{ 私有字符串failureUrl=“/login?error”; private RedirectStrategy RedirectS

安全配置中已注册的处理程序:

.formLogin().loginPage(/login).failureHandler(新的CustomAuthenticationFailureHandler())
我的自定义失败处理程序:

公共类CustomAuthenticationFailureHandler实现AuthenticationFailureHandler{
私有字符串failureUrl=“/login?error”;
private RedirectStrategy RedirectStrategy=新的DefaultRedirectStrategy();
@凌驾
验证失败(HttpServletRequest请求、HttpServletResponse响应、,
AuthenticationException(异常)引发IOException、ServletException{
this.redirectStrategy.sendRedirect(请求、响应、this.failureUrl);
}
}
onAuthenticationFailure
在发生身份验证失败时被触发,但随着Spring触发了另一个请求,请查找另一个req堆栈

LoginUrlAuthenticationEntryPoint.start(HttpServletRequest、HttpServletResponse、AuthenticationException)行:169
ExceptionTranslationFilter.sendStartAuthentication(HttpServletRequest、HttpServletResponse、FilterChain、AuthenticationException)行:204
ExceptionTranslationFilter.handleSpringSecurityException(HttpServletRequest、HttpServletResponse、FilterChain、RuntimeException)行:178
因此,此请求将覆盖我的sendredirect请求

我是否需要配置/执行任何其他操作来实现这一点?请帮忙。 提前谢谢

我的配置:

@覆盖
受保护的无效配置(HttpSecurity http)引发异常{
http
.addFilterBefore(SignUpFilter(userService),UsernamePasswordAuthenticationFilter.class)
.授权请求()
蚂蚁配对者(
"/",
“/注册”,
“/retrieveUsernameForm”,
.permitAll()
.及()
.anonymous()
.authenticationProvider(匿名authenticationProvider())
.authenticationFilter(匿名authenticationFilter())
.及()
.formLogin()
.loginPage(SecurityController.URI\u登录)
.failureHandler(新的CustomAuthenticationFailureHandler())
.permitAll()
.defaultSuccessUrl(securityController.createUri(securityController.PATH\u PART\u LOGIN))
.及()
.rememberMe()
.rememberMeParameter(“记住我”)
.key(记住令牌密钥)
.RememberServices(TokenBasedMemberMeservices())
.及()
.logout()
.permitAll()
.及()
.headers()
.frameOptions().disable()
.addHeaderWriter(新的StaticHeaderWriter(“X-Frame-Options”、“SAMEORIGIN”))
.及()
.csrf().disable();
http.formLogin()
.addObjectPostProcessor(新的ObjectPostProcessor(){
@凌驾
公共UsernamePasswordAuthenticationFilter后处理(UsernamePasswordAuthenticationFilter筛选器){
filter.setSessionAuthenticationStrategy(sessionAuthenticationStrategyForContentAndStoreUsers());
回流过滤器;
}
});
http.exceptionHandling().accessDeniedHandler(accessDeniedHandler);
}

“localhost:8080/test/login”如果在处理程序中处理了错误,我将追加/login?错误,正如我在正文中提到的,第二个请求将被覆盖,url将变成localhost:8080/test/login。因此我无法在我的controller.SecurityController.URI\u login=“/login”(包含上下文+登录)和SecurityController.PATH\u PART\u LO‌​GIN是“/login”,您必须允许访问失败的URL。将
login
添加到
.antMatchers(“/”、“/register”、“/retrieveUsernameForm”
。现在可以了。非常感谢。如果我们在.antMatchers(“)中提到任何uri,请告诉我这个spring不会干扰?在这个流中,如果/login url中发生任何故障,我必须通过我的处理程序执行该流?很高兴帮助您,但我不理解您在评论中提出的问题。您能重新表述一下吗?“localhost:8080/test/login”如果在处理程序中处理了错误,我将添加/login?error,正如我在正文中提到的,第二个请求将被覆盖,url将变成localhost:8080/test/login。因此,我无法在controller.SecurityController.URI\u login=“/login”(包含上下文+登录)和SecurityController.PATH\u PART\u LO中捕捉错误场景‌​GIN是“/login”,您必须允许访问失败的URL。将
login
添加到
.antMatchers(“/”、“/register”、“/retrieveUsernameForm”
。现在可以了。非常感谢。如果我们在.antMatchers(“)中提到任何uri,请告诉我spring不会干扰?在这个流程中,如果/login url中发生任何故障,我必须通过我的处理程序执行该流程?很高兴帮助您,但我不理解您评论中的问题。您能重新措辞吗?