I currently work in a project where each user has his own schema in Oracle 11g DB. This design was done because all the security roles and privileges to access the Oracle tables are stored in the DB. Our team is trying to figure how to do this in the cool Play! framework. Any suggestions?
As far as I understand, you can try wrap a value of DB.datasource with something like this (where currentUser() and currentPassword() should return the credentials of the current user who makes a request):
public class DataSourceWrapper {
private DataSource original;
public DataSourceWrapper(DataSource original) {
this.original = original;
}
public Connection getConnection() {
return original.getConnection(currentUser(), currentPassword());
}
...
public DataSource getOriginal() {
return original;
}
}
Replacement of DB.datasource should happen between execution of onApplicationStart() methods of DB and JPA plugins, so that you need to create a custom plugin:
public class DataSourceReplacementPlugin extends PlayPlugin {
public void onApplicationStart() {
DB.datasource = new DataSourceWrapper(DB.datasource);
}
public void onApplicationStop() {
if (DB.datasource instanceof DataSourceWrapper) {
DB.datasource = ((DataSourceWrapper) DB.datasource).getOriginal();
}
}
}
and register in with the appropriate priority level in conf/play.plugins:
350: DataSourceReplacementPlugin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With