我正在尝试在登录后实现重定向,这意味着我不能再使用glassfish内置的表单身份验证设置来自动处理这些事情.首先,我需要在请求受保护页面时控制重定向到登录页面.据我了解,这是通过过滤器完成的.这种方法可以与web-xml中的安全约束相结合吗?实际上,我的过滤器根本没有被调用,因为glassfish只是接管并向用户抛出一个基本的登录框,并且即使没有设置登录配置也会忽略所有过滤器.基本上,在glassfish中配置安全性约束时,我没有设法在用户登录之前调用过滤器.
我是否真的需要在过滤器中手动接管安全性才能使其正常工作?如果是这样的话,实施似乎很糟糕.
使用带有JSF 2的glassfish 3.1和使用request.login手动登录的自定义登录页面.
web.xml中.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value><!--Production-->Development</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>de.odysseus.el.ExpressionFactoryImpl</param-value>
</context-param>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.xdin.competence.jsf.util.LoginFilter</filter-class>
</filter>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
<!--<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/viewExpired.jsf</location>
</error-page>-->
<security-constraint>
<display-name>ManagerArea</display-name>
<web-resource-collection>
<web-resource-name>ManagerArea</web-resource-name>
<description/>
<url-pattern>/manager/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>Manager-role</role-name>
<role-name>Admin-role</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<display-name>EmployeeArea</display-name>
<web-resource-collection>
<web-resource-name>EmployeeConstraint</web-resource-name>
<description/>
<url-pattern>/user/Overview.jsf</url-pattern>
<url-pattern>/user/PrepareReport.jsf</url-pattern>
<url-pattern>/user/Search.jsf</url-pattern>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>Employee-role</role-name>
<role-name>Admin-role</role-name>
<role-name>Manager-role</role-name>
<role-name>OKIF-role</role-name> …Run Code Online (Sandbox Code Playgroud) 我正在尝试 - 使用JSF 2.0 - 以一种巧妙的方式实现登录/记住我/注销管理.由于传统<form action="j_security_check" ...方式缺乏灵活性,我决定采用不同的路径,但我发现了一个问题.
声明性安全正确地通过设置无论是在应用服务器<security-domain>和在web.xml中通过<security-constraint>,<login-config>和<form-login-page>.
登录页面:
<h:form id="loginForm">
<h:panelGrid columns="2" cellspacing="5">
<h:outputText value="Username" />
<h:inputText value="#{loginBean.username}" />
<h:outputText value="Password:" />
<h:inputText value="#{loginBean.password}" />
<h:outputLabel value=""/>
<h:commandButton value="Login" action="#{loginBean.login}" />
</h:panelGrid>
</h:form>
Run Code Online (Sandbox Code Playgroud)
简单的LoginBean#login():
public String login( )
{
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance( ).getExternalContext( ).getRequest( );
try {
request.login( username, password );
}
catch ( ServletException e ) {
FacesContext.getCurrentInstance().addMessage( "Unknown login...
return null;
}
return "i_dont_know_where_you_were_going";
} …Run Code Online (Sandbox Code Playgroud) 在使用Moharra JSF 2的JBoss AS 7.1.1上,使用inputText元素创建的XHTML文件不会呈现该属性required="true".
没有错误,但输出HTML不包含必需的属性.如果编写纯HTML输入元素,则必需属性将呈现为JSF表单的一部分.任何人都知道为什么这个属性会被删除?该案例是一个容器管理的登录表单,因此没有支持bean.提前谢谢了.
我们有一个基于JSF(2.0)的Web应用程序,在JBoss 6.1上运行.我们正在使用基于FORM的身份验证与JAAS.
一些用户将"admin/editUser.jsf"这样的链接添加到他们的书签中.如果用户直接访问此页面(不使用应用程序中的导航),则此页面无法正常工作.
问题是:有没有办法在登录后将用户重定向到index.jsf页面,独立于请求的URL?
我已经开发了一个简单的登录表单,可以在我的JSF + PrimeFaces页面中使用:
<form action="j_security_check" method="post">
<p:dialog modal="true" header="Login" widgetVar="loginDlg">
<h:panelGrid columns="3" cellpadding="5">
<h:outputLabel for="j_username">Username:</h:outputLabel>
<h:inputText id="j_username" required="true" />
<h:message for="j_username" />
<h:outputLabel for="j_password">Password:</h:outputLabel>
<h:inputSecret id="j_password" required="true" />
<h:message for="j_password" />
<br />
<h:commandButton value="Login" />
</h:panelGrid>
</p:dialog>
</form>
Run Code Online (Sandbox Code Playgroud)
尝试使用空密码,但缺少的密码(必需)不会被h:message组件捕获.我也转而p:commandButton认为问题可能出在按钮的Ajax行为中,但页面没有呈现,因为PrimeFaces抱怨CommandButton不在表单元素中.容器抛出的异常是:
com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Access denied on empty password for user pippo
Run Code Online (Sandbox Code Playgroud)
总结一下,我有两个问题: