Eclipse 基于JSF表单的身份验证&x2B;托管Bean登录不工作

Eclipse 基于JSF表单的身份验证&x2B;托管Bean登录不工作,eclipse,tomcat,authentication,jsf-2,managed-bean,Eclipse,Tomcat,Authentication,Jsf 2,Managed Bean,我想实现一个托管Bean表单基身份验证,如下所示 我需要配置和构建所有必需的元素,比如登录表单、错误页面、web.xml安全配置和Tomcat安全域(JDBC) 问题出在哪里?应该在托管Bean中调用login()方法的commandButton不工作,我可以看到构造函数和getter被调用,但login方法和setter没有 奇怪的是什么?如果我从web.xml中删除所有与安全相关的元素,重新启动应用程序并直接转到login.xhtml表单,login()方法确实会被调用 结论?如果使用托管b

我想实现一个托管Bean表单基身份验证,如下所示 我需要配置和构建所有必需的元素,比如登录表单、错误页面、web.xml安全配置和Tomcat安全域(JDBC)

问题出在哪里?应该在托管Bean中调用login()方法的commandButton不工作,我可以看到构造函数和getter被调用,但login方法和setter没有

奇怪的是什么?如果我从web.xml中删除所有与安全相关的元素,重新启动应用程序并直接转到login.xhtml表单,login()方法确实会被调用

结论?如果使用托管bean,JSF实现中一定有某种东西阻止了这种基于表单的身份验证正常工作

注意:常规的基于表单的j_安全检查身份验证(不使用JSF)工作正常

有什么想法吗?

login.xhtml web.xml

FormBasedManagedBeanAuth
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
/面孔/*
状态保存方法:“客户端”或“服务器”(=默认值)。参见JSF规范2.5.2
javax.faces.STATE_保存方法
客户
javax.servlet.jsp.jstl.fmt.localizationContext
资源.应用
com.sun.faces.config.ConfigureListener
javax.faces.PROJECT_阶段
发展
faces/index.xhtml
Tomcat7FormBasedJAAS
安全的
/*
用户
形式
/faces/login.xhtml
/faces/error.xhtml
用户
xml(tomcat,片段)
无论如何,我都不是这方面的专家,遇到这个问题也是因为我有同样的问题。我最后做的是在web.xml中有一个安全区域和一个非安全区域,就像这样

<security-constraint>
    <web-resource-collection>
        <web-resource-name>SecureArea</web-resource-name>
        <url-pattern>/secure/*</url-pattern>
    </web-resource-collection>

安全区
/稳妥/*
因此,我有下面的URL进行登录 /WAR/login.xhtml 对于我应用程序的其余部分 /战争/安全/*

这样就可以执行loginBean。
工作得很有魅力。我不确定是否有更好的方法,但这对我很有效。

您的login.xhtml是安全区域,因此未经授权的用户不能访问任何bean

你可以按照你自己的回答继续,或者你可以定义一个“公共”区域, 让其他一切安全:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Public Area</web-resource-name>
        <description>Public Area</description>
        <url-pattern>/public/*</url-pattern>
    </web-resource-collection>
</security-constraint>

公众区
公众区
/公开的/*
现在将login.xhtml移动到public/login.xhtml,并更正web.xml中的登录配置:

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>ALMGCCAdminDB</realm-name>
    <form-login-config>
        <form-login-page>/public/login.xhtml</form-login-page>
        <form-error-page>/public/error.xhtml</form-error-page>
    </form-login-config>
</login-config>

形式
ALMGCCAdminDB
/public/login.xhtml
/public/error.xhtml
<Realm className="org.apache.catalina.realm.JDBCRealm"
    connectionName="database"
    connectionPassword="password"
    connectionURL="jdbc:mysql://localhost:3306/database"
    driverName="com.mysql.jdbc.Driver"
    roleNameCol="roleName"
    userCredCol="password"
    userNameCol="userName"
    userRoleTable="user_role"
    userTable="user"/>
<security-constraint>
    <web-resource-collection>
        <web-resource-name>SecureArea</web-resource-name>
        <url-pattern>/secure/*</url-pattern>
    </web-resource-collection>
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Public Area</web-resource-name>
        <description>Public Area</description>
        <url-pattern>/public/*</url-pattern>
    </web-resource-collection>
</security-constraint>
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>ALMGCCAdminDB</realm-name>
    <form-login-config>
        <form-login-page>/public/login.xhtml</form-login-page>
        <form-error-page>/public/error.xhtml</form-error-page>
    </form-login-config>
</login-config>