1

我想在JBoss 7.1上部署一個可用的JSF應用程序(Tomcat 7.0.34)我已經配置了迄今爲止正在工作的數據源。但是我通過設置容器管理的認證有困難。通過調用index.xhtml,從數據庫正確加載所有項目。但是當我進行登錄時,用戶沒有任何作用。所以他不允許訪問他的客戶詳細信息頁面。因此,我想問一下,我是否忘記了要配置的東西。在JBoss 7.1上安裝JSF應用程序

我的配置:

standalone.xml

安全域似乎正常工作。如果我將所選列'角色'更改爲'r',登錄期間將引發異常。

... 
<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true" use-ccm="true"> 
    <connection-url>jdbc:mysql://localhost:3306/bookstore</connection-url> 
    <driver>mysql</driver> 
     <security> 
      <user-name>bookstore</user-name> 
      <password>book$tore</password> 
     </security> 
</datasource> 
... 
<security-domain name="SgpRealm" cache-type="default"> 
    <authentication> 
     <login-module code="Database" flag="required"> 
      <module-option name="dsJndiName" value="java:jboss/datasources/MySqlDS"/> 
      <module-option name="principalsQuery" value="SELECT pwd FROM customer where eMail=?"/> 
      <module-option name="rolesQuery" value="SELECT role, role FROM roles WHERE eMail=?"/> 
      <module-option name="unauthenticatedIdentity" value="anonymous"/> 
      <module-option name="password-stacking" value="useFirstPass"/> 
     </login-module> 
    </authentication> 
</security-domain> 

在JBoss-web.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<jboss> 
    <security-domain>SgpRealm</security-domain> 
</jboss> 

符web.xml

<security-constraint> 
    <web-resource-collection> 
    <web-resource-name>Authenticated admins only</web-resource-name> 
    <url-pattern>/faces/sections/admin/*</url-pattern> 
</web-resource-collection> 
<auth-constraint> 
    <role-name>ADMIN</role-name> 
    </auth-constraint> 
</security-constraint> 

<login-config> 
    <auth-method>FORM</auth-method> 
<form-login-config> 
    <form-login-page>/faces/sections/authentication/login.xhtml</form-login-page> 
    <form-error-page>/faces/sections/authentication/loginFailed.xhtml</form-error-page> 
</form-login-config> 
</login-config> 

<security-role> 
    <role-name>ADMIN</role-name> 
</security-role> 

的login.xhtml

<h:form prependId="false"> 
<table id="loginTable" > 
    <tr> 
     <td><h:outputLabel for="email" value="#{msgs.username}" /> 
     </td> 
     <td><h:inputText id="email" value="#{login.eMail}" 
          required="true" style="width:100%" /></td> 
    </tr> 
    <tr> 
     <td><h:outputLabel for="password" value="#{msgs.password}" /> 
     </td> 
     <td><h:inputSecret id="password" value="#{login.password}" 
          required="true" style="width:100%" /></td> 
    </tr> 
    <tr height="50px"> 
     <td colspan="2"><h:commandButton value="#{msgs.login}" 
          actionListener="#{login.doLogin}" style="width:104%" /></td> 
    </tr> 

</table>  
</h:form> 

的Login.java#doLogin(。 ..)方法

public void doLogin(ActionEvent e) throws IOException { 
FacesContext context = FacesContext.getCurrentInstance(); 
HttpServletRequest request = (HttpServletRequest) context 
    .getExternalContext().getRequest(); 

try { 
    // Try to login customer via container management 
    request.login(eMail, password); 

      /* 
      * Prints out the username (eMail) of the logged in user !!! 
      */     
      System.out.println(request.getUserPrincipal()); 

      if(request.isUserInRole("ADMIN")){ 

        /* 
        * This part of source is never reached!!!! 
        */ 

        System.out.println("Role: ADMIN"); 
      } 
      ... 

通過使用Tomcat實例,在META-INF目錄中有一個名爲context.xml的文件。 (對於JBoss我刪除了它)

<Context> 

    <Resource name="jdbc/bookstore" 
    auth="Container" 
    type="javax.sql.DataSource" 
     username="bookstore" 
     password="book$tore" 
     driverClassName="com.mysql.jdbc.Driver" 
     url="jdbc:mysql://localhost/bookstore"/> 

</Context> 

我需要某物嗎?類似的JBoss,還是有任何額外的配置文件neeeded?

非常感謝!

回答

0

所以,我的應用程序現在運行在JBoss上。我只是改變了安全域從

<security-domain name="SgpRealm" cache-type="default"> 
<authentication> 
    <login-module code="Database" flag="required"> 
     <module-option name="dsJndiName" value="java:jboss/datasources/MySqlDS"/> 
     <module-option name="principalsQuery" value="SELECT pwd FROM customer where eMail=?"/> 
     <module-option name="rolesQuery" value="SELECT role, role FROM roles WHERE eMail=?"/> 
     <module-option name="unauthenticatedIdentity" value="anonymous"/> 
     <module-option name="password-stacking" value="useFirstPass"/> 
    </login-module> 
</authentication> 

<security-domain name="SgpRealm" cache-type="default"> 
<authentication> 
    <login-module code="Database" flag="required"> 
     <module-option name="dsJndiName" value="java:jboss/datasources/MySqlDS"/> 
     <module-option name="principalsQuery" value="SELECT pwd FROM customer where eMail=?"/> 
     <module-option name="rolesQuery" value="SELECT role, role FROM roles WHERE eMail=?"/> 
    </login-module> 
</authentication> 

文件context.xml中仍被刪除。