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 Can you bind new objects to JNDI in Tomcat using InitialContext ? 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 "Can you bind new objects to JNDI in Tomcat using InitialContext ?" Watch "Can you bind new objects to JNDI in Tomcat using InitialContext ?" New topic
Author

Can you bind new objects to JNDI in Tomcat using InitialContext ?

sin pillai
Greenhorn

Joined: Mar 30, 2010
Posts: 5
In a recent meeting regarding JNDI, everybody in my team mentioned that Tomcat provides "read-only" access to JNDI via InitialContext.

I did a small POC in tomcat 7,

Context jndiContext = new InitialContext();
jndiContext.bind("test",new String("TESTJNDI"));


and then did a lookup opening a new InitialContext ..and was able to obtain that String back.

I am little confused now.

Appreciate any explanation or clarification.

thanks !
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

Last time I tried was a long time ago, and my attempt bounced.

Because the Tomcat JNDI registry is primarily used for configuration information, the ability to add/update entries could potentially cause trouble, so to be conservative, I'd avoid doing so. However, one thing you might do is see if you can add elements to the "java:comp/env" directory tree. It's possible that that section is protected, since that's where the critical data is, while other trees might be safe.

I would, however, check the JEE spec and see what (if anything) it has to say on applications updating JNDI. In the final analysis, what you can do versus what you should do is critical. People used to alter incoming parameters from Httpservlet requests, but that wasn't supported by the spec and one day Tomcat started adhering more closely to the spec, the offending apps broke, and the "clever" people had no one to blame but themselves. Same thing applies to people who write data files to their WARs, only in that particular case, I can break existing apps just by changing the Tomcat deployment configuration.


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

Joined: Mar 30, 2010
Posts: 5
Thanks Tim. By the way, nicely said about can-do vs should-do.
I tried binding the object to java:comp/env tree and now Tomcat woke and complained about "Context is read-only"


Out of curiosity, when you do not specify JNDI tree location and just do new IntialContext() and then bind("test",new String("TESTJNDI"));
which location in directory tree is the object bound to?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

I would expect that "test" would bind to the context root. Might be interesting to see if you can create directories, though. For example "test/data1".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can you bind new objects to JNDI in Tomcat using InitialContext ?
 
Similar Threads
java.lang.ClassCastException when assigning to home interface?
javax.naming.CannotProceedException; remaining name
How to Reuse JDBC connectivity code in other Java programs or classes?
adding bean as a JNDI to tomcat
ClassCastException with JMS.