2016-12-12 42 views
0

我试过了我能找到的所有东西,而且似乎无法解决这个问题。 我想在我的网站上使用FORM认证使用在JBoss中-web.xml中:蜻蜓安全域无法正常工作

<jboss-web> 
    <context-root>/JacobHewitt</context-root> 
    <security-domain>ref</security-domain> 
</jboss-web> 

这里是我的standalone.xml

<security-domain name="ref" cache-type="default"> 
       <authentication> 
        <login-module code="Database" flag="required"> 
         <module-option name="dsJndiName" value="java:jboss/datasources/RefereeDS"/> 
         <module-option name="principalsQuery" value="SELECT password FROM UserEntity WHERE email=?"/> 
         <module-option name="rolesQuery" value="SELECT role, 'Roles' FROM UserEntity WHERE email=?"/> 
         <module-option name="hashAlgorithm" value="SHA-256"/> 
         <module-option name="hashEncoding" value="base64"/> 
         <module-option name="unauthenticatedIdentity" value="GUEST"/> 
        </login-module> 
       </authentication> 
      </security-domain> 

这里我的安全域是数据源也在standalone.xml中

<datasource jta="false" jndi-name="java:jboss/datasources/RefereeDS" pool-name="RefereeDS" enabled="true" use-java-context="true" use-ccm="false"> 
       <connection-url>jdbc:derby://localhost:1527/Referee</connection-url> 
       <driver-class>org.apache.derby.jdbc.ClientDriver</driver-class> 
       <driver>derbyclient.jar</driver> 
       <security> 
         <user-name>jake</user-name> 
         <password>jake</password> 
       </security> 
       <validation> 
         <validate-on-match>false</validate-on-match> 
         <background-validation>false</background-validation> 
       </validation> 
       <statement> 
         <share-prepared-statements>false</share-prepared-statements> 
       </statement> 
      </datasource> 

上面的数据源正在工作,因为我一直在使用它。

这里是用于创建UserEntity表的UserEntity.java类。

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package com.mycompany.jacobhewitt.entitys; 

import java.io.Serializable; 
import java.util.Date; 
import javax.persistence.CascadeType; 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.FetchType; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.NamedQuery; 
import javax.persistence.OneToOne; 
import javax.persistence.Table; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 
import java.io.Serializable; 
import java.math.BigInteger; 
import java.nio.ByteBuffer; 
import java.nio.CharBuffer; 
import java.nio.charset.Charset; 
import java.security.MessageDigest; 
import java.security.NoSuchAlgorithmException; 
import javax.persistence.NamedQueries; 

/** 
* 
* @author jake 
*/ 
@Entity 
@NamedQueries({@NamedQuery(name="findUserByEmail", query="SELECT u FROM UserEntity u WHERE u.email = :email")}) 
public class UserEntity implements Serializable { 

    @Id 
    @Column(name="email") 
    private String email; 

    @Column(name="password", length=32, columnDefinition = "VARCHAR(32)") 
    private char[] password; 

    private String firstName; 
    private String lastName; 

    @Column(name="since", columnDefinition = "DATE", nullable = true) 
    private Date since; 


    private String role; 

    public void setRole(String role){ 
     this.role = role; 

    } 

    public String getRole(){ 
     return role; 
    } 

    public void setPassword(char[] password){ 
     this.password = password; 
    } 

    public void setPassword(String password){ 
     this.password = hashPassword(password.toCharArray()); 
    } 

    public char[] getPassword(){ 
     return password; 
    } 

    public String getFirstName() { 
     return firstName; 
    } 

    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 

    public String getLastName() { 
     return lastName; 
    } 

    public void setLastName(String lastName) { 
     this.lastName = lastName; 
    } 

    public String getEmail() { 
     return email; 
    } 

    public void setEmail(String email) { 
     this.email = email; 
    } 

    public Date getSince() { 
     return since; 
    } 

    public void setSince(Date since) { 
     this.since = since; 
    } 

    private char[] hashPassword(char[] password) { 
     char[] encoded = null; 
     try { 
      ByteBuffer passwdBuffer = Charset.defaultCharset().encode(CharBuffer.wrap(password)); 
      byte[] passwdBytes = passwdBuffer.array(); 
      MessageDigest mdEnc = MessageDigest.getInstance("MD5"); 
      mdEnc.update(passwdBytes, 0, password.length); 
      encoded = new BigInteger(1, mdEnc.digest()).toString(16).toCharArray(); 
     } catch (NoSuchAlgorithmException ex) { 

     } 

     return encoded; 
    } 

} 

这里是给定的,当我尝试将wildfly服务器上运行的错误:

Deploying C:\wildfly-10.1.0.Final\standalone\deployments\JacobHewitt-1.0-SNAPSHOT.war 
"{ 
    <b>\"WFLYCTL0412: Required services that are not installed:\" => [\"jboss.security.security-domain.ref\"],</b> 
    \"WFLYCTL0180: Services with missing/unavailable dependencies\" => [ 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.TeamEJB.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.UserEntityFacade.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.TeamEntityFacade.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.UserEJB.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.undertow.deployment.default-server.default-host./JacobHewitt.UndertowDeploymentInfoService is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.PenaltyCodeEJB.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.RefereeEJB.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.FoulEntityFacade.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.CommentEJB.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.MatchEJB.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.RefereeEntityFacade.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.MatchEntityFacade.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.PenaltyCodeEntityFacade.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.PersonFacade.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.DataBasePopulator.CREATE is missing [jboss.security.security-domain.ref]\", 
     \"jboss.deployment.unit.\\\"JacobHewitt-1.0-SNAPSHOT.war\\\".component.CommentEntityFacade.CREATE is missing [jboss.security.security-domain.ref]\" 
    ] 
}" 

任何帮助将广泛赞赏。由于

回答

0

尝试更新的jboss-web.xml中

<jboss-web> 
    <context-root>/JacobHewitt</context-root> 
    <security-domain>java:/jaas/ref</security-domain> 
</jboss-web> 
+0

我曾经尝试这样做无济于事。不过谢谢。 –