File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes How can I read my context.xml's JNDIRealm settings dynamically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How can I read my context.xml Watch "How can I read my context.xml New topic

How can I read my context.xml's JNDIRealm settings dynamically?

Michael Brown

Joined: May 05, 2008
Posts: 27

I have a JNDIRealm in my context.xml that connects to Active Directory in order to authorise users in application...

It all works fine.

I'm just wondering if there is a way to read this JNDIRealm settings ( connectionName , connectionPassword and connectionURL ) dynamically from some Java class inside my application...?

For example using something like Context.lookup("MyRealm") and getting it's properties...

I use Tomcat 6.
David Newton

Joined: Sep 29, 2008
Posts: 12617

Moving; this isn't Struts-related.
Michael Brown

Joined: May 05, 2008
Posts: 27
Yes, now that I think about it - you're right...

My application is written using struts2, but this is not Struts2 related question...

My appologies...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950

The actual security infrastructure items won't be visible inside the webapp. Not only would that be a potential security risk (the app user and the app itself could even have different security connections!), but also it wouldn't be possible in a transparent way. One of the great things about security realms is that you can use a tomcat-users.xml file for testing even though the production system is LDAP-authenticated.

However, you CAN set up a system where the info you want is inferred based on the user principal name, using that as an argument to an LDAP search.

The example you cited, however, seems to have more to do with database connections. And like security realms, in J(2)EE, database connections are generally best left completely in the hands of the container. You wouldn't (I hope!) get a different connection for each user! For one thing, it places the DBA in the position of having to duplicate the security team's work for each web application user.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: How can I read my context.xml's JNDIRealm settings dynamically?
Similar Threads
JNDI realm strange problem(Tomcat 6.0.16)
user roles shared between application
How to setup Realm in WebSphere like tomcat?
How to configure Tomcat for authentication against Active Directory of Windows Server 2003
How to get user credentials from LDAP using Apache Tomacet JNDIRealm