users@glassfish.java.net

Can't get JDBCRealm to work with MySQL

From: <glassfish_at_javadesktop.org>
Date: Sun, 15 Apr 2007 16:33:31 PDT

I'm using JDBCRealm with form-based security in testing with JavaDB (Derby) - it works
 great, but I cannot get it working with MySQL -- which is required for this project. I've
worked on this for a day and a half and would really welcome some help.

I'm running Glassfish v2b42 with Hibernate 3.1/Hibernate Entity Manager 3.2.1 on
Redhat ES 4.0, Java 6, MySQL 5.0.16.

I successfully write a record to my Contact table with username = admin, password =
admin33. The MD5 encoded password looks the same in the Derby and MySQL
databases -- the value is, "f6a1921633481c17562904903c058f14", however, when I try logging in, it works on Derby, but fails on MySQL.

I've tried both UTF-8 and Latin-1 character sets for the database and neither works.

[b]Here's my JDBCRealm definition in domain.xml[/b]

        <auth-realm classname="com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm" name="smash-users">
          <property name="jaas-context" value="jdbcRealm"/>
          <property name="datasource-jndi" value="jdbc/smashmysql"/>
          <property name="user-table" value="CONTACT"/>
          <property name="user-name-column" value="USERNAME"/>
          <property name="password-column" value="PASSWORD"/>
                  <property name="group-table" value="USERGROUP"/>
          <property name="group-name-column" value="GROUPNAME"/>
          <property name="digest-algorithm" value="MD5"/>
        </auth-realm>

[b]Here's my MD5 encoding code[/b]

[code]
    private static final char[] HEXADECIMAL = { '0', '1', '2', '3',
    '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        MessageDigest md = getDigest();
        md.reset();
        String inStr = new String(inChars);
        byte[] bytes = md.digest(inStr.getBytes());
        StringBuilder sb = new StringBuilder(2 * bytes.length);
        for (int i = 0; i < bytes.length; i++) {
            int low = (int)(bytes[i] & 0x0f);
            int high = (int)((bytes[i] & 0xf0) >> 4);
            sb.append(HEXADECIMAL[high]);
            sb.append(HEXADECIMAL[low]);
        }
        char[] outChars = sb.toString().toCharArray();
        return outChars;
[/code]

[b]Here's the output from server.log when I try to login using form-based login[/b]

I don't see anything useful here, but maybe someone else does...thank very much.. Rick

---- server.log output -----

[#|2007-04-15T19:23:56.476-0400|FINE|sun-appserver9.1|javax.enterprise.system.core.naming|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.naming.SerialContext;MethodName=<init>;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|SerialContext ==> SerialContext instance created : com.sun.enterprise.naming.SerialContext_at_16c281d|#]

[#|2007-04-15T19:23:56.477-0400|FINE|sun-appserver9.1|javax.enterprise.system.core.naming|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.naming.SerialContext;MethodName=lookup;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|SerialContext ==> doing lookup with com.sun.enterprise.naming.SerialContext_at_16c281d|#]

[#|2007-04-15T19:23:56.477-0400|FINE|sun-appserver9.1|javax.enterprise.system.core.naming|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.naming.SerialContext;MethodName=lookup;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|SerialContext ==> looking up : jdbc/smashmysql|#]

[#|2007-04-15T19:23:56.477-0400|FINE|sun-appserver9.1|javax.enterprise.system.core.naming|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.naming.SerialContext;MethodName=getProvider;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|lookup call inside the server VM...|#]

[#|2007-04-15T19:23:56.477-0400|FINE|sun-appserver9.1|javax.enterprise.system.core.naming|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.naming.SerialContextProviderImpl;MethodName=lookup;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;| SerialContextProviderImpl :: lookup jdbc/smashmysql|#]

[#|2007-04-15T19:23:56.478-0400|FINE|sun-appserver9.1|javax.enterprise.system.core.naming|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.naming.factory.ConnectorObjectFactory;MethodName=getObjectInstance;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|ConnectorObjectFactory: Reference Class Name: com.sun.gjc.spi.DataSource
Type: poolName
Content: SmashMySQLPool
Type: rarName
Content: __cp
 Name:jdbc/smashmysql|#]

[#|2007-04-15T19:23:56.478-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=getActiveResourceAdapter;__cp;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|returning/found the resource adapter from connector registry|#]

[#|2007-04-15T19:23:56.478-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=isMCFCreated;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|isMCFCreated SmashMySQLPool - true|#]

[#|2007-04-15T19:23:56.479-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=getManagedConnectionFactory;SmashMySQLPool;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|Returning the MCF from connector registry.|#]

[#|2007-04-15T19:23:56.479-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=getInstance;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|returning the connector registry|#]

[#|2007-04-15T19:23:56.479-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectionManagerFactory;MethodName=getAvailableConnectionManager;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|@@@@ Creating plain ConnectionManager|#]

[#|2007-04-15T19:23:56.479-0400|FINE|sun-appserver9.1|javax.enterprise.system.core.naming|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.naming.factory.ConnectorObjectFactory;MethodName=deriveJndiName;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|JNDI name will be suffixed with :__nontx|#]

[#|2007-04-15T19:23:56.479-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=isMCFCreated;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|isMCFCreated SmashMySQLPool - true|#]

[#|2007-04-15T19:23:56.480-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=getManagedConnectionFactory;SmashMySQLPool;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|Returning the MCF from connector registry.|#]

[#|2007-04-15T19:23:56.480-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=getInstance;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|returning the connector registry|#]

[#|2007-04-15T19:23:56.480-0400|FINE|sun-appserver9.1|javax.enterprise.system.core.naming|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.naming.factory.ConnectorObjectFactory;MethodName=getObjectInstance;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|Connection Factory:com.sun.gjc.spi.jdbc40.DataSource40_at_1bdbbf0|#]

[#|2007-04-15T19:23:56.480-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=getInstance;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|returning the connector registry|#]

[#|2007-04-15T19:23:56.480-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectionManagerImpl;MethodName=allocateConnection;jdbc/smashmysql__nontx;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|RAR5036:Resource reference is not defined for JNDI name [jdbc/smashmysql__nontx]|#]

[#|2007-04-15T19:23:56.481-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=getInstance;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|returning the connector registry|#]

[#|2007-04-15T19:23:56.481-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectorRegistry;MethodName=getDescriptor;__cp;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|Found/returing Connector descriptor in connector registry.|#]

[#|2007-04-15T19:23:56.481-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.connectors.ConnectionManagerImpl;MethodName=internalGetConnection;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|ConnectionMgr: poolName SmashMySQLPool txLevel : 1|#]

[#|2007-04-15T19:23:56.481-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.resource.PoolManagerImpl;MethodName=logFine;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|@@@@ Returning noTxResourceManager|#]

[#|2007-04-15T19:23:56.481-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.resource.PoolManagerImpl;MethodName=logFine;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|@@@@ Returning noTxResourceManager|#]

[#|2007-04-15T19:23:56.482-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.resource.NoTxResourceManagerImpl;MethodName=enlistResource;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|NoTxResourceManagerImpl :: enlistResource called|#]

[#|2007-04-15T19:23:56.482-0400|SEVERE|sun-appserver9.1|javax.enterprise.system.core.security|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;admin;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|SEC1112: Cannot validate user [admin] for JDBC realm.|#]

[#|2007-04-15T19:23:56.482-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.resource.PoolManagerImpl;MethodName=logFine;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|@@@@ Returning noTxResourceManager|#]

[#|2007-04-15T19:23:56.482-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.resource.NoTxResourceManagerImpl;MethodName=delistResource;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|NoTxResourceManagerImpl :: delistResource called|#]

[#|2007-04-15T19:23:56.483-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.resource.AbstractResourcePool;MethodName=resourceClosed;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|Pool: resourceClosed: 33|#]

[#|2007-04-15T19:23:56.483-0400|FINE|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;ClassName=com.sun.enterprise.resource.AbstractResourcePool;MethodName=resourceClosed;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|Pool: resourceFreed: 33|#]

[#|2007-04-15T19:23:56.483-0400|INFO|sun-appserver9.1|javax.enterprise.system.core.security|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;admin;|SEC5046: Audit: Authentication refused for [admin].|#]

[#|2007-04-15T19:23:56.483-0400|WARNING|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|Web login failed: Login failed: javax.security.auth.login.LoginException: Security Exception|#]

[#|2007-04-15T19:23:56.484-0400|WARNING|sun-appserver9.1|org.apache.coyote.tomcat5.CoyoteRequest|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8181-0;_RequestID=3fb4b8ae-3860-4c67-82b7-2f339dae639f;|PWC4011: Unable to set request character encoding to UTF-8 from context /Smash-war, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
[Message sent by forum member 'rickhoro' (rickhoro)]

http://forums.java.net/jive/thread.jspa?messageID=212469