This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes overriding JDBCRealm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "overriding JDBCRealm" Watch "overriding JDBCRealm" New topic
Author

overriding JDBCRealm

Yacov Wolfowicz
Greenhorn

Joined: Feb 18, 2010
Posts: 4
Hi,

I'm trying to customize the way authentication is done.
I created a class, overriding JDBCRealm which delegates all calls to JDBCRealm. When using it in my server.xml file, I get some annoying exceptions and TOMCAT won't start.

What am I missing??


Thanks.

I use Tomcat 5.5, with eclipse.

the exceptions:


java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: java.lang.NullPointerException
at org.apache.catalina.startup.Catalina.await(Catalina.java:616)
at org.apache.catalina.startup.Catalina.start(Catalina.java:576)
... 6 more



working server.xml:


NOT working server.xml



my class
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
I'd start by looking at which object is null, and what the code that throws the exception is doing; that may provide a clue for further investigation.


Ping & DNS - my free Android networking tools app
Yacov Wolfowicz
Greenhorn

Joined: Feb 18, 2010
Posts: 4
Thanks for the reply.

I put a breakpoint at the constructor of my class and never get there, so i suspect something in the configuration is broken, which i cannot see. Or, am I missing something else?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
By "code" I meant the Tomcat code, since that's where the exception originates.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15961
    
  19

It is certainly possible to subclass JDBCRealm. I've got one I wrote that allows for case-insensitive userids, since the standard JDBCRealm doesn't support this common convention.

You can set up a general intercept for NullPointerException if you're using Eclipse/RAD as your debugger. This isn't always the best solution, since some apps throw and catch exceptions internally and thus may bury you in spurious breakpoints. However, I think Tomcat's fairly clean in that regard these days.

You might also want to just browse Tomcat's source code for the org.apache.catalina.startup.Catalina class and see what objects are being worked with near line 616. It might give you an idea on what objects of your own need checking.


Customer surveys are for companies who didn't pay proper attention to begin with.
Yacov Wolfowicz
Greenhorn

Joined: Feb 18, 2010
Posts: 4
a week went by....

I still can't figure out what's wrong with my configuration. I'll take the chance of appearing stupid, and ask the stupid question:
The class I'm implementing is actually part of the servlet. Should I make it a "library" class for Apache?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
Tim and I both suggested to take a look at the Tomcat source code around the line where the exception is thrown; did you do that?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15961
    
  19

Yacov Wolfowicz wrote:a week went by....

I still can't figure out what's wrong with my configuration. I'll take the chance of appearing stupid, and ask the stupid question:
The class I'm implementing is actually part of the servlet. Should I make it a "library" class for Apache?


That's not a configuration problem. The Realms are not part of the webapps. They're part of the container environment, so they're on a different classpath than any of the webapps. Meaning that the Realm class can't find classes in any of the WARs. Each webapp has its own unique classpath consisting of the J2EE environment plus the WEB-INF/classes and the contents of the jars in WEB-INF/lib, but nothing outside that particular webapp shares that classpath. And security is outside all webapps.

Which is why it's called container-based security!
Yacov Wolfowicz
Greenhorn

Joined: Feb 18, 2010
Posts: 4
So, If I'm following you right, I should place the CustomRealm.class, somewhere in Tomcat's classpath, right?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15961
    
  19

Yacov Wolfowicz wrote:So, If I'm following you right, I should place the CustomRealm.class, somewhere in Tomcat's classpath, right?


Yup. Best results are if you just jar it all up and place it in the Tomcat server lib directory, same as you would for pooled database drivers and such.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding JDBCRealm
 
Similar Threads
Problems with EJB Local and using servlets - null pointers
Confused about Life cycle of Servlets
Want to Edit cells in a JTable
phone listener is not working properly
Removing Objects from a Custom Layout