use of com.actiontech.dble.config.model.UserPrivilegesConfig in project dble by actiontech.
the class UserConfigLoader method loadPrivileges.
private void loadPrivileges(UserConfig userConfig, boolean isLowerCaseTableNames, Element node) {
UserPrivilegesConfig privilegesConfig = new UserPrivilegesConfig();
NodeList privilegesNodes = node.getElementsByTagName("privileges");
int privilegesNodesLength = privilegesNodes.getLength();
for (int i = 0; i < privilegesNodesLength; i++) {
Element privilegesNode = (Element) privilegesNodes.item(i);
String check = privilegesNode.getAttribute("check");
if (null != check) {
privilegesConfig.setCheck(Boolean.valueOf(check));
}
NodeList schemaNodes = privilegesNode.getElementsByTagName("schema");
int schemaNodeLength = schemaNodes.getLength();
for (int j = 0; j < schemaNodeLength; j++) {
Element schemaNode = (Element) schemaNodes.item(j);
String name1 = schemaNode.getAttribute("name");
if (isLowerCaseTableNames) {
name1 = name1.toLowerCase();
}
String dml1 = schemaNode.getAttribute("dml");
int[] dml1Array = new int[dml1.length()];
for (int offset1 = 0; offset1 < dml1.length(); offset1++) {
dml1Array[offset1] = Character.getNumericValue(dml1.charAt(offset1));
}
UserPrivilegesConfig.SchemaPrivilege schemaPrivilege = new UserPrivilegesConfig.SchemaPrivilege();
schemaPrivilege.setDml(dml1Array);
NodeList tableNodes = schemaNode.getElementsByTagName("table");
int tableNodeLength = tableNodes.getLength();
for (int z = 0; z < tableNodeLength; z++) {
UserPrivilegesConfig.TablePrivilege tablePrivilege = new UserPrivilegesConfig.TablePrivilege();
Element tableNode = (Element) tableNodes.item(z);
String name2 = tableNode.getAttribute("name");
if (isLowerCaseTableNames) {
name2 = name2.toLowerCase();
}
String dml2 = tableNode.getAttribute("dml");
int[] dml2Array = new int[dml2.length()];
for (int offset2 = 0; offset2 < dml2.length(); offset2++) {
dml2Array[offset2] = Character.getNumericValue(dml2.charAt(offset2));
}
tablePrivilege.setDml(dml2Array);
schemaPrivilege.addTablePrivilege(name2, tablePrivilege);
}
privilegesConfig.addSchemaPrivilege(name1, schemaPrivilege);
}
}
userConfig.setPrivilegesConfig(privilegesConfig);
}
use of com.actiontech.dble.config.model.UserPrivilegesConfig in project dble by actiontech.
the class ServerPrivileges method checkPrivilege.
// check SQL Privilege
public static boolean checkPrivilege(ServerConnection source, String schema, String tableName, CheckType chekcType) {
UserConfig userConfig = DbleServer.getInstance().getConfig().getUsers().get(source.getUser());
if (userConfig == null) {
return true;
}
UserPrivilegesConfig userPrivilege = userConfig.getPrivilegesConfig();
if (userPrivilege == null || !userPrivilege.isCheck()) {
return true;
}
UserPrivilegesConfig.SchemaPrivilege schemaPrivilege = userPrivilege.getSchemaPrivilege(schema);
if (schemaPrivilege == null) {
return true;
}
UserPrivilegesConfig.TablePrivilege tablePrivilege = schemaPrivilege.getTablePrivilege(tableName);
if (tablePrivilege == null && schemaPrivilege.getDml().length == 0) {
return true;
}
int index = -1;
if (chekcType == CheckType.INSERT) {
index = 0;
} else if (chekcType == CheckType.UPDATE) {
index = 1;
} else if (chekcType == CheckType.SELECT) {
index = 2;
} else if (chekcType == CheckType.DELETE) {
index = 3;
}
if (tablePrivilege != null) {
return tablePrivilege.getDml()[index] > 0;
} else {
return schemaPrivilege.getDml()[index] > 0;
}
}
Aggregations