gro*_*rei 5 jsf login j-security-check
我有一个Web应用程序,我希望主页包含一个登录表单,以及其他数据.如果用户选择登录,则应将其重定向到另一个页面(例如login_success.jsp).我的问题是:我可以使用j_security_check机制登录,或者唯一的方法是使用托管bean来处理登录?
我的主页看起来像这样:
....
<form action="j_security_check" method="POST" name="loginForm">
<h:panelGrid columns="2">
<h:outputLabel id="userNameLabel" for="j_username" value="#{label.home_username}:" />
<h:inputText id="j_username" autocomplete="off" />
<h:outputLabel id="passwordLabel" for="j_password" value="#{label.home_password}:" />
<h:inputSecret id="j_password" autocomplete="off" />
<h:panelGroup>
<h:commandButton type="submit" value="Login" />
<h:commandButton type="reset" value="Clear" />
</h:panelGroup>
</h:panelGrid>
</form>
...
Run Code Online (Sandbox Code Playgroud)
如果我按下登录按钮,我得到 - > HTTP状态400 - 对表单登录页面的无效直接引用.很明显,j_security_check机制不知道在哪里"重定向",因为我以前没有请求过受保护的资源.
HTTP状态400 - 对表单登录页面的无效直接引用.
这意味着您<form-login-page>在不允许的情况下通过直接请求手动打开.
很明显,j_security_check机制不知道在哪里"重定向",因为我以前没有请求过受保护的资源.
这不是错误试图告诉你的.
将登录页面放在/WEB-INF文件夹中以防止可能的直接访问.然后,要触发登录,只需直接请求受限资源.如有必要,容器将自动显示登录页面.
或者,如果您没有仅受限制的资源(即登录只显示更多选项/功能,如在讨论论坛中),那么请不要使用a <form-login-page>,而是使用带有支持bean的JSF表单HttpServletRequest#login().