Thanks for you answer Chris,
i will try to provide you more details. 
Initially i was using just one Datasource object to connect my application
to an IBM DB2 database.
I preferred to use the Datasource solution instead the DriverManger one for
the connection pooling support provided by tomcat.

Then i was looking for a solution in order to connect to the DB2 database
using differente user credentials (that because i need to design a security
model at db level).

Normally, when you define a tomcat <Resource> element of type
javax.xml.DataSource, tomcat instantiates a BasicDatasource. But the
BasicDatasource object does not support the operation
getConnection(user,pass). 

After looking for that soultion i found the class PerUserPoolDataSource. 
The tomcat's website describes how to deploy a PerUserPoolDataSource
datasource. 

I followed all the instructions but the lookup method of the context object
returned me always null. 

That's why i decided to define a <Resource> element for each user role. 

Have you ever succeeded in using the PerUserPoolDataSource? Do you think
there are other solutions to connect to the database using different users?

thanks again,

Claudio



Christopher Schultz-2 wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Claudio,
> 
> On 5/13/2009 12:35 PM, Claudio80 wrote:
>> I need to access to a DB2 database using those 3 different roles in order
>> to
>> limite the access to some tables' rows. 
>> So i tried to use the PerUserPerUserPoolDataSource in order to use the
>> method getConnection(user,pass) not provided in the BasicDataSource but i
>> got some problem.
> 
> Would you like to post the details of that problem, and maybe we can
> help? I personally wouldn't use this approach since IIRC it requires a
> separate database connection for /each user/, rather than using roles to
> determine which type of connection you get.
> 
>> So i decided to define 3 Resource element in the context.xml (one for
>> each
>> role) and when i need to create a specific datasource based on the role i
>> use cxt.lookup( "jdbc/" + roleName )
>> 
>> I have 2 question:
>> 
>> 1) Do you think it is a good solution
> 
> Looks good to me.
> 
>> 2) It is better have a DAO object with a list of datasource or a list of
>> DAO
>> objects (one for each DataSource)
> 
> I would do neither. I would have your DAO accept a java.sql.Connection
> object OR the JNDI name under which the DataSource can be found. You can
> pass that information either via a parameter to some method like
> getProductById(String dataSourceName, Integer id) or by using a
> ThreadLocal so you don't pollute your method signatures.
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAkoSsXkACgkQ9CaO5/Lv0PC48gCdE8hLDZEup0rAh9fGghT6plaS
> QhEAn2wP0xtU2Za3FBUZc4K/83JfPHOX
> =+VC6
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Different-resources-for-different-user-roles-tp23525487p23618942.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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

Reply via email to