tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Stewart <SStew...@csky.com>
Subject RE: JNDI DataSource Realm
Date Wed, 13 Aug 2003 21:26:40 GMT
I posted this awhile back (for MySQL), but here it is again.  Also, when you
define your DataSource in this manner, you do not need the <resource-ref>
node in your context-specific web.xml files.


    The global DataSource definition
    --------------------------------

        <!-- Global JNDI resources -->
        <GlobalNamingResources>

            <!-- Editable user database that can also be used by JNDI
DatabaseRealm to authenticate users -->
            <Resource name="jdbc/MySQLConnectPool" 
                      auth="Container" 
                      type="javax.sql.DataSource" />

            <ResourceParams name="jdbc/MySQLConnectPool" >
			
                <parameter>
                    <name>username</name>
                    <value>????????</value>
                </parameter>

                <parameter>
                    <name>password</name>
                    <value>????????</value>
                </parameter>

                <parameter>
                    <name>driverClassName</name>
                    <value>com.mysql.jdbc.Driver</value>
                </parameter>

                <parameter>
                    <name>url</name>
                    <value>jdbc:mysql://<your IP here>:3306/<your DB name
here>?autoReconnect=true</value>
                </parameter>
				
                <parameter>
                    <name>removeAbandoned</name>
                    <value>true</value>
                </parameter>
				
                <parameter>
                    <name>removeAbandonedTimeout</name>
                    <value>60</value>
                </parameter>
				
                <parameter>
                    <name>logAbandoned</name>
                    <value>true</value>
                </parameter>
				
                <parameter>
                    <name>maxActive</name>
                    <value>200</value>
                </parameter>
				
                <parameter>
                    <name>maxIdle</name>
                    <value>30000</value>
                </parameter>
				
                <parameter>
                    <name>maxWait</name>
                    <value>100</value>
                </parameter>
				
            </ResourceParams>

        </GlobalNamingResources>


    Realm definition using global DataSource
    ----------------------------------------

        <Realm  
            className="org.apache.catalina.realm.DataSourceRealm" 
            dataSourceName="jdbc/MySQLConnectPool"
            userTable="customers" 
            userNameCol="customer_username" 
            userCredCol="customer_password"
            userRoleTable="roles" 
            roleNameCol="role" 
            debug="0"
        />


    Context reference to global DataSource
    --------------------------------------

        <ResourceLink name="jdbc/MySQLConnectPool"
                      global="jdbc/MySQLConnectPool"
                      type="javax.sql.DataSource" />
						  

Hope this helps!!

Thanks,

Scott Stewart
[Manager, Software Development]
SStewart@csky.com

ClearSky Mobile Media, Inc.
56 E. Pine St. Suite 200
Orlando, FL 32801
USA



-----Original Message-----
From: Madere, Colin [mailto:colin.madere@ieminc.com] 
Sent: Wednesday, August 13, 2003 5:17 PM
To: 'Tomcat Users List'
Subject: JNDI DataSource Realm


Tomcat 4.1.27
PostgreSQL 7.3.4
pg73jdbc3.jar

Trying to use JNDI as a Realm source for both auth and data access for a
whole server, therefore trying as a GlobalNamingContext attribute.  No love.

* Set up as a JDBC Realm, auth works.
* Set up Datasource as JNDI Resource within <DefaultContext>, data access
works.

Move <Resource> and params to <GlobalNamingContext> and I get the "Name jdbc
is not bound in this Context" error.  Saw lots of refs to this error via
Google, but none relevant AFAICT.  (Do I look up resources in the global
context differently?  If so doesn't that kind of break the idea of it being
an abstractly defined data source?)

Anyone successfully using <GlobalNamingContext> for DataSources? Using these
components (Tomcat 4.1.x, postgreSQL)?

Change Realm from JDBC to DataSourceRealm and auth does not work (or report
any errors in logs).

server.xml (with DataSourceRealm commented out)

<Server port="8005" shutdown="SHUTDOWN" debug="0">

  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
            debug="0"/>
  <Listener
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
            debug="0"/>

  <!-- Global JNDI resources -->
  <GlobalNamingResources>

  </GlobalNamingResources>

  <!-- Define the Tomcat Stand-Alone Service -->
  <Service name="Tomcat-Standalone">

    <!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8080" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="100" debug="0" connectionTimeout="20000"
               useURIValidationHack="false" disableUploadTimeout="true" />
    <!-- Note : To disable connection timeouts, set connectionTimeout value
     to -1 -->

    <!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8009" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="0"
               useURIValidationHack="false"
 
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>

    <!-- Define the top level container in our container hierarchy -->
    <Engine name="Standalone" defaultHost="localhost" debug="0">

      <!-- Global logger unless overridden at lower levels -->
      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="catalina_log." suffix=".txt"
              timestamp="true"/>

      <!-- Because this Realm is here, an instance will be shared globally
-->
      <!--
      <Realm className="org.apache.catalina.realm.DataSourceRealm"
debug="99"
             dataSourceName="java:/comp/env/jdbc/Auth"
             userTable="Account" userNameCol="username"
userCredCol="password"
             userRoleTable="AccountRole" roleNameCol="role_name"/>
      -->

      <Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
            driverName="org.postgresql.Driver"
         connectionURL="jdbc:postgresql://localhost/www_auth"
        connectionName="www"
             userTable="Account" userNameCol="username"
userCredCol="password"
         userRoleTable="AccountRole" roleNameCol="role_name"/>

      <!-- Define the default virtual host -->
      <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true"
autoDeploy="true">

        <Valve className="org.apache.catalina.authenticator.SingleSignOn"
debug="0"/>

        <Logger className="org.apache.catalina.logger.FileLogger"
directory="logs"
                   prefix="localhost_log." suffix=".txt" timestamp="true"/>
        <!--
          <Context path="" docBase="ROOT" debug="0"/>
        -->
        <DefaultContext>
          <Resource name="jdbc/Auth" auth="Container"
type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/Auth">
            <parameter>
              <name>factory</name>
              <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
            </parameter>
            <parameter>
              <name>maxActive</name>
              <value>100</value>
            </parameter>
            <parameter>
              <name>maxIdle</name>
              <value>30</value>
            </parameter>
            <parameter>
              <name>maxWait</name>
              <value>10000</value>
            </parameter>
            <parameter>
              <name>username</name>
              <value>www</value>
            </parameter>
            <parameter>
              <name>password</name>
              <value></value>
            </parameter>
            <parameter>
              <name>driverClassName</name>
              <value>org.postgresql.Driver</value>
            </parameter>
            <parameter>
              <name>url</name>
              <value>jdbc:postgresql://localhost/www_auth</value>
            </parameter>
          </ResourceParams>
        </DefaultContext>
      </Host>
    </Engine>
  </Service>
</Server>

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

Mime
View raw message