Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
Spring security 如果身份验证失败,如何为多个相同的登录页面附加相同的参数?_Spring Security - Fatal编程技术网

Spring security 如果身份验证失败,如何为多个相同的登录页面附加相同的参数?

Spring security 如果身份验证失败,如何为多个相同的登录页面附加相同的参数?,spring-security,Spring Security,我在不同的端点上有相同的登录表单:/welcome, /login 如果我设置failureUrl(/welcome?error),如果身份验证失败而不是/login?error,它也会将/login重定向到/welcome?error 我想我需要实现一个failureHandler,但是如何从HttpServletRequest中提取实际的登录端点呢 我想说这样的话: response.sendRedirect(/[actual\u login\u endpoint]?错误)我解决了它。我必须

我在不同的端点上有相同的登录表单:
/welcome
/login

如果我设置failureUrl(
/welcome?error
),如果身份验证失败而不是
/login?error
,它也会将
/login
重定向到
/welcome?error

我想我需要实现一个failureHandler,但是如何从HttpServletRequest中提取实际的登录端点呢

我想说这样的话:

response.sendRedirect(/[actual\u login\u endpoint]?错误)

我解决了它。我必须在登录表单中发送一个隐藏属性。我认为没有更简单的解决办法

@Override
public void onAuthenticationFailure(
        final HttpServletRequest request,
        final HttpServletResponse response,
        final AuthenticationException exception) throws IOException, ServletException {
    if (request.getParameter("loginForm").equals("welcome")) {
        response.sendRedirect("/welcome?error");
    } else if (request.getParameter("loginForm").equals("login")) {
        response.sendRedirect("/login?error");
    }
}