2

I have written an application using java, camel, spring, shiro, c3p0 and jpa. This application needs to connect to some web services and some db and it has now a static configuration using classic spring propertyplaceholders and .prop property files. I inject properties in java classes using @Value annotations and I define datasources using spring with ${} placeholders. In the configuration there are url,username,password for web services and database,url,username,password for datasource.

Now I need to do a dynamic/multi tenant configuration. I mean that each "customer" can have his set of passwords and that these login/passwords can change over time. Using shiro I can add to the Subject some data, so I can add current properties to it and get them where I need. But how can I continue to use @value annotations? And, most important question, how can I change datasources parameters at runtime? I see in c3p0 documentation that using getConnection(username,password) with a new pair of username and password creates a new pool and close the old. But I do not use getConnection because only the EntityManager uses datasource.

Please help me! Thanks, Mario

After a lot of searching I think I can do in this way:

  • for properties use DynamicCombinedConfiguration from commons configuration, but I do not know how to tell it to read the tenant id from Shiro Subject
  • for JPA use AbstractDataSource from spring, but again I do not know if I can read the tenant id from Shiro Subject

Can you tell me if I am pointing in the right direction?

Thanks again, Mario

mgiammarco
  • 371
  • 5
  • 16

0 Answers0