Wildfly digest login-config with database login module

I am trying to encrypt a password in a database login module with a Wildfly picketbox module. These are my sources.

== web.xml

 ... 
 <security-role> 
    <role-name>administrator</role-name> 
 </security-role> 

 <login-config> 
    <auth-method>DIGEST</auth-method> 
    <realm-name>WildFly8DigestRealm</realm-name> 
 </login-config> 
 .... 

== jboss-web.xml

 ... 
 <jboss-web> 
    <security-domain>java:/jaas/my_secure_domain</security-domain> 
 </jboss-web>

== standalone.xml

... 
 <security-domain name="my_secure_domain" 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 password from credential where uid=?"/> 
          <module-option name="rolesQuery" value="select urole, 'Roles' from credential where uid=?"/> 
          <module-option name="hashAlgorithm" value="MD5"/> 
          <module-option name="hashEncoding" value="base64"/> 
          <module-option name="hashUserPassword" value="true"/> 
          <module-option name="hashStorePassword" value="true"/> 
       </login-module> 
    </authentication> 
 </security-domain>

Password is encrypted below.

== EncryptPassword.java

import java.security.MessageDigest; 
import org.jboss.security.Base64Encoder; 

public class EncryptPassword { 

  public static void main(String[] args) { 
    // TODO Auto-generated method stub 
    String algoritmo = "MD5"; 
    String clearTextPassword = "passwd123"; 
    String hashedPassword = null; 

    try { 
       byte[] hash = MessageDigest.getInstance(algoritmo).digest(clearTextPassword.getBytes()); 
       hashedPassword = Base64Encoder.encode(hash); 
       System.out.println("Clear Text Password : " + clearTextPassword); 
       System.out.println("Encrypted Password : " + hashedPassword); 
    } catch (Exception e) { 
       e.printStackTrace(); 
    } 
  } 
 } 

And also I executed the Java command on the shell as shown below, and also on the Java file:

C:> java -cp c: \ wildfly-8.0.0.final \ modules \ system \ layers \ base \ org \ picketbox \ main \ picketbox-4.0.20.Final.jar org.jboss.security.Base64Encoder passwd123 MD5

Both results yield the same hashed password, and the hashed password is updated.

Clear Text Password : passwd123 
Encrypted Password : EWT55bjO92g5bc1TdOS26w== 

However, the login still failed. And in server.log, this raises the following exception.

 LoginModule Class: org.jboss.security.auth.spi.DatabaseServerLoginModule 
 ControlFlag: LoginModuleControlFlag: required 
 Options: 
 name=hashUserPassword, value=true 
 name=hashAlgorithm, value=MD5 
 name=principalsQuery, value=select password from credential where uid=? 
 name=hashEncoding, value=base64 
 name=dsJndiName, value=java:jboss/datasources/MySqlDS 
 name=hashStorePassword, value=true 
 name=rolesQuery, value=select urole, 'Roles' from credential where uid=? 

 2014-07-15 21:06:45,845 TRACE [org.jboss.security] (default task-2) PBOX000236: Begin initialize method 
 2014-07-15 21:06:45,845 DEBUG [org.jboss.security] (default task-2) PBOX000281: Password hashing activated, algorithm: MD5, encoding: base64, charset: null, callback: null, storeCallBack: null 
 2014-07-15 21:06:45,846 TRACE [org.jboss.security] (default task-2) PBOX000262: Module options [dsJndiName: java:jboss/datasources/MySqlDS, principalsQuery: select password from credential where uid=?, rolesQuery: select urole, 'Roles' from credential where uid=?, suspendResume: true] 
 2014-07-15 21:06:45,847 TRACE [org.jboss.security] (default task-2) PBOX000240: Begin login method 
 2014-07-15 21:06:46,022 TRACE [org.jboss.security] (default task-2) PBOX000263: Executing query select password from credential where uid=? with username admin 
 2014-07-15 21:06:46,037 DEBUG [org.jboss.security] (default task-2) PBOX000283: Bad password for username admin 
 2014-07-15 21:06:46,037 TRACE [org.jboss.security] (default task-2) PBOX000244: Begin abort method 
 2014-07-15 21:06:46,037 DEBUG [org.jboss.security] (default task-2) PBOX000206: Login failure: javax.security.auth.login.FailedLoginException: PBOX000070: Password invalid/Password required 
 at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:284) [picketbox-4.0.20.Final.jar:4.0.20.Final] 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_60] 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_60] 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_60] 
 at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_60] 
 at javax.security.auth.login.LoginContext.invoke(LoginContext.java:762) [rt.jar:1.7.0_60] 
 at javax.security.auth.login.LoginContext.access$000(LoginContext.java:203) [rt.jar:1.7.0_60] 
 at javax.security.auth.login.LoginContext$4.run(LoginContext.java:690) [rt.jar:1.7.0_60] 
 at javax.security.auth.login.LoginContext$4.run(LoginContext.java:688) [rt.jar:1.7.0_60] 
 at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_60] 
 at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:687) [rt.jar:1.7.0_60] 
 at javax.security.auth.login.LoginContext.login(LoginContext.java:595) [rt.jar:1.7.0_60]
+4
2

, :

  • hashed/encoded, hashUserPassword true, .
  • , , hashed/encoded, hashStorePassword true, .
  • / .

, / ( ), , /, .

hashStorePassword false :

<module-option name="hashStorePassword" value="false"/> 
+4

module-option name="hashUserPassword" value="true" module-option name="hashStorePassword" value="true" module-option name="hashStorePassword" value="false", .

+1

Source: https://habr.com/ru/post/1548492/


All Articles