mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve WallFilter
This commit is contained in:
@@ -49,6 +49,7 @@ public abstract class WallProvider {
|
||||
|
||||
private final ConcurrentMap<String, WallDenyStat> deniedTables = new ConcurrentHashMap<String, WallDenyStat>();
|
||||
private final ConcurrentMap<String, WallDenyStat> deniedFunctions = new ConcurrentHashMap<String, WallDenyStat>();
|
||||
private final ConcurrentMap<String, WallDenyStat> deniedSchemas = new ConcurrentHashMap<String, WallDenyStat>();
|
||||
|
||||
public WallProvider(WallConfig config){
|
||||
this.config = config;
|
||||
@@ -146,6 +147,25 @@ public abstract class WallProvider {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkDenySchema(String schemaName) {
|
||||
if (schemaName == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
schemaName = schemaName.toLowerCase();
|
||||
if (getConfig().getDenySchemas().contains(schemaName)) {
|
||||
WallDenyStat denyStat = this.deniedSchemas.get(schemaName);
|
||||
if (denyStat == null) {
|
||||
this.deniedSchemas.putIfAbsent(schemaName, new WallDenyStat());
|
||||
denyStat = this.deniedSchemas.get(schemaName);
|
||||
}
|
||||
denyStat.incrementAndGetDenyCount();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkDenyTable(String tableName) {
|
||||
if (tableName == null) {
|
||||
@@ -193,6 +213,15 @@ public abstract class WallProvider {
|
||||
String formName = WallVisitorUtils.form(tableName);
|
||||
return deniedTables.get(formName);
|
||||
}
|
||||
|
||||
public WallDenyStat getDenniedSchemaStat(String schemaName) {
|
||||
if (schemaName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String formName = WallVisitorUtils.form(schemaName);
|
||||
return deniedSchemas.get(formName);
|
||||
}
|
||||
|
||||
public WallCheckResult check(String sql) {
|
||||
WallCheckResult result = new WallCheckResult();
|
||||
|
||||
Reference in New Issue
Block a user