1

我已经尝试了所有我能找到的东西,但似乎无法解决这个问题。我正在尝试使用 jboss-web.xml 在我的网站上使用 FORM 身份验证:

<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]\"
    ]
}"

任何帮助将不胜感激。谢谢

4

2 回答 2

1

得到它的工作:您必须在这里使用 undertow 安全域而不是 elytron 安全域

使用先前使用命令创建的安全域:/subsystem=undertow/application-security-domain= etc. 等等。

于 2020-11-19T10:50:02.237 回答
1

尝试更新 jboss-web.xml

<jboss-web>
    <context-root>/JacobHewitt</context-root>
     <security-domain>java:/jaas/ref</security-domain>
</jboss-web>
于 2016-12-13T08:16:28.357 回答