removed hardcoded usuage of database user and password and allow this to be configured/changed in tenants table for each possible tenant.
This commit is contained in:
+8
-2
@@ -27,7 +27,9 @@ public class JdbcTenantDetailsService implements TenantDetailsService {
|
||||
|
||||
try {
|
||||
TenantMapper rm = new TenantMapper();
|
||||
String sql = "select id, name, schema_name as schemaName from tenants t where t.identifier like ?";
|
||||
String sql = "select id, name, schema_name as schemaName, schema_server as schemaServer, schema_server_port as schemaServerPort, " +
|
||||
" schema_username as schemaUsername, schema_password as schemaPassword " +
|
||||
" from tenants t where t.identifier like ?";
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {tenantIdentifier});
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
@@ -43,8 +45,12 @@ public class JdbcTenantDetailsService implements TenantDetailsService {
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
String schemaName = rs.getString("schemaName");
|
||||
String schemaServer = rs.getString("schemaServer");
|
||||
String schemaServerPort = rs.getString("schemaServerPort");
|
||||
String schemaUsername = rs.getString("schemaUsername");
|
||||
String schemaPassword = rs.getString("schemaPassword");
|
||||
|
||||
return new MifosPlatformTenant(id, name, schemaName);
|
||||
return new MifosPlatformTenant(id, name, schemaName, schemaServer, schemaServerPort, schemaUsername, schemaPassword);
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
-2
@@ -5,11 +5,20 @@ public class MifosPlatformTenant {
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String schemaName;
|
||||
private final String schemaServer;
|
||||
private final String schemaServerPort;
|
||||
private final String schemaUsername;
|
||||
private final String schemaPassword;
|
||||
|
||||
public MifosPlatformTenant(Long id, String name, String schemaName) {
|
||||
public MifosPlatformTenant(final Long id, final String name, final String schemaName,
|
||||
final String schemaServer, final String schemaServerPort, final String schemaUsername, final String schemaPassword) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.schemaName = schemaName;
|
||||
this.schemaServer = schemaServer;
|
||||
this.schemaServerPort = schemaServerPort;
|
||||
this.schemaUsername = schemaUsername;
|
||||
this.schemaPassword = schemaPassword;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@@ -23,4 +32,20 @@ public class MifosPlatformTenant {
|
||||
public String getSchemaName() {
|
||||
return schemaName;
|
||||
}
|
||||
}
|
||||
|
||||
public String getSchemaServer() {
|
||||
return schemaServer;
|
||||
}
|
||||
|
||||
public String getSchemaServerPort() {
|
||||
return schemaServerPort;
|
||||
}
|
||||
|
||||
public String getSchemaUsername() {
|
||||
return schemaUsername;
|
||||
}
|
||||
|
||||
public String getSchemaPassword() {
|
||||
return schemaPassword;
|
||||
}
|
||||
}
|
||||
+11
-3
@@ -47,12 +47,20 @@ public class TomcatJdbcDataSourcePerTenantService implements DataSourcePerTenant
|
||||
|
||||
private DataSource createNewDataSourceFor(final MifosPlatformTenant tenant) {
|
||||
// see http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency
|
||||
|
||||
StringBuilder jdbcUrlBuilder = new StringBuilder("jdbc:mysql://")
|
||||
.append(tenant.getSchemaServer())
|
||||
.append(':')
|
||||
.append(tenant.getSchemaServerPort())
|
||||
.append('/')
|
||||
.append(tenant.getSchemaName());
|
||||
|
||||
PoolConfiguration poolConfiguration = new PoolProperties();
|
||||
poolConfiguration.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
poolConfiguration.setName(tenant.getSchemaName() + "_pool");
|
||||
poolConfiguration.setUrl("jdbc:mysql://localhost:3306/" + tenant.getSchemaName());
|
||||
poolConfiguration.setUsername("root");
|
||||
poolConfiguration.setPassword("mysql");
|
||||
poolConfiguration.setUrl(jdbcUrlBuilder.toString());
|
||||
poolConfiguration.setUsername(tenant.getSchemaUsername());
|
||||
poolConfiguration.setPassword(tenant.getSchemaPassword());
|
||||
|
||||
poolConfiguration.setInitialSize(5);
|
||||
poolConfiguration.setMaxActive(5);
|
||||
|
||||
Reference in New Issue
Block a user