improve WallFilter, support intersectAllow

This commit is contained in:
wenshao
2013-03-19 01:31:32 +08:00
parent f1e6e0d937
commit c75c44e9ee
4 changed files with 41 additions and 4 deletions
@@ -45,6 +45,7 @@ public class WallConfig implements WallConfigMBean {
private boolean insertAllow = true;
private boolean mergeAllow = true;
private boolean minusAllow = false;
private boolean intersectAllow = false;
private boolean multiStatementAllow = false;
@@ -91,10 +92,18 @@ public class WallConfig implements WallConfigMBean {
}
public boolean isIntersectAllow() {
return intersectAllow;
}
public void setIntersectAllow(boolean intersectAllow) {
this.intersectAllow = intersectAllow;
}
public boolean isMinusAllow() {
return minusAllow;
}
public void setMinusAllow(boolean minusAllow) {
this.minusAllow = minusAllow;
}
@@ -753,6 +753,11 @@ public class WallVisitorUtils {
return;
}
if (x.getOperator() == SQLUnionOperator.INTERSECT && !visitor.getConfig().isIntersectAllow()) {
addViolation(visitor, x);
return;
}
if (!visitor.getConfig().isSelectUnionCheck()) {
return;
}
@@ -0,0 +1,23 @@
package com.alibaba.druid.bvt.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallUtils;
public class IntersectTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateOracle(//
"SELECT * FROM A MINUS SELECT * FROM B")); //
}
public void test_true() throws Exception {
WallConfig config = new WallConfig();
config.setMinusAllow(true);
Assert.assertTrue(WallUtils.isValidateOracle(//
"SELECT * FROM A MINUS SELECT * FROM B", config)); //
}
}
@@ -11,13 +11,13 @@ public class MinusTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateOracle(//
"SELECT * FROM A MINUS SELECT * FROM B")); //
"SELECT * FROM A Intersect SELECT * FROM B")); //
}
public void test_true() throws Exception {
WallConfig config = new WallConfig();
config.setMinusAllow(true);
config.setIntersectAllow(true);
Assert.assertTrue(WallUtils.isValidateOracle(//
"SELECT * FROM A MINUS SELECT * FROM B", config)); //
"SELECT * FROM A Intersect SELECT * FROM B", config)); //
}
}