You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Claudio80 <cl...@gmail.com> on 2009/05/13 18:35:52 UTC

Different resources for different user roles

Hi All,

I have a web application that communicate with a  DB2 Database. 
There are multiple users that need to authenitcate them before using the
application.
Each user has just a role and the are 3 roles.
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.

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
2) It is better have a DAO object with a list of datasource or a list of DAO
objects (one for each DataSource)

Thanks in advance,

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


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


Re: Different resources for different user roles

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Claudio,

On 5/19/2009 11:42 AM, Claudio80 wrote:
> 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. 

This is an indication that your setup is incorrect. Where is the
PerUserPoolDataSource.class file in your setup?

> 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?

No, I've never even tried to do this. I just use JOINs to make sure that
my users have access to appropriate data.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkoS3YkACgkQ9CaO5/Lv0PDBzgCfSqpEuLQkVXxQYEB6OIzAtmdN
qFMAoKBbSbAEx4ApWPm5EfMejUuZVKnV
=8Y8Q
-----END PGP SIGNATURE-----

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


Re: Different resources for different user roles

Posted by Claudio80 <cl...@gmail.com>.
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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Different resources for different user roles

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org