Java 无重定向的Spring安全性
我有一个Spring安全实现,它是无状态的,使用基于令牌的身份验证。我的大部分逻辑都存在于扩展AbstractAuthenticationProcessingFilter的类中。我的问题是,身份验证成功后,AbstractAuthenticationProcessingFilter执行302重定向,这是我不希望看到的。我只想完成最初的请求。如何解决这个问题?我能够通过重写成功和失败处理程序,使spring security公开的“login”rest方法返回“200OK”,而不是“302重定向”。 下面的代码显示了如何实现相同的功能Java 无重定向的Spring安全性,java,spring,spring-security,Java,Spring,Spring Security,我有一个Spring安全实现,它是无状态的,使用基于令牌的身份验证。我的大部分逻辑都存在于扩展AbstractAuthenticationProcessingFilter的类中。我的问题是,身份验证成功后,AbstractAuthenticationProcessingFilter执行302重定向,这是我不希望看到的。我只想完成最初的请求。如何解决这个问题?我能够通过重写成功和失败处理程序,使spring security公开的“login”rest方法返回“200OK”,而不是“302重定向”
//configure http by using the successHandler
//and failure handler methods
http.
formLogin()
.loginPage("/authentication/login")
.loginProcessingUrl("/authentication/processLogin")
.successHandler(successHandler())
.failureHandler(failureHandler())
.and()
......
private AuthenticationFailureHandler failureHandler() {
return new SimpleUrlAuthenticationFailureHandler() {
public void onAuthenticationFailure(HttpServletRequest request,
HttpServletResponse response, AuthenticationException exception)
throws IOException, ServletException {
response.setContentType("text/html;charset=UTF-8");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication Failed. Wrong username or password or both");
}
};
}
private AuthenticationSuccessHandler successHandler() {
return new SimpleUrlAuthenticationSuccessHandler() {
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession(false);
session.setMaxInactiveInterval(60*180);
response.getWriter().println("LoginSuccessful");
}
};
}