use of com.actiontech.dble.config.model.UserConfig in project dble by actiontech.
the class ServerPrivileges method checkFirewallWhiteHostPolicy.
@Override
public boolean checkFirewallWhiteHostPolicy(String user, String host) {
if (!checkManagerPrivilege(user)) {
// normal user try to login by manager port
return false;
}
boolean isPassed = false;
ServerConfig config = DbleServer.getInstance().getConfig();
FirewallConfig firewallConfig = config.getFirewall();
Map<String, List<UserConfig>> whitehost = firewallConfig.getWhitehost();
if (whitehost == null || whitehost.size() == 0) {
Map<String, UserConfig> users = config.getUsers();
isPassed = users.containsKey(user);
} else {
List<UserConfig> list = whitehost.get(host);
if (list != null) {
for (UserConfig userConfig : list) {
if (userConfig.getName().equals(user)) {
isPassed = true;
break;
}
}
}
}
if (!isPassed) {
ALARM.error(Alarms.FIREWALL_ATTACK + "[host=" + host + ",user=" + user + ']');
return false;
}
return true;
}
use of com.actiontech.dble.config.model.UserConfig in project dble by actiontech.
the class ServerPrivileges method getUserSchemas.
@Override
public Set<String> getUserSchemas(String user) {
ServerConfig conf = DbleServer.getInstance().getConfig();
UserConfig uc = conf.getUsers().get(user);
if (uc != null) {
return uc.getSchemas();
} else {
return null;
}
}
use of com.actiontech.dble.config.model.UserConfig in project dble by actiontech.
the class ServerPrivileges method isManagerUser.
protected boolean isManagerUser(String user) {
ServerConfig conf = DbleServer.getInstance().getConfig();
UserConfig uc = conf.getUsers().get(user);
return uc != null && uc.isManager();
}
use of com.actiontech.dble.config.model.UserConfig in project dble by actiontech.
the class ReloadConfig method reload.
public static void reload() throws Exception {
/* 1 load new conf, ConfigInitializer will check itself */
ConfigInitializer loader;
try {
loader = new ConfigInitializer(false, DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames());
} catch (Exception e) {
throw new Exception(e);
}
Map<String, UserConfig> users = loader.getUsers();
Map<String, SchemaConfig> schemas = loader.getSchemas();
Map<String, PhysicalDBNode> dataNodes = loader.getDataNodes();
Map<String, PhysicalDBPool> dataHosts = loader.getDataHosts();
Map<ERTable, Set<ERTable>> erRelations = loader.getErRelations();
FirewallConfig firewall = loader.getFirewall();
/* 2 apply the new conf */
DbleServer.getInstance().getConfig().reload(users, schemas, dataNodes, dataHosts, erRelations, firewall, DbleServer.getInstance().getSystemVariables(), loader.isDataHostWithoutWH(), false);
}
use of com.actiontech.dble.config.model.UserConfig in project dble by actiontech.
the class ReloadConfig method reloadAll.
public static void reloadAll(final int loadAllMode) throws Exception {
/*
* 1 load new conf
* 1.1 ConfigInitializer init adn check itself
* 1.2 DataNode/DataHost test connection
*/
ConfigInitializer loader;
try {
loader = new ConfigInitializer(true, DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames());
} catch (Exception e) {
throw new Exception(e);
}
Map<String, UserConfig> newUsers = loader.getUsers();
Map<String, SchemaConfig> newSchemas = loader.getSchemas();
Map<String, PhysicalDBNode> newDataNodes = loader.getDataNodes();
Map<String, PhysicalDBPool> newDataHosts = loader.getDataHosts();
Map<ERTable, Set<ERTable>> newErRelations = loader.getErRelations();
FirewallConfig newFirewall = loader.getFirewall();
SystemVariables newSystemVariables = DbleServer.getInstance().getSystemVariables();
if (!loader.isDataHostWithoutWH()) {
VarsExtractorHandler handler = new VarsExtractorHandler(newDataNodes);
newSystemVariables = handler.execute();
ConfigInitializer confInit = new ConfigInitializer(newSystemVariables.isLowerCaseTableNames());
newUsers = confInit.getUsers();
newSchemas = confInit.getSchemas();
newDataNodes = confInit.getDataNodes();
newErRelations = confInit.getErRelations();
newFirewall = confInit.getFirewall();
newDataHosts = confInit.getDataHosts();
}
if ((loadAllMode & ManagerParseConfig.OPTT_MODE) != 0) {
try {
loader.testConnection(false);
} catch (Exception e) {
throw new Exception(e);
}
}
/*
* 2 transform
* 2.1 old dataSource continue to work
* 2.2 init the new dataSource
* 2.3 transform
* 2.4 put the old connection into a queue
*/
ServerConfig config = DbleServer.getInstance().getConfig();
/* 2.1 do nothing */
boolean isReloadStatusOK = true;
/* 2.2 init the new dataSource */
for (PhysicalDBPool dbPool : newDataHosts.values()) {
String hostName = dbPool.getHostName();
// set schemas
ArrayList<String> dnSchemas = new ArrayList<>(30);
for (PhysicalDBNode dn : newDataNodes.values()) {
if (dn.getDbPool().getHostName().equals(hostName)) {
dnSchemas.add(dn.getDatabase());
}
}
dbPool.setSchemas(dnSchemas.toArray(new String[dnSchemas.size()]));
// get data host
String dnIndex = DnPropertyUtil.loadDnIndexProps().getProperty(dbPool.getHostName(), "0");
if (!"0".equals(dnIndex)) {
LOGGER.info("init data host: " + dbPool.getHostName() + " to use datasource index:" + dnIndex);
}
dbPool.init(Integer.parseInt(dnIndex));
if (!dbPool.isInitSuccess()) {
isReloadStatusOK = false;
break;
}
}
if (isReloadStatusOK) {
/* 2.3 apply new conf */
config.reload(newUsers, newSchemas, newDataNodes, newDataHosts, newErRelations, newFirewall, newSystemVariables, loader.isDataHostWithoutWH(), true);
recycleOldBackendConnections(config, ((loadAllMode & ManagerParseConfig.OPTF_MODE) != 0));
AlarmAppender.refreshConfig();
} else {
// INIT FAILED
LOGGER.info("reload failed, clear previously created data sources ");
for (PhysicalDBPool dbPool : newDataHosts.values()) {
dbPool.clearDataSources("reload config");
dbPool.stopHeartbeat();
}
throw new Exception("Init DbPool failed");
}
}
Aggregations