JAAS+JSF2.0+Glassfish

JAAS+JSF2.0+Glassfish,jsf,authentication,login,glassfish,jaas,Jsf,Authentication,Login,Glassfish,Jaas,我不知道如何整合这三者 我有一个简单的jsf登录页面,我还创建了JDBCRealm。 我有一个简单的数据访问层,它使用jdbc连接到数据库。 我限制了对登录以外的其他页面的访问,这很好 <login-config> <auth-method>FORM</auth-method> <realm-name>JDBCRealm</realm-name> <form-login-config> <form-lo

我不知道如何整合这三者

我有一个简单的jsf登录页面,我还创建了JDBCRealm。 我有一个简单的数据访问层,它使用jdbc连接到数据库。 我限制了对登录以外的其他页面的访问,这很好

  <login-config>
<auth-method>FORM</auth-method>
<realm-name>JDBCRealm</realm-name>
 <form-login-config> 
    <form-login-page>/index.jsf</form-login-page> 
    <form-error-page>/xxx.jsf</form-error-page> 
</form-login-config> 
</login-config>

 <security-constraint>
<web-resource-collection>
    <web-resource-name>Secure Pages</web-resource-name>
    <url-pattern>/*</url-pattern>
    <http-method>GET</http-method>
    <http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
    <role-name>Users</role-name>
</auth-constraint>
</security-constraint>
我应该怎么做才能真正让它工作,因为我找不到合适的解决方案: 是这样吗? -我需要在登录页面下验证我的bean中的密码和登录是否正确吗?或者它是由glassfish在这个JDBC领域自动完成的?如果是,如何在那里启用/转发


提前感谢

在与之相关联的页面中,您需要创建一个表单,该表单至少与URL j_安全检查和输入字段名j_用户名和j_密码类似:


在与相关联的页面中,您需要创建一个表单,该表单至少与URL j_安全检查和输入字段名j_用户名和j_密码类似:

登录页面的代码: 登录表单

登录页面的代码: 登录表单


不幸的是,我得到404,请求的资源不可用。。在地址栏中,我有:http://remoteaddress:8080/PresentationL/j_security_checkI很抱歉,它完全有效-我只是忘记了有不正确的密码站点xxx.jsf-这就是为什么我得到404。。。谢谢不幸的是,我得到404,请求的资源不可用。。在地址栏中,我有:http://remoteaddress:8080/PresentationL/j_security_checkI很抱歉,它完全有效-我只是忘记了有不正确的密码站点xxx.jsf-这就是为什么我得到404。。。非常感谢。
<form action="j_security_check" method="post">
    <input type="text" name="j_username" />
    <input type="password" name="j_password" />
    <input type="submit" />
</form>
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();

try {
    request.login(username, password);
    return "home";
} catch (ServletException e) {
    errorMessage = e.getMessage();
    return "error";
}
    <h:form>
        <h:panelGrid columns="2">

        <h:outputLabel for ="uname" value="Enter User Name :  "/>
        <h:inputText id="uname" value="#{JSFManagedBean.username}"/>
        <h:outputLabel for ="pass" value="Enter Password  :"/>
        <h:inputSecret id="pass" value="#{JSFManagedBean.password}"/>
        <h:outputText/><h:outputText/>
        <h:outputText/>
        <h:commandButton id="login" value="Login" action="#{JSFManagedBean.Login()}"/>
        </h:panelGrid>
    </h:form>
</h:body>
Managed Bean contain the following Login Method 
    public String Login() {
        try {
            message="";
            HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
            request.login(username, password);
            if(request.isUserInRole("Admin"))
                return "/AdminPage/Admin.xhtml";
            else if(request.isUserInRole("Visitor"))
                return "/VisitorPage/Visitor.xhtml";
            else {
                message= "Either Login or Password is wrong";
                return "/index.xhtml";
            }

        } catch(Exception e) {
            message= "Either Login or Password is wrong";
        }
        return null;
    }