【问题标题】:Bad redirect on j_security_check form based authentication基于 j_security_check 表单的身份验证重定向错误
【发布时间】:2018-10-01 04:06:02
【问题描述】:

在用户输入错误的用户名/密码后,我通过重定向到错误页面来处理这个问题。在我的情况下,错误页面与登录相同,但我传递了参数 wrongCredentials,因此我可以在我的 jsf 页面中呈现显示错误用户名/密码消息的特殊块。 如果用户现在输入正确的凭据而不是被重定向到源页面,他会被重定向到 */j_security_check 并使用 GET 并得到 404 未找到。

我发现有趣的是,当输入错误的凭据时,浏览器中的 url 不会更改为 */login.xhtml?wrongCredentials=true 而是更改为 */j_security_check 但呈现的页面登录时会显示有关错误的正确错误消息凭据。

这是我的 web.xml

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.xhtml</form-login-page>
        <form-error-page>/login.xhtml?wrongCredentials=true</form-error-page>
    </form-login-config>
</login-config>

这里也是登录页面表单:

<form id="login_form" name="login_form" action="j_security_check" method="post">
                                <table>
                                    <tbody>
                                    <tr>
                                        <td><input type="text" id="username" name="j_username" placeholder="Username"/></td>
                                    </tr>
                                    <tr>
                                        <td><input type="password" id="password" name="j_password" placeholder="Password"/></td>
                                    </tr>
                                    <tr>
                                        <td><input type="submit" value="login" class="btnBlue"/></td>
                                    </tr>
                                    </tbody>
                                </table>
                                <p:panel rendered="${param['wrongCredentials'] != null}" styleClass="wrongPasswordPanel">
                                    <h:outputText value="Wrong username or password" styleClass="wrongPasswordTxt"/>
                                </p:panel>
                                <p:panel styleClass="forgotPasswordPanel">
                                    <h:outputText value="Forgot password? Please, contact " styleClass="wrongPasswordTxt"/><a href="mailto:support@support.com" class="wrongPasswordTxt">support@support.com</a>
                                </p:panel>

我试图实现一个自定义过滤器来拦截 */j_security_check GET 请求,但过滤器是在 j_security_check 之后加载的。

我正在运行 WildFly10。

【问题讨论】:

  • 您找到解决方案了吗?
  • @André 是的,我找到了解决问题的解决方法,但没有解决问题的根源。我添加了自定义 Servlet 过滤器,用于检查是否存在 HTTP 标头条目 Referer。如果它存在并且设置为 j_security_check 我会用主页的 url 覆盖它。这在使用 jsecurity 成功登录后重定向的技巧总是重定向到 Referer 标头中提供的页面,这绕过了它。

标签: jsp jsf web


【解决方案1】:

在我的情况下,我遇到了严重的重定向错误,因为我正在 https://localhost:8181/... 中测试我的应用程序,并且服务器尝试重定向到 https://0.0.0.0.0.0.0.1:8181/... 这应该是相当于 127.0.0.1 的 IPv6 (查看“位置”http 响应标头)。

浏览器无法理解该 IP 并引发错误。

我所做的解决方法是使用我的实际主机名而不是“localhost”进行测试,例如https://myhostname:8181/... 在这种情况下,服务器将主机名保留在位置标头中,而不是将其转换为 IPv6。

【讨论】:

    猜你喜欢
    • 2014-08-18
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    相关资源
    最近更新 更多