I am trying to configure tomcat to provide a JNDI Datasource, both so that the container can provide Basic Authentication, and for the war file to use (via Torque).
I have done this (including Torque!). It took a bit of playing around, but I found that I had to do the following.
(Others please take note: I'd like to know if I could have gotton away with fewer steps... please let me know if that's the case)
1. Define a <Resource> in the <GlobalNamingResources> section of server.xml:
<Resource name="@DATASOURCE_REF@" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="@DATASOURCE_REF@"> ... </ResourceParams>
(I'm using ant to replace the DATSOURCE_REF marker with "jdbc/myDataSource").
I have deduced that Tomcat requires this to be defined at the global level because of where the authenticator runs -- which appears to be *outside* the context for which you want to authenticate users.
2. Put your <Realm> inside the <Context> for which you want to authenticate:
<Realm className="org.apache.catalina.realm.DataSourceRealm" dataSourceName="@DATASOURCE_REF@" userTable="user" userRoleTable="user_role" userNameCol="username" userCredCol="password" roleNameCol="rolename" digest="MD5" debug="99" />
Somewhat obviously, this sets up the Realm and allows the authentication to take place.
3. Add a <ResourceLink> to the <Context> section for my particular context:
<ResourceLink name="@DATASOURCE_REF@" global="@DATASOURCE_REF@" type="javax.sql.DataSource" />
This links a global resource to the context, and makes it available for use by the webapp.
4. Add a <resource-ref> section to my web.xml:
<resource-ref> <description>DataSource for my application</description> <res-ref-name>jdbc/myDataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
I think this actually creates the "other side" of the link that it established with the <ResourceLink> in the server.xml. I'm not entirely sure.
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
I was getting this same error and played around for the better part of two days to get this working.
Finally, I can do all of these things:
1. Use the Realm the way I want to 2. Have Torque use the same JNDI DataSource
(Just so you know, this is what I use for my torque JNDI setup: [EMAIL PROTECTED]@.jndi.path=java:comp/env/@DATASOURCE_REF@ )
3. Browse the JNDI tree by hand (from a JSP within my context) and actually see the DataSource object in there.
Woo hoo!
I hope that helps.
-chris
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]