mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor WallFilter, change permit > deny
This commit is contained in:
@@ -63,11 +63,11 @@ public class WallConfig implements WallConfigMBean {
|
||||
|
||||
private boolean doPrivilegedAllow = false;
|
||||
|
||||
protected final Set<String> permitFunctions = new HashSet<String>();
|
||||
protected final Set<String> permitTables = new HashSet<String>();
|
||||
protected final Set<String> permitSchemas = new HashSet<String>();
|
||||
protected final Set<String> permitVariants = new HashSet<String>();
|
||||
protected final Set<String> permitObjects = new HashSet<String>();
|
||||
protected final Set<String> denyFunctions = new HashSet<String>();
|
||||
protected final Set<String> denyTables = new HashSet<String>();
|
||||
protected final Set<String> denySchemas = new HashSet<String>();
|
||||
protected final Set<String> denyVariants = new HashSet<String>();
|
||||
protected final Set<String> denyObjects = new HashSet<String>();
|
||||
|
||||
protected final Set<String> readOnlyTables = new HashSet<String>();
|
||||
|
||||
@@ -159,11 +159,11 @@ public class WallConfig implements WallConfigMBean {
|
||||
dir = dir.substring(0, dir.length() - 1);
|
||||
}
|
||||
|
||||
loadResource(this.permitVariants, dir + "/permit-variant.txt");
|
||||
loadResource(this.permitSchemas, dir + "/permit-schema.txt");
|
||||
loadResource(this.permitFunctions, dir + "/permit-function.txt");
|
||||
loadResource(this.permitTables, dir + "/permit-table.txt");
|
||||
loadResource(this.permitObjects, dir + "/permit-object.txt");
|
||||
loadResource(this.denyVariants, dir + "/deny-variant.txt");
|
||||
loadResource(this.denySchemas, dir + "/deny-schema.txt");
|
||||
loadResource(this.denyFunctions, dir + "/deny-function.txt");
|
||||
loadResource(this.denyTables, dir + "/deny-table.txt");
|
||||
loadResource(this.denyObjects, dir + "/deny-object.txt");
|
||||
loadResource(this.readOnlyTables, dir + "/readonly-table.txt");
|
||||
}
|
||||
|
||||
@@ -357,24 +357,24 @@ public class WallConfig implements WallConfigMBean {
|
||||
this.commentAllow = commentAllow;
|
||||
}
|
||||
|
||||
public Set<String> getPermitFunctions() {
|
||||
return permitFunctions;
|
||||
public Set<String> getDenyFunctions() {
|
||||
return denyFunctions;
|
||||
}
|
||||
|
||||
public Set<String> getPermitTables() {
|
||||
return permitTables;
|
||||
public Set<String> getDenyTables() {
|
||||
return denyTables;
|
||||
}
|
||||
|
||||
public Set<String> getPermitSchemas() {
|
||||
return permitSchemas;
|
||||
public Set<String> getDenySchemas() {
|
||||
return denySchemas;
|
||||
}
|
||||
|
||||
public Set<String> getPermitVariants() {
|
||||
return permitVariants;
|
||||
public Set<String> getDenyVariants() {
|
||||
return denyVariants;
|
||||
}
|
||||
|
||||
public Set<String> getPermitObjects() {
|
||||
return permitObjects;
|
||||
public Set<String> getDenyObjects() {
|
||||
return denyObjects;
|
||||
}
|
||||
|
||||
public Set<String> getReadOnlyTables() {
|
||||
@@ -389,31 +389,31 @@ public class WallConfig implements WallConfigMBean {
|
||||
this.mustParameterized = mustParameterized;
|
||||
}
|
||||
|
||||
public boolean isPermitObjects(String name) {
|
||||
public boolean isDenyObjects(String name) {
|
||||
if (!objectCheck) {
|
||||
return false;
|
||||
}
|
||||
|
||||
name = WallVisitorUtils.form(name);
|
||||
return permitObjects.contains(name);
|
||||
return denyObjects.contains(name);
|
||||
}
|
||||
|
||||
public boolean isPermitSchema(String name) {
|
||||
public boolean isDenySchema(String name) {
|
||||
if (!schemaCheck) {
|
||||
return false;
|
||||
}
|
||||
|
||||
name = WallVisitorUtils.form(name);
|
||||
return this.permitSchemas.contains(name);
|
||||
return this.denySchemas.contains(name);
|
||||
}
|
||||
|
||||
public boolean isPermitFunction(String name) {
|
||||
public boolean isDenyFunction(String name) {
|
||||
if (!functionCheck) {
|
||||
return false;
|
||||
}
|
||||
|
||||
name = WallVisitorUtils.form(name);
|
||||
return this.permitFunctions.contains(name);
|
||||
return this.denyFunctions.contains(name);
|
||||
}
|
||||
|
||||
public boolean isCallAllow() {
|
||||
|
||||
@@ -113,22 +113,22 @@ public interface WallConfigMBean {
|
||||
|
||||
void setCommentAllow(boolean commentAllow);
|
||||
|
||||
Set<String> getPermitFunctions();
|
||||
Set<String> getDenyFunctions();
|
||||
|
||||
Set<String> getPermitTables();
|
||||
Set<String> getDenyTables();
|
||||
|
||||
Set<String> getPermitSchemas();
|
||||
Set<String> getDenySchemas();
|
||||
|
||||
Set<String> getPermitVariants();
|
||||
Set<String> getDenyVariants();
|
||||
|
||||
Set<String> getPermitObjects();
|
||||
Set<String> getDenyObjects();
|
||||
|
||||
Set<String> getReadOnlyTables();
|
||||
|
||||
boolean isPermitObjects(String name);
|
||||
boolean isDenyObjects(String name);
|
||||
|
||||
boolean isPermitSchema(String name);
|
||||
boolean isDenySchema(String name);
|
||||
|
||||
boolean isPermitFunction(String name);
|
||||
boolean isDenyFunction(String name);
|
||||
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public abstract class WallProvider {
|
||||
SQLStatementParser parser = createParser(sql);
|
||||
|
||||
if (!config.isCommentAllow()) {
|
||||
parser.getLexer().setAllowComment(false); // permit comment
|
||||
parser.getLexer().setAllowComment(false); // deny comment
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface WallVisitor extends SQLASTVisitor {
|
||||
|
||||
void addViolation(Violation violation);
|
||||
|
||||
boolean isPermitTable(String name);
|
||||
boolean isDenyTable(String name);
|
||||
|
||||
String toSQL(SQLObject obj);
|
||||
}
|
||||
|
||||
@@ -237,13 +237,13 @@ public class MySqlWallVisitor extends MySqlASTVisitorAdapter implements WallVisi
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermitTable(String name) {
|
||||
public boolean isDenyTable(String name) {
|
||||
if (!config.isTableCheck()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
name = WallVisitorUtils.form(name);
|
||||
return config.getPermitTables().contains(name);
|
||||
return config.getDenyTables().contains(name);
|
||||
}
|
||||
|
||||
public void preVisit(SQLObject x) {
|
||||
|
||||
@@ -83,7 +83,7 @@ public class OracleWallVisitor extends OracleASTVisitorAdapter implements WallVi
|
||||
public boolean visit(SQLIdentifierExpr x) {
|
||||
String name = x.getName();
|
||||
name = WallVisitorUtils.form(name);
|
||||
if (config.isVariantCheck() && config.getPermitVariants().contains(name)) {
|
||||
if (config.isVariantCheck() && config.getDenyVariants().contains(name)) {
|
||||
getViolations().add(new IllegalSQLObjectViolation(toSQL(x)));
|
||||
}
|
||||
return true;
|
||||
@@ -158,7 +158,7 @@ public class OracleWallVisitor extends OracleASTVisitorAdapter implements WallVi
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermitTable(String name) {
|
||||
public boolean isDenyTable(String name) {
|
||||
if (!config.isTableCheck()) {
|
||||
return false;
|
||||
}
|
||||
@@ -167,7 +167,7 @@ public class OracleWallVisitor extends OracleASTVisitorAdapter implements WallVi
|
||||
if (name.startsWith("v$") || name.startsWith("v_$")) {
|
||||
return true;
|
||||
}
|
||||
return config.getPermitTables().contains(name);
|
||||
return config.getDenyTables().contains(name);
|
||||
}
|
||||
|
||||
public void preVisit(SQLObject x) {
|
||||
|
||||
@@ -80,13 +80,13 @@ public class SQLServerWallVisitor extends SQLServerASTVisitorAdapter implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermitTable(String name) {
|
||||
public boolean isDenyTable(String name) {
|
||||
if (!config.isTableCheck()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
name = WallVisitorUtils.form(name);
|
||||
return config.getPermitTables().contains(name);
|
||||
return config.getDenyTables().contains(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +97,7 @@ public class SQLServerWallVisitor extends SQLServerASTVisitorAdapter implements
|
||||
public boolean visit(SQLIdentifierExpr x) {
|
||||
String name = x.getName();
|
||||
name = WallVisitorUtils.form(name);
|
||||
if (config.isVariantCheck() && config.getPermitVariants().contains(name)) {
|
||||
if (config.isVariantCheck() && config.getDenyVariants().contains(name)) {
|
||||
getViolations().add(new IllegalSQLObjectViolation(toSQL(x)));
|
||||
}
|
||||
return true;
|
||||
@@ -238,10 +238,10 @@ public class SQLServerWallVisitor extends SQLServerASTVisitorAdapter implements
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerObjectReferenceExpr x) {
|
||||
if (x.getSchema() != null && config.isPermitSchema(x.getSchema())) {
|
||||
if (x.getSchema() != null && config.isDenySchema(x.getSchema())) {
|
||||
this.getViolations().add(new IllegalSQLObjectViolation(this.toSQL(x)));
|
||||
}
|
||||
if (x.getDatabase() != null && config.isPermitSchema(x.getDatabase())) {
|
||||
if (x.getDatabase() != null && config.isDenySchema(x.getDatabase())) {
|
||||
this.getViolations().add(new IllegalSQLObjectViolation(this.toSQL(x)));
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -737,7 +737,7 @@ public class WallVisitorUtils {
|
||||
|
||||
String methodName = x.getMethodName();
|
||||
|
||||
if (visitor.getConfig().isPermitFunction(methodName.toLowerCase())) {
|
||||
if (visitor.getConfig().isDenyFunction(methodName.toLowerCase())) {
|
||||
addViolation(visitor, x);
|
||||
}
|
||||
|
||||
@@ -747,11 +747,11 @@ public class WallVisitorUtils {
|
||||
if (x instanceof SQLName) {
|
||||
String owner = ((SQLName) x).getSimleName();
|
||||
owner = WallVisitorUtils.form(owner);
|
||||
if (visitor.getConfig().isPermitSchema(owner)) {
|
||||
if (visitor.getConfig().isDenySchema(owner)) {
|
||||
addViolation(visitor, x);
|
||||
}
|
||||
|
||||
if (visitor.getConfig().isPermitObjects(owner)) {
|
||||
if (visitor.getConfig().isDenyObjects(owner)) {
|
||||
addViolation(visitor, x);
|
||||
}
|
||||
}
|
||||
@@ -771,7 +771,7 @@ public class WallVisitorUtils {
|
||||
|
||||
if (expr instanceof SQLName) {
|
||||
String tableName = ((SQLName) expr).getSimleName();
|
||||
if (visitor.isPermitTable(tableName)) {
|
||||
if (visitor.isDenyTable(tableName)) {
|
||||
addViolation(visitor, x);
|
||||
}
|
||||
}
|
||||
@@ -879,7 +879,7 @@ public class WallVisitorUtils {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("load oracle permit tables errror", e);
|
||||
LOG.error("load oracle deny tables errror", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user