mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve wall filter, add allowDoPrivileged
This commit is contained in:
@@ -57,6 +57,8 @@ public class WallConfig implements WallConfigMBean {
|
||||
|
||||
private boolean mustParameterized = false;
|
||||
|
||||
private boolean allowDoPrivileged = 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>();
|
||||
@@ -73,6 +75,14 @@ public class WallConfig implements WallConfigMBean {
|
||||
|
||||
}
|
||||
|
||||
public boolean isAllowDoPrivileged() {
|
||||
return allowDoPrivileged;
|
||||
}
|
||||
|
||||
public void setAllowDoPrivileged(boolean allowDoPrivileged) {
|
||||
this.allowDoPrivileged = allowDoPrivileged;
|
||||
}
|
||||
|
||||
public boolean isInited() {
|
||||
return inited;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public abstract class WallProvider {
|
||||
}
|
||||
|
||||
public List<Violation> check(String sql) {
|
||||
if (privileged.get() == Boolean.TRUE) {
|
||||
if (config.isAllowDoPrivileged() && privileged.get() == Boolean.TRUE) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.wall.WallConfig;
|
||||
import com.alibaba.druid.wall.WallProvider;
|
||||
import com.alibaba.druid.wall.WallUtils;
|
||||
|
||||
@@ -31,10 +32,13 @@ public class DoPrivilegedTest extends TestCase {
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
final WallConfig config = new WallConfig();
|
||||
config.setAllowDoPrivileged(true);
|
||||
|
||||
WallProvider.doPrivileged(new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
Assert.assertTrue(WallUtils.isValidateMySql("select @@version_compile_os"));
|
||||
Assert.assertTrue(WallUtils.isValidateMySql("select @@version_compile_os", config));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user