mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve WallFilter
This commit is contained in:
@@ -29,6 +29,7 @@ import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import com.alibaba.druid.sql.visitor.ExportParameterVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.util.LRUCache;
|
||||
import com.alibaba.druid.wall.spi.WallVisitorUtils;
|
||||
import com.alibaba.druid.wall.violation.IllegalSQLObjectViolation;
|
||||
@@ -54,9 +55,16 @@ public abstract class WallProvider {
|
||||
|
||||
public final WallDenyStat commentDeniedStat = new WallDenyStat();
|
||||
|
||||
protected String dbType = null;
|
||||
|
||||
public WallProvider(WallConfig config){
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public WallProvider(WallConfig config, String dbType){
|
||||
this.config = config;
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
public WallConfig getConfig() {
|
||||
return config;
|
||||
@@ -128,6 +136,7 @@ public abstract class WallProvider {
|
||||
public abstract ExportParameterVisitor createExportParameterVisitor();
|
||||
|
||||
public boolean checkValid(String sql) {
|
||||
WallContext.createIfNotExists(dbType);
|
||||
WallCheckResult result = check(sql);
|
||||
return result.getViolations().isEmpty();
|
||||
}
|
||||
@@ -262,7 +271,7 @@ public abstract class WallProvider {
|
||||
return result;
|
||||
} catch (ParserException e) {
|
||||
if (config.isStrictSyntaxCheck()) {
|
||||
result.getViolations().add(new SyntaxErrorViolation(e, sql));
|
||||
result.getViolations().add(new SyntaxErrorViolation(e, sql));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user