Don't mix up configs
This commit is contained in:
@@ -43,6 +43,10 @@ public class GoogleFirebaseBackend {
|
||||
|
||||
GoogleFirebaseBackend(boolean isEnabled, String name, String credsPath, String db) {
|
||||
this.isEnabled = isEnabled;
|
||||
if (!isEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
FirebaseApp fbApp = FirebaseApp.initializeApp(getOpts(credsPath, db), name);
|
||||
fbAuth = FirebaseAuth.getInstance(fbApp);
|
||||
|
@@ -21,18 +21,16 @@
|
||||
package io.kamax.mxisd.backend.sql;
|
||||
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
import io.kamax.mxisd.config.sql.SqlProviderConfig;
|
||||
import org.springframework.stereotype.Component;
|
||||
import io.kamax.mxisd.config.sql.SqlConfig;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@Component
|
||||
public class SqlConnectionPool {
|
||||
|
||||
private ComboPooledDataSource ds;
|
||||
|
||||
public SqlConnectionPool(SqlProviderConfig cfg) {
|
||||
public SqlConnectionPool(SqlConfig cfg) {
|
||||
ds = new ComboPooledDataSource();
|
||||
ds.setJdbcUrl("jdbc:" + cfg.getType() + ":" + cfg.getConnection());
|
||||
ds.setMinPoolSize(1);
|
||||
|
@@ -20,7 +20,9 @@
|
||||
|
||||
package io.kamax.mxisd.backend.sql;
|
||||
|
||||
import io.kamax.matrix.MatrixID;
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.sql.SqlConfig;
|
||||
import io.kamax.mxisd.config.sql.SqlProviderConfig;
|
||||
import io.kamax.mxisd.controller.directory.io.UserDirectorySearchResult;
|
||||
import io.kamax.mxisd.directory.IDirectoryProvider;
|
||||
@@ -28,8 +30,6 @@ import io.kamax.mxisd.exception.InternalServerError;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -39,21 +39,18 @@ import java.util.Optional;
|
||||
|
||||
import static io.kamax.mxisd.controller.directory.io.UserDirectorySearchResult.Result;
|
||||
|
||||
|
||||
@Component
|
||||
public class SqlDirectoryProvider implements IDirectoryProvider {
|
||||
public abstract class SqlDirectoryProvider implements IDirectoryProvider {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(SqlDirectoryProvider.class);
|
||||
|
||||
protected SqlProviderConfig cfg;
|
||||
protected SqlConfig cfg;
|
||||
private MatrixConfig mxCfg;
|
||||
|
||||
private SqlConnectionPool pool;
|
||||
|
||||
@Autowired
|
||||
public SqlDirectoryProvider(SqlProviderConfig cfg, MatrixConfig mxCfg, SqlConnectionPool pool) {
|
||||
public SqlDirectoryProvider(SqlConfig cfg, MatrixConfig mxCfg) {
|
||||
this.cfg = cfg;
|
||||
this.pool = pool;
|
||||
this.pool = new SqlConnectionPool(cfg);
|
||||
this.mxCfg = mxCfg;
|
||||
}
|
||||
|
||||
@@ -77,6 +74,7 @@ public class SqlDirectoryProvider implements IDirectoryProvider {
|
||||
|
||||
public UserDirectorySearchResult search(String searchTerm, SqlProviderConfig.Query query) {
|
||||
try (Connection conn = pool.get()) {
|
||||
log.info("Will execute query: {}", query.getValue());
|
||||
try (PreparedStatement stmt = conn.prepareStatement(query.getValue())) {
|
||||
setParameters(stmt, searchTerm);
|
||||
|
||||
@@ -87,7 +85,7 @@ public class SqlDirectoryProvider implements IDirectoryProvider {
|
||||
while (rSet.next()) {
|
||||
processRow(rSet).ifPresent(e -> {
|
||||
if (StringUtils.equalsIgnoreCase("localpart", query.getType())) {
|
||||
e.setUserId("@" + e.getUserId() + mxCfg.getDomain());
|
||||
e.setUserId(new MatrixID(e.getUserId(), mxCfg.getDomain()).getId());
|
||||
}
|
||||
result.addResult(e);
|
||||
});
|
||||
|
@@ -52,9 +52,9 @@ public class SqlThreePidProvider implements IThreePidProvider {
|
||||
private SqlConnectionPool pool;
|
||||
|
||||
@Autowired
|
||||
public SqlThreePidProvider(SqlProviderConfig cfg, MatrixConfig mxCfg, SqlConnectionPool pool) {
|
||||
public SqlThreePidProvider(SqlProviderConfig cfg, MatrixConfig mxCfg) {
|
||||
this.cfg = cfg;
|
||||
this.pool = pool;
|
||||
this.pool = new SqlConnectionPool(cfg);
|
||||
this.mxCfg = mxCfg;
|
||||
}
|
||||
|
||||
|
@@ -37,8 +37,8 @@ public class SynapseSqliteDirectoryProvider extends SqlDirectoryProvider {
|
||||
private SynapseSqlProviderConfig cfg;
|
||||
|
||||
@Autowired
|
||||
public SynapseSqliteDirectoryProvider(SynapseSqlProviderConfig cfg, MatrixConfig mxCfg, SqlConnectionPool pool) {
|
||||
super(cfg, mxCfg, pool);
|
||||
public SynapseSqliteDirectoryProvider(SynapseSqlProviderConfig cfg, MatrixConfig mxCfg) {
|
||||
super(cfg, mxCfg);
|
||||
|
||||
if (StringUtils.equals("sqlite", cfg.getType())) {
|
||||
String userId = "'@' || p.user_id || ':" + mxCfg.getDomain() + "'";
|
||||
|
220
src/main/java/io/kamax/mxisd/config/sql/SqlConfig.java
Normal file
220
src/main/java/io/kamax/mxisd/config/sql/SqlConfig.java
Normal file
@@ -0,0 +1,220 @@
|
||||
package io.kamax.mxisd.config.sql;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class SqlConfig {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(SqlConfig.class);
|
||||
|
||||
public static class Query {
|
||||
|
||||
private String type;
|
||||
private String value;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Type {
|
||||
|
||||
private SqlProviderConfig.Query name = new SqlProviderConfig.Query();
|
||||
private SqlProviderConfig.Query threepid = new SqlProviderConfig.Query();
|
||||
|
||||
public SqlProviderConfig.Query getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SqlProviderConfig.Query name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public SqlProviderConfig.Query getThreepid() {
|
||||
return threepid;
|
||||
}
|
||||
|
||||
public void setThreepid(SqlProviderConfig.Query threepid) {
|
||||
this.threepid = threepid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Auth {
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Directory {
|
||||
|
||||
private Boolean enabled;
|
||||
private SqlProviderConfig.Type query = new SqlProviderConfig.Type();
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public SqlProviderConfig.Type getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(SqlProviderConfig.Type query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Identity {
|
||||
|
||||
private Boolean enabled;
|
||||
private String type;
|
||||
private String query;
|
||||
private Map<String, String> medium = new HashMap<>();
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public Map<String, String> getMedium() {
|
||||
return medium;
|
||||
}
|
||||
|
||||
public void setMedium(Map<String, String> medium) {
|
||||
this.medium = medium;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean enabled;
|
||||
private String type;
|
||||
private String connection;
|
||||
private SqlProviderConfig.Auth auth = new SqlProviderConfig.Auth();
|
||||
private SqlProviderConfig.Directory directory = new SqlProviderConfig.Directory();
|
||||
private SqlProviderConfig.Identity identity = new SqlProviderConfig.Identity();
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void setConnection(String connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public SqlProviderConfig.Auth getAuth() {
|
||||
return auth;
|
||||
}
|
||||
|
||||
public void setAuth(SqlProviderConfig.Auth auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public SqlProviderConfig.Directory getDirectory() {
|
||||
return directory;
|
||||
}
|
||||
|
||||
public void setDirectory(SqlProviderConfig.Directory directory) {
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
public SqlProviderConfig.Identity getIdentity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
public void setIdentity(SqlProviderConfig.Identity identity) {
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
protected abstract String getProviderName();
|
||||
|
||||
public void build() {
|
||||
log.info("--- " + getProviderName() + " Provider config ---");
|
||||
|
||||
if (getAuth().isEnabled() == null) {
|
||||
getAuth().setEnabled(isEnabled());
|
||||
}
|
||||
|
||||
if (getDirectory().isEnabled() == null) {
|
||||
getDirectory().setEnabled(isEnabled());
|
||||
}
|
||||
|
||||
if (getIdentity().isEnabled() == null) {
|
||||
getIdentity().setEnabled(isEnabled());
|
||||
}
|
||||
|
||||
log.info("Enabled: {}", isEnabled());
|
||||
if (isEnabled()) {
|
||||
log.info("Type: {}", getType());
|
||||
log.info("Connection: {}", getConnection());
|
||||
log.info("Auth enabled: {}", getAuth().isEnabled());
|
||||
log.info("Identity type: {}", getIdentity().getType());
|
||||
log.info("Identity medium queries: {}", new Gson().toJson(getIdentity().getMedium()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -20,227 +20,25 @@
|
||||
|
||||
package io.kamax.mxisd.config.sql;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties("sql")
|
||||
@Primary
|
||||
public class SqlProviderConfig {
|
||||
public class SqlProviderConfig extends SqlConfig {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(SqlProviderConfig.class);
|
||||
|
||||
public static class Query {
|
||||
|
||||
private String type;
|
||||
private String value;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Type {
|
||||
|
||||
private Query name = new Query();
|
||||
private Query threepid = new Query();
|
||||
|
||||
public Query getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Query name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Query getThreepid() {
|
||||
return threepid;
|
||||
}
|
||||
|
||||
public void setThreepid(Query threepid) {
|
||||
this.threepid = threepid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Auth {
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Directory {
|
||||
|
||||
private Boolean enabled;
|
||||
private Type query = new Type();
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Type getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(Type query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Identity {
|
||||
|
||||
private Boolean enabled;
|
||||
private String type;
|
||||
private String query;
|
||||
private Map<String, String> medium = new HashMap<>();
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public Map<String, String> getMedium() {
|
||||
return medium;
|
||||
}
|
||||
|
||||
public void setMedium(Map<String, String> medium) {
|
||||
this.medium = medium;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean enabled;
|
||||
private String type;
|
||||
private String connection;
|
||||
private Auth auth = new Auth();
|
||||
private Directory directory = new Directory();
|
||||
private Identity identity = new Identity();
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void setConnection(String connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public Auth getAuth() {
|
||||
return auth;
|
||||
}
|
||||
|
||||
public void setAuth(Auth auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public Directory getDirectory() {
|
||||
return directory;
|
||||
}
|
||||
|
||||
public void setDirectory(Directory directory) {
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
public Identity getIdentity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
public void setIdentity(Identity identity) {
|
||||
this.identity = identity;
|
||||
@Override
|
||||
protected String getProviderName() {
|
||||
return "Generic SQL";
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void build() {
|
||||
log.info("--- SQL Provider config ---");
|
||||
|
||||
if (getAuth().isEnabled() == null) {
|
||||
getAuth().setEnabled(isEnabled());
|
||||
}
|
||||
|
||||
if (getDirectory().isEnabled() == null) {
|
||||
getDirectory().setEnabled(isEnabled());
|
||||
}
|
||||
|
||||
if (getIdentity().isEnabled() == null) {
|
||||
getIdentity().setEnabled(isEnabled());
|
||||
}
|
||||
|
||||
log.info("Enabled: {}", isEnabled());
|
||||
if (isEnabled()) {
|
||||
log.info("Type: {}", getType());
|
||||
log.info("Connection: {}", getConnection());
|
||||
log.info("Auth enabled: {}", getAuth().isEnabled());
|
||||
log.info("Identity type: {}", getIdentity().getType());
|
||||
log.info("Identity medium queries: {}", new Gson().toJson(getIdentity().getMedium()));
|
||||
}
|
||||
super.build();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -20,20 +20,24 @@
|
||||
|
||||
package io.kamax.mxisd.config.sql.synapse;
|
||||
|
||||
import io.kamax.mxisd.config.sql.SqlProviderConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import io.kamax.mxisd.config.sql.SqlConfig;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static io.kamax.mxisd.config.sql.synapse.SynapseSqlProviderConfig.NAMESPACE;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(NAMESPACE)
|
||||
public class SynapseSqlProviderConfig extends SqlProviderConfig {
|
||||
@ConfigurationProperties("synapseSql")
|
||||
public class SynapseSqlProviderConfig extends SqlConfig {
|
||||
|
||||
public static final String NAMESPACE = "synapseSql";
|
||||
@Override
|
||||
protected String getProviderName() {
|
||||
return "Synapse SQL";
|
||||
}
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(SynapseSqlProviderConfig.class);
|
||||
@PostConstruct
|
||||
public void build() {
|
||||
super.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user