• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to debug DataSourceRealm when attempted login always goes to form-error-page

 
Ranch Hand
Posts: 239
2
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I'm hoping to get some help on how to debug failing to login using the DataSourceRealm, my context.xml and web.xml are below.
  • I've tested the database connection, that's working, and I can return usernames and passwords through that connection
  • I've tried turning the form-error-page off, but tomcat doesn't provide any futher details on why it's failing
  • I've tried to look in the log file, but the catalina log is telling me WARNING [http-nio-8080-exec-440] org.apache.tomcat.util.digester.SetPropertiesRule.begin Match [Context/Realm] failed to set property [debug] to [99]


  • I've been poking around all day, but haven't be able to make any progress, and tips would be welcomed.

    Thanks

    Marten

    note the userTable and userRoleTable are the same because a user can only be in one role in this application.





     
    Saloon Keeper
    Posts: 28720
    211
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I had to go back and check my docs, because I tend to think of the form-error-page as the "login fail page".

    The standard Tomcat Realms all have debug logging available, so the short answer is that you simply bump the log level to "debug" or "trace" for the Tomcat logger. The exact logger name you need you can pull from its Tomcat source code, but it probably starts with something like "org.catalina.realm".

    However, you don't get the form error page because there was literally an error in the Realm, which is why I forgot that that's its official name. You get it when you attempt to login and you fail. Because the userid/password was not authenticated by the Realm.

    If memory serves, the stock JDBCRealm is case sensitive to both userid and password.  Also, padding spaces in the database columns containing those items will throw off the process. A lot of systemss NOT Unix/Linux!) are case-insensitive for userid, but case-sensitive for password. To get that you have to subclass the Realm with a custom Realm of your own.
     
    marten koomen
    Ranch Hand
    Posts: 239
    2
    jQuery Postgres Database Java
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Tim

    I did a bit of deep dive into the logging functionality, and while not much of what I did made sense, login is now working, with the only thing effectively change I made was to add the localDateSource value in the Realm, as per below.



    on well, all fixed, thanks
     
    Tim Holloway
    Saloon Keeper
    Posts: 28720
    211
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ouch!

    I'm not sure what that's even supposed to mean. It sounds like this particular Realm allows using a JNDI server other than the one built into Tomcat. And even then, the built-in JNDI server should be the default!

    Congratulations on solving this. Have a cow!
     
    marten koomen
    Ranch Hand
    Posts: 239
    2
    jQuery Postgres Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Tim, very generous with an undeserved cow, as I'm not sure what solved it, but as you suggest I think it had something to do with JINDI, and I suspect it's a Netbeans  things.

    I found the following line in the localhost log in Tomcat's log folder
    SEVERE: Exception performing authentication
    javax.naming.NameNotFoundException: Name [jdbc/...] is not bound in this Context. Unable to find [jdbc].


    which I thought strange because a servlet in the same context was able to access the database with the same details. So I added antiJARLocking in the Context tag in the context xml as per below. I found it somewhere, it's bit mysterious but it makes sense.  I'm not sure what the solution was - the antilocking or the localDataSource

     
    Tim Holloway
    Saloon Keeper
    Posts: 28720
    211
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I can't really say. a JNDI URL itself has the form java:/comp/env/foo/bar, where "foo" is a "directory" and "bar" is a resource. JNDI not only provides the database for JDBC Connection Pools, but also for anything else your app defines as a "Resource".

    The "foo" part for a database connection pool is typically "jdbc", but it can be anything. The "bar" would be the resource name. You don't eevn need "foo/bar" if you're onlly going to define one connection resource, but it's good practice.

    Possible the "localDatasource" allows omitting the "java:/comp/env", but there's insufficient documentation to tell. Unless NetBeans is messing around in tomcat's insides, it shouldn't make any difference that you're using NetBeans.
     
    marten koomen
    Ranch Hand
    Posts: 239
    2
    jQuery Postgres Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I use " java:/comp/env/foo/bar"  in the java code, as in


    but not in in my context.xml in the Realm descriptor for the dataSourceName where I just use foo/bar, when I do use java:/comp/env/foo/bar it doesn't work according to my trial and error method.

    However I'm not sure that Netbeans isn't the culprit (apols for double negative). In Netbeans the database connection and authentication realm work well when I Run my app, but when I try Debug it hangs then finishes with the message below.

    ------------------------------------------------------------------------
    BUILD SUCCESS
    ------------------------------------------------------------------------
    Total time:  2.000 s
    Finished at: 2024-09-22T19:51:43+10:00
    ------------------------------------------------------------------------
    Deploying on Apache Tomcat or TomEE
       profile mode: false
       debug mode: true
       force redeploy: true
    Checking data source definitions for missing JDBC drivers...
    Stopping Tomcat process...
    Waiting for Tomcat...
    Stopping of Tomcat failed.



    It seems to be having trouble picking up the drivers. Not having Debug is not a totally bad thing, as it forces me to code without mistakes.
     
    Tim Holloway
    Saloon Keeper
    Posts: 28720
    211
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yes, the resource declaration doesn't use "java:comp/env".

    You seem to be missing a lot of startup messages. I don't know how NetBeans is launching Tomcat, but in my preferred Eclipse environment, the Tomcat plugin (NOT the built-in SWT abomination) is using a live Tomcat installation and the database drivers are required to be in TOMCAT_HOME/lib, just as they would be in production.

    If NetBeans is mucking around with things, you might have to manually include the jdbc JAR file as part of the run/test configuation classpath.
     
    marten koomen
    Ranch Hand
    Posts: 239
    2
    jQuery Postgres Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Tim -  another case of a novice blaming the tools.

    I checked the TOMCAT_HOME\lib folder and it had a newer version of the postgres driver than declared in the pom.xml and in the development lib folder. Once I updated my pom.xml to reflect the newer driver, as well as delete older drivers from my system, things started to work as expected.

    Having said that, it took a bit to expunge the outdated driver as it kept popping up in places, that Netbeans deploys tomcat apps from an \.m2 folder in my windows/users folder is annoying, and I had to restart my machine to ensure everything was good after some search and destroy missions.

    Debug is now working fine, and from trial and error I can report that my set up does not work if  the localDataSource="true" element is not in the Realm element, but the antiJARLocking element is redundant.
     
    Tim Holloway
    Saloon Keeper
    Posts: 28720
    211
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Urk.

    Yous database driver (postgresql) should NOT be declared in your POM. Your POM only defines the WAR that will be created and deployed. The Database Connection Pool is created and owned by Tomcat, and Tomcat has a different classpath than the WAR. Putting the database JAR in your WAR itself can lead to unpredictable results.
     
    marten koomen
    Ranch Hand
    Posts: 239
    2
    jQuery Postgres Database Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks! a huge conceptual error fixed, my environment is now working swimmingly. I wasn't getting System.out.println output in my console before, and now that's functioning.  Onwards and upwards.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic