【发布时间】: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 标头中提供的页面,这绕过了它。