首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSF登录失败

JSF登录失败
EN

Stack Overflow用户
提问于 2017-05-29 18:53:47
回答 1查看 243关注 0票数 0

我是使用Java和JSF进行开发的新手(这是Uni研究的一部分);我使用的是Derby8.2、GlassFish 4.1.1 (带Derby )、JSF2.2:

虽然我的登录无法通过jdbcRealm进行身份验证,但它也从不重定向到我的authFailure.xhtml页面&只是重新加载登录页面。

查看GlassFish日志,我只看到一条消息说“jdbcrealm.invaliduser”

我的数据库有以下数据:

--电子邮件-密码-APPGROUP

webmaster--5f4dcc3b5aa765d61d8327deb882cf99--ADMIN

staff1--5f4dcc3b5aa765d61d8327deb882cf99--USER

我使用了MD5散列来加密单词"password“

我的login.xhtml页面:

代码语言:javascript
复制
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html">

    <h:head>
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <meta name="description" content="NDIS Management System"/>
        <meta name="author" content="Danielle Walker"/>

        <title>NDIS Home</title>
        <!-- Bootstrap core CSS -->
        <h:outputStylesheet name="bootstrap/css/bootstrap.min.css"/>
        <h:outputStylesheet name="bootstrap/css/the-big-picture.css"  />
        <h:outputStylesheet name="css/google-button.css" />
        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <f:verbatim>
            <!--[if lt IE 9]>
              <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
              <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
            <![endif]-->    
        </f:verbatim>

        <f:verbatim>
            <script>
                var googleUser = {};
                var startApp = function () {
                    gapi.load('auth2', function () {
                        // Retrieve the singleton for the GoogleAuth library and set up the client.
                        auth2 = gapi.auth2.init({
                            client_id: '.....apps.googleusercontent.com',
                            cookiepolicy: 'single_host_origin'
                                    // Request scopes in addition to 'profile' and 'email'
                                    //scope: 'additional_scope'
                        });
                        attachSignin(document.getElementById('customBtn'));
                    });
                };

                function attachSignin(element) {
                    console.log(element.id);
                    auth2.attachClickHandler(element, {},
                            function (googleUser) {
                                document.getElementById('name').text = "Signed in: " +
                                        googleUser.getBasicProfile().getId();
                                //document.getElementById('login:j_username').value = googleUser.getBasicProfile().getEmail();
                            }, function (error) {
                        alert(JSON.stringify(error, undefined, 2));
                        //alert("Opps... an error Occured");
                    });
                }
                function signOut() {
                    var auth2 = gapi.auth2.getAuthInstance();
                    auth2.signOut().then(function () {
                        console.log('User signed out.');
                    });
                }
            </script>
        </f:verbatim>
        <ui:insert name="head"/>
    </h:head>

    <h:body class="full">

        <nav class="navbar navbar-inverse navbar-fixed-bottom" role="navigation">
            <div class="container">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#"></a>
                </div>
                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li>
                            <a href="#">About</a>
                        </li>
                        <li>
                            <a href="#">Contact</a>
                        </li>
                    </ul>
                    <ul class="navbar-right">
                        <li>
                            <div id="gSignInWrapper" style="padding-top:5px;">
                                <div id="customBtn" class="customGPlusSignIn" style="float: right;">
                                    <span class="icon"></span><span class="buttonText">Sign In</span>
                                </div>
                            </div>
                            <span style="color:#f9f9f9"><div id="name"></div></span>
                        </li>
                    </ul>
                </div>
                <!-- /.navbar-collapse -->
            </div>
            <!-- /.container -->
        </nav>

        <h:form id="login" onsubmit="document.getElementById('login').action = 'j_security_check';" prependId="false">
            <h:panelGrid columns="2">
                <h:outputLabel for="j_username" value="Username" />
                <h:inputText id="j_username" />            
                <h:outputLabel for="j_password" value="Password" />
                <h:inputSecret id="j_password" />
                <h:commandButton id="submit" value="Login" />
            </h:panelGrid>
        </h:form>
        <script>startApp();</script>

        <ui:insert name="body"/>

        <!-- Bootstrap core JavaScript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <h:outputScript name="bootstrap/js/bootstrap.min.js"/>
        <script src="https://apis.google.com/js/api:client.js" />
    </h:body>
</html>

我的Web.xml文件:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <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>/faces/*</url-pattern>
        <url-pattern>/javax.faces.resource/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <!--<welcome-file>faces/admin/mainmenu.xhtml</welcome-file>
        <welcome-file>faces/user/usermenu.xhtml</welcome-file>-->
        <welcome-file>/faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <error-page>
        <error-code>403</error-code>
        <location>/faces/authFailure.xhtml</location>
    </error-page>
    <security-constraint>
        <display-name>NDIS-Admin</display-name>
        <web-resource-collection>
            <web-resource-name>ADMIN</web-resource-name>
            <description>ADMIN</description>
            <url-pattern>/faces/admin/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>ADMIN</role-name>
        </auth-constraint>
    </security-constraint>
    <security-constraint>
        <display-name>NDIS-User</display-name>
        <web-resource-collection>
            <web-resource-name>USER</web-resource-name>
            <description>USER</description>
            <url-pattern>/faces/user/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>USER</role-name>
            <role-name>ADMIN</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>jdbcRealm</realm-name>
        <form-login-config>
            <form-login-page>/faces/login.xhtml</form-login-page>
            <form-error-page>/faces/authFailure.xhtml</form-error-page>
        </form-login-config>
    </login-config>
    <security-role>
        <description>NDIS-Admin</description>
        <role-name>ADMIN</role-name>
    </security-role>
    <security-role>
        <description>NDIS-User</description>
        <role-name>USER</role-name>
    </security-role>
    <mime-mapping>
        <extension>ttf</extension>
        <mime-type>css/fonts</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>otf</extension>
        <mime-type>font/opentype</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>woff2</extension>
        <mime-type>font/woff2</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>woff</extension>
        <mime-type>font/woff</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>eot</extension>
        <mime-type>application/vnd.ms-fontobject</mime-type>
    </mime-mapping>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>    

我的faces-config.xml文件;

代码语言:javascript
复制
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
              xmlns="http://xmlns.jcp.org/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">

    <application>  
        <!-- This supports resources referenced from within css files e.g. url(../fonts/glyphicons) -->
        <resource-handler>org.omnifaces.resourcehandler.UnmappedResourceHandler</resource-handler>
    </application>
    <navigation-rule>
        <description>Administrator Main Menu</description>
        <from-view-id>/admin/mainmenu.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>logout</from-outcome>
            <to-view-id>logout.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <description>User Main Menu</description>
        <from-view-id>/user/mainmenu.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>logout</from-outcome>
            <to-view-id>logout.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>
 </faces-config>

我的jdbcRealm配置:(没有显示,但摘要算法设置为MD5)

EN

回答 1

Stack Overflow用户

发布于 2017-05-30 11:37:57

我解决了我自己的问题:-)我丢失了一个beans.xml &然后做了一个干净的构建,一切都正常了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44240740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档