Igor  Masternoy
Igor Masternoy

Reputation: 436

Spring using different DataSource that depends on user

I have web application and i use Spring MVC. Now i'd like to add to different dataSources for administrator and for simple user. So my application should connect through anonymous user to DB, that can only select from tables and insert into some tables. But when user authorize himself by admin - application should change user and password on DB connection and connect with root authorities to DB. Is it possible to do this with spring 3.0.5?

Upvotes: 0

Views: 388

Answers (1)

Jose Luis Martin
Jose Luis Martin

Reputation: 10709

Try with

org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter

you can set the credentials on the Datasource via setCredentialsForCurrentThread() method in the login filter, for example.

Upvotes: 1

Related Questions