wildfly security domain not working

6.7k Views Asked by At

I've tried everything i can find and can't seem to work this out. I'm trying to use FORM authentication on my website using the in jboss-web.xml:

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

Here is my security-domain in my 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>  

Here is the datasource also in the 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>

The datasource above is working as i have been using it.

here is the UserEntity.java class used to create the UserEntity table.

/*
 * 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;
    }

}

Here is the error given when i try to run on the wildfly server:

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

Any help will be wildly appreciated. Thanks

2

There are 2 best solutions below

1
On

Try to update jboss-web.xml

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

Got it working: You must use here the undertow security domain and not the elytron security domain

With the previous created security domain with command: /subsystem=undertow/application-security-domain= etc. etc.