You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Allistair Crossley <Al...@QAS.com> on 2006/03/24 12:57:24 UTC

Tomcat 5.5 DataSourceRealm

Hi All,

I've failed miserably in configuring a DataSourceRealm for a web
application. I've scoured Google (50/50), mailing list archives (ask a
friend), and not to much avail. I've also liased with the Tomcat 5.5
documentation as far as I can tell.

So I turn to "ask the audience" ;)

I am using the Realm method described in the docu as "Inside a <Context>
element - This Realm will be used ONLY for THIS web application."

Before this I tried out my security web.xml declarations with the simple
tomcat-users UserDatabase and this worked fine. Now I want to get it
working with database tables.

I configure my web app Context a la META-INF/context.xml

My DataSources are working fine and have been for a good while. The main
one, inside the context.xml is

	<Resource 
		name="jdbc/web" 
		auth="Container" 
		driverClass="net.sourceforge.jtds.jdbc.Driver" 
		minPoolSize="5" maxPoolSize="10" 
		acquireIncrement="1" 
		user="user" password="pass" 
		factory="org.apache.naming.factory.BeanFactory" 
		type="com.mchange.v2.c3p0.ComboPooledDataSource" 
	
jdbcUrl="jdbc:jtds:sqlserver://intratest:1433/dbWeb;charset=Cp1252" 
	/> 

And I have my web.xml

	<resource-ref>
		<description>Web Database</description>
		<res-ref-name>jdbc/web</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>

So, I've created my Realm tables and so on in my database (the same one
pointed to by the above Resource).

I declare in the context.xml file

	<Realm 
	  className="org.apache.catalina.realm.DataSourceRealm" 
	  dataSourceName="jdbc/web"
        userTable="tblUsers" 
        userRoleTable="tblUserRoles" 
        userNameCol="user_name"
        userCredCol="user_pass"
        roleNameCol="role_name" 
	/>	

I fire up Tomcat and it does not seem to have too much trouble until I
try and login.

2006-03-24 11:43:07,578 - ERROR
(org.apache.catalina.realm.DataSourceRealm:405) - Exception performing
authentication
javax.naming.NameNotFoundException: Name jdbc is not bound in this
Context
	at
org.apache.naming.NamingContext.lookup(NamingContext.java:769)
	at
org.apache.naming.NamingContext.lookup(NamingContext.java:152)
	at
org.apache.catalina.realm.DataSourceRealm.open(DataSourceRealm.java:401)

I recognise the "Name jdbc is not bound in this Context" from the days
of migrating from Tomcat 5.0 to 5.5 due to the new format for defining
Resource elements. However, that's an old story that I figured out eons
ago, my DataSource Resources are proven and work. I therefore do not
believe this to be a DataSource config or driver problem.

It seems to me like the datasources are simply _not ready_ by the time
the Realm element is processed? Could this be the case? Or am I simply
not seeing something obvious (quite possible :))

Your help appreciated,

Allistair



<FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE> 
-------------------------------------------------------
QAS Ltd.
Registered in England: No 2582055
Registered in Australia: No 082 851 474
-------------------------------------------------------
</FONT> <FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLACK> 
Disclaimer:  The information contained within this e-mail is confidential and may be privileged. This email is intended solely for the named recipient only; if you are not authorised you must not disclose, copy, distribute, or retain this message or any part of it. If you have received this message in error please contact the sender at once so that we may take the appropriate action and avoid troubling you further.  Any views expressed in this message are those of the individual sender.  QAS Limited has the right lawfully to record, monitor and inspect messages between its employees and any third party.  Your messages shall be subject to such lawful supervision as QAS Limited deems to be necessary in order to protect its information, its interests and its reputation.  

Whilst all efforts are made to safeguard Inbound and Outbound emails, QAS Limited cannot guarantee that attachments are virus free or compatible with your systems and does not accept any liability in respect of viruses or computer problems experienced.
</FONT>


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