Bug 44162 - Problem getting GlobalNamingResources DataSource DBCP from Custom JAAS
Summary: Problem getting GlobalNamingResources DataSource DBCP from Custom JAAS
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.14
Hardware: PC Windows XP
: P2 critical (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords: ErrorMessage
Depends on:
Blocks:
 
Reported: 2008-01-03 00:08 UTC by Mariano Lopez
Modified: 2008-01-03 11:51 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mariano Lopez 2008-01-03 00:08:42 UTC
I am trying to implement a custom JAAS login module for tomcat 6.0.14 that is
working now over 5.5.25.

This configuration works perfectly on tomcat 5.5.25 but not over 6.0.14.

I think the problem is with accesing JNDI objects out of context without
ResourceLink element. I need to access this way from LoginModule implementation.

The configuration is the following:

server.xml:

  <Server port="9085" shutdown="SHUTDOWN">
  ....
	<GlobalNamingResources>
	    <Resource name="jdbc/dataSource_usuarios_aplicaciones_Local" 
	              auth="Container"
	              type="javax.sql.DataSource"
	              driverClassName="com.mysql.jdbc.Driver" 
                   factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" 
	              maxActive="20" maxIdle="10" maxWait="30000" 
	              minEvictableIdleTimeMillis="30000" 
	              username="----" 
	              password="----" 
	              testOnBorrow="true" 
	              testWhileIdle="true" 
	              timeBetweenEvictionRunsMillis="10000" 
url="jdbc:mysql://localhost:3306/usuarios_aplicaciones?autoReconnectForPools=true&amp;connectTimeout=30000"
	              validationQuery="SELECT 1" />
	  </GlobalNamingResources>
	....
	....
	<Engine name="Catalina" defaultHost="localhost">
		...
		<Realm className="org.apache.catalina.realm.JAASRealm" 
		             resourceName="jdbc/dataSource_usuarios_aplicaciones_Local"
		             appName="UsuariosAplicaciones" 
		            
userClassNames="org.sescam.chua.AutenticacionTomcatChua.UsuarioChuaLDAP"
		            
roleClassNames="org.sescam.chua.AutenticacionTomcatChua.GrupoChuaPrincipal"/>
		...
	</Engine>
  ....
  </Server>

The class that implements 'LoginModule' interface has the following code in
initialize method:

  DataSource dataSourceSQL = null;
  try {
    Context ctx = new InitialContext();
    Context envContext = (Context) ctx.lookup("java:comp/env");
    dataSourceSQL = (DataSource) 
          envContext.lookup("jdbc/dataSource_usuarios_aplicaciones_Local");
    LoginModuloChua.entidadesDAO = new EntidadesDAO(dataSourceSQL);
  } catch (NamingException ex) {
    LoginModuloChua.entidadesDAO = null;
    log_ERROR("Se ha producido una NamingException con " +
              "nombreJndiDBCP: '" + this.nombreJndiDBCP + "' en " +
              "'initialize' -> iniciando 'entidadesDAO': " +
              ex.getMessage());
    ex.printStackTrace();
  }

And always throws the following exception:

  javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
Comment 1 Mark Thomas 2008-01-03 11:51:16 UTC
You are not obtaining the initial context correctly for a realm that is not
inside a context. As per my users list response, look at the DataSourceRealm code.