tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Wishnie" <>
Subject HELP--Programmatically accessing the UserDatabase?
Date Sat, 14 Sep 2002 01:11:17 GMT
Tomcat: 4.1.10
JDK: 1.4.0
OS: Redhat 7.2


I have a vanilla Tomcat config (pretty much the example server.xml that ships with 1.4.10)
and am using the UserDatabaseRealm in
conjunction with the tomcat-users file for authentication.

This works fine, but now I want to programmatically access the Userdatabase to get some info
in one of my servlets.

I read through the JNDI How-to and it seems to me that what I'm doing should work, but the
resource can't be found at runtime.

Any help would be greatly appreciated.

Here are relevent sections of code/config:

Server XML
        <!-- Editable user database that can also be used by
        UserDatabaseRealm to authenticate users -->
        <Resource name="UserDatabase" auth="Container"
            description="User database that can be updated and saved">
        <ResourceParams name="UserDatabase">


 <!-- realm, defined as default for me Engine -->

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                debug="0" resourceName="UserDatabase"/>

Code in servlet
 try {
            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            UserDatabase udb = (UserDatabase) envCtx.lookup("UserDatabase");

            Iterator it=udb.getUsers();
            User use=null;
            while (it.hasNext()) {
        } catch (NamingException nameEx) {
            // log error

Exception generated
javax.naming.NameNotFoundException: Name UserDatabase is not bound in this Context
        at org.apache.naming.NamingContext.lookup(
        at org.apache.naming.NamingContext.lookup(


- Jeff

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message