2017-05-29 255 views
0

即時通訊新的Java開發& JSF(這是Uni研究的一部分); 我使用NetBeans 8.2,GlassFish的4.1.1(與德比DB),JSF 2.2:JSF登錄失敗

雖然我的登錄失敗的通過jdbcRealm認證,我想不通),它也從來沒有重定向到我的authFailure .xhtml頁面&只是重新加載登錄頁面。

展望了GlassFish日誌,我只是有消息說「 jdbcrealm.invaliduser」

我的數據庫具有以下數據:
--email -----------密碼----------- APPGROUP
站長 - 5f4dcc3b5aa765d61d8327deb882cf99 - ADMIN
staff1--5f4dcc3b5aa765d61d8327deb882cf99 - 用戶

伊夫使用MD5哈希來字加密 「密碼」

我login.xhtml頁:

<?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文件:

<?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文件;

<?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) enter image description here

回答

1

我解決我自己的問題:-) 我錯過了一個beans.xml的&然後做一個乾淨的版本,它一切正常。