8

I have set the realm setting in server.xml host section to something like this:

<Realm  className="org.apache.catalina.realm.JDBCRealm"  driverName="org.gjt.mm.mysql.Driver"  
         connectionURL="jdbc:mysql://localhost:3306/test" connectionName="test" connectionPassword="test"  
             userTable="users" userNameCol="user_name" userCredCol="user_pass" userRoleTable="user_roles" 
       roleNameCol="user_role" />

Also in web.xml:

<security-role>
    <role-name>ADMIN</role-name>
</security-role>

<security-constraint>  
    <web-resource-collection>  
        <web-resource-name>critical</web-resource-name>  
        <url-pattern>/admin/*</url-pattern>  
        <http-method>GET</http-method>  
        <http-method>POST</http-method>  
    </web-resource-collection>  
    <auth-constraint>  
        <role-name>ADMIN</role-name>  
    </auth-constraint>  
</security-constraint>  

<login-config>  
    <auth-method>FORM</auth-method>  
    <form-login-config>  
        <form-login-page>/login.jsp</form-login-page>  
        <form-error-page>/error.jsp</form-error-page>  
    </form-login-config>  
</login-config> 

And I have the databased set up. However when login.jsp is envoked, even I entered the right password I was redirected to error.jsp

I want to know if there is a way to find what's wrong during the process. Can I do it in Eclipse or any other hints that may solve the problem?

5
  • Do you see anything in the log files ? Also, did you create and populate the appropriate tables ?
    – Santosh
    Sep 7, 2012 at 4:38
  • I think I have the right tables. Where can I find realm logs?
    – NSF
    Sep 7, 2012 at 4:49
  • Check the files in the logs folder of Tomcat.
    – Santosh
    Sep 7, 2012 at 5:01
  • @Santosh It says ClassNotFoundException: org.gjt.mm.mysql.Driver
    – NSF
    Sep 7, 2012 at 5:57
  • The driver class files org.gjt.mm.mysql.Drive are packaged in a jar file. The possible jar which contain this are mysql-connector-java.jar or mm.mysql.jar Check for any of these jars put them in lib folder in tomcat.
    – Santosh
    Sep 7, 2012 at 7:52

2 Answers 2

16

To get the debug information from the Realm authentication steps, follow this procedure.

When you define your Realm in the server.xml, add debug="9" to the definition (you can of course use a lower number for less detail).

<Realm  className="org.apache.catalina.realm.JDBCRealm"  driverName="org.gjt.mm.mysql.Driver"  
   connectionURL="jdbc:mysql://localhost:3306/test" connectionName="test" connectionPassword="test"  
   userTable="users" userNameCol="user_name" userCredCol="user_pass" userRoleTable="user_roles" 
   roleNameCol="user_role" debug="9" />

You also need to add this to your logging.properties file:

org.apache.catalina.realm.level = ALL
org.apache.catalina.realm.useParentHandlers = true
org.apache.catalina.authenticator.level = ALL
org.apache.catalina.authenticator.useParentHandlers = true

You may also need to add this, to prevent bufferring of the logs. If you do, remember to remove it after you've finished debugging.

1catalina.org.apache.juli.FileHandler.bufferSize = -1

Now, the debug logs for the realms should end up in the catalina.out file.

1
  • No luck for Eclipse 2022-03 + Tomcat 8.5.79. Nothing extra is logged following the instructions above. May 27, 2022 at 15:16
1

For others finding this issue, I found the following worked for Tomcat 8.5.40:

java.util.logging.ConsoleHandler.level = ALL
org.apache.catalina.level = FINEST
org.apache.catalina.realm.JNDIRealm.level = FINEST
org.apache.catalina.realm.JNDIRealm.useParentHandlers = true

The key fact appears to be that your logging travels through several layers of definitions and will be trimmed by the first one that has a lower level so you need to make sure that each bit it passes through is FINEST or ALL.

Hopefully this will save someone some time ;)

Ian.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.