我在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
方法{{1}方法。
我尝试添加GET
和attribute
,但无法获得我想要的内容。
答案 0 :(得分:0)
没有!!!你不能没有黑客的重定向。供参考,你可以看看 https://softwareengineering.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect