wood burning stoves 2.0*
The moose likes Tomcat and the fly likes 'Exception performing authentication' using JDBC Realm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark " Watch " New topic
Author

'Exception performing authentication' using JDBC Realm

Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
Hello,

I have an annoying error which I can't solve for quite a while. I recently was introduced to container-based security and try to implement it. I have configure the realm as following:



Unfortunately I can't login with this. The log error messages are:

SEVERE: Exception performing authentication
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null WHERE login = 'user1'' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030)
at org.apache.catalina.realm.JDBCRealm.getRoles(JDBCRealm.java:640)
at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:430)
at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:355)
at org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:146)
at org.apache.catalina.realm.LockOutRealm.authenticate(LockOutRealm.java:180)
at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:282)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:440)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)


Please notice the '' around the user name... Is this correct?

As you see I also use allRolesMode="authOnly", because I don't need this functionality and moreover the database doesn't have and won't ever have an additional column for user roles (it is quite pointless if won't use it than every user will have the same value in this column - big waste of recourses.).

The server is Tomcat 7.0.19
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

The Tomcat Context definition is XML. XML requires all attribute values to be delimited by double-quote characters, unlike HTML which can use single-quote characters or no delimiters at all. If you're referring to the usage of quotes in the MySQL error message in the SQLException, its usage of single and double quotes is just plain bizarre.

I wasn't familiar with the allRolesMode option myself. My apps tend to have a minimum of 3 roles: unsecured, app user, and app administrator. So I've never had that issue.

I think your real problem is that you've setup the following structure:


That's malformed XML. It's the equivalent of this:


Assuming what you gave us is correct, I'm surprized that Tomcat didn't simple fail to start because of a digester XML error.


Customer surveys are for companies who didn't pay proper attention to begin with.
Adam Kronicki
Ranch Hand

Joined: Sep 01, 2009
Posts: 68
No Tomcat works fine with this. But i is the problem of allRolesMode="authOnly" . When I added user role tables and columns it works. Unfortunately as I wrote The db won't have user roles columns so I needed to pick one with enum values and listed all of them in the application web.xml file :/ I don't like this but it seems that there is no other way :/ Unless anybody knows another approach to ignore roles checking?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'Exception performing authentication' using JDBC Realm