【问题标题】:wildfly security domain not workingWildfly 安全域不起作用
【发布时间】:2021-01-30 01:06:35
【问题描述】:

我已经尝试了所有我能找到的东西,但似乎无法解决这个问题。 我正在尝试在我的网站上使用 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]\"
    ]
}"

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

【问题讨论】:

    标签: java authentication wildfly securitydomain


    【解决方案1】:

    尝试更新 jboss-web.xml

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

    【讨论】:

    • 我试过这个没有用。不过还是谢谢。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-20
      • 2016-08-22
      • 1970-01-01
      • 2015-11-29
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2014-09-15
      相关资源
      最近更新 更多