tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Wishnie" <j...@deluxebiz.com>
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


Hi,

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
------------------
<GlobalNamingResources>
        <!-- Editable user database that can also be used by
        UserDatabaseRealm to authenticate users -->
        <Resource name="UserDatabase" auth="Container"
            type="org.apache.catalina.UserDatabase"
            description="User database that can be updated and saved">
        </Resource>
        <ResourceParams name="UserDatabase">
            <parameter>
                <name>factory</name>
                <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
            </parameter>
            <parameter>
                <name>pathname</name>
                <value>conf/tomcat-users.xml</value>
            </parameter>
        </ResourceParams>
    </GlobalNamingResources>

 ...

 <!-- 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()) {
                use=(User) it.next();
             }
        } catch (NamingException nameEx) {
            // log error
        }


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


Thanks!!

- Jeff


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message