【发布时间】:2015-10-18 11:40:55
【问题描述】:
我在我的 Spring 应用中编写了一个自定义 Failure Handler
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler{
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {
DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
request.setAttribute("X-Http-Method-Override", "POST");
response.setHeader("X-Http-Method-Override", "POST");
redirectStrategy.sendRedirect(request, response, "/login");
}
}
我想做的是:如果登录失败,我想redirect 到另一个页面/login,但使用POST 方法而不是GET 方法。
我尝试添加attribute 和setHeader,但无法得到我想要的。
【问题讨论】:
标签: java spring spring-mvc spring-security