remm        2004/01/29 02:47:39

  Modified:    catalina/src/share/org/apache/catalina/realm
                        DataSourceRealm.java mbeans-descriptors.xml
  Log:
  - Add localDataSource flag, based on code submitted by Neil Katin.
  - Bug 25805.
  
  Revision  Changes    Path
  1.5       +38 -7     
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java
  
  Index: DataSourceRealm.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DataSourceRealm.java      26 Jan 2004 19:47:16 -0000      1.4
  +++ DataSourceRealm.java      29 Jan 2004 10:47:39 -0000      1.5
  @@ -74,6 +74,7 @@
   import javax.naming.Context;
   import javax.sql.DataSource;
   
  +import org.apache.naming.ContextBindings;
   import org.apache.catalina.LifecycleException;
   import org.apache.catalina.ServerFactory;
   import org.apache.catalina.core.StandardServer;
  @@ -125,6 +126,12 @@
   
   
       /**
  +     * Context local datasource.
  +     */
  +    protected boolean localDataSource = false;
  +
  +
  +    /**
        * Descriptive information about this Realm implementation.
        */
       protected static final String name = "DataSourceRealm";
  @@ -188,6 +195,23 @@
       }
   
       /**
  +     * Return if the datasource will be looked up in the webapp JNDI Context.
  +     */
  +    public boolean getLocalDataSource() {
  +        return localDataSource;
  +    }
  +
  +    /**
  +     * Set to true to cause the datasource to be looked up in the webapp JNDI
  +     * Context.
  +     *
  +     * @param localDataSource the new flag value
  +     */
  +    public void setLocalDataSource(boolean localDataSource) {
  +      this.localDataSource = localDataSource;
  +    }
  +
  +    /**
        * Return the column in the user role table that names a role.
        *
        */
  @@ -446,10 +470,17 @@
       private Connection open() {
   
           try {
  -            StandardServer server = (StandardServer) ServerFactory.getServer();
  -            Context context = server.getGlobalNamingContext();
  +            Context context = null;
  +            if (localDataSource) {
  +                context = ContextBindings.getClassLoader();
  +                context = (Context) context.lookup("comp/env");
  +            } else {
  +                StandardServer server = 
  +                    (StandardServer) ServerFactory.getServer();
  +                context = server.getGlobalNamingContext();
  +            }
               DataSource dataSource = (DataSource)context.lookup(dataSourceName);
  -            return dataSource.getConnection();
  +         return dataSource.getConnection();
           } catch (Exception e) {
               // Log the problem for posterity
               log(sm.getString("dataSourceRealm.exception"), e);
  
  
  
  1.3       +4 -0      
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/mbeans-descriptors.xml
  
  Index: mbeans-descriptors.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/mbeans-descriptors.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- mbeans-descriptors.xml    10 Nov 2003 20:00:50 -0000      1.2
  +++ mbeans-descriptors.xml    29 Jan 2004 10:47:39 -0000      1.3
  @@ -21,6 +21,10 @@
                           non-plaintext format"
                    type="java.lang.String"/>
   
  +    <attribute   name="localDataSource"
  +          description="Configures if the DataSource is local to the webapp"
  +                 type="boolean"/>
  +
       <attribute   name="roleNameCol"
             description="The column in the user role table that names a role"
                    type="java.lang.String"/>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to