• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Bartender
Posts: 20841
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sin pillai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 20841
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!