Mar*_*iel 3 jsf redirect login jaas jsf-2
我正在使用实现与Request.login()登录的Web应用程序。问题是,如果登录失败,则jsf不会重定向到form-error-page。如果我使用传统方法j_security_check,一切正常。是否有某种类型的详细信息与托管Bean登录相同?
ExternalContext externalContext = externalContext();
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
request.login(username, password);
Run Code Online (Sandbox Code Playgroud)
在我的web.xml中
<login-config>
<auth-method>FORM</auth-method>
<realm-name>security_domain</realm-name>
<form-login-config>
<form-login-page>/pages/login.xhtml</form-login-page>
<form-error-page>/pages/loginError.xhtml</form-error-page>
</form-login-config>
</login-config>
Run Code Online (Sandbox Code Playgroud)
当不直接提交到/j_security_checkURL时,<login-config>基本上会被完全忽略,包括<form-error-page>。
自己处理:
try {
request.login(username, password);
} catch (ServletException e) {
externalContext.redirect(externalContext.getRequestContextPath() + "/pages/loginError.xhtml");
}
Run Code Online (Sandbox Code Playgroud)
与具体问题无关,对于UX,实际上最好在表单中仅显示错误消息的情况下留在同一页面上。
try {
request.login(username, password);
} catch (ServletException e) {
facesContext.addMessage(null, new FacesMessage("Unknown login"));
}
Run Code Online (Sandbox Code Playgroud)