WallConfig support properties config

This commit is contained in:
高铁
2016-05-11 13:23:45 +08:00
parent fa3a423582
commit e24bd88597
3 changed files with 123 additions and 7 deletions
@@ -17,9 +17,11 @@ package com.alibaba.druid.wall;
import com.alibaba.druid.wall.spi.WallVisitorUtils;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;
import static com.alibaba.druid.util.Utils.getBoolean;
import static com.alibaba.druid.wall.spi.WallVisitorUtils.loadResource;
public class WallConfig implements WallConfigMBean {
@@ -124,7 +126,7 @@ public class WallConfig implements WallConfigMBean {
private int insertValuesCheckSize = 3;
public WallConfig(){
this.configFromProperties(System.getProperties());
}
public boolean isCaseConditionConstAllow() {
@@ -787,4 +789,36 @@ public class WallConfig implements WallConfigMBean {
this.insertValuesCheckSize = insertValuesCheckSize;
}
public void configFromProperties(Properties properties) {
{
String tenantColumn = properties.getProperty("druid.wall.tenantColumn");
if (tenantColumn != null) {
this.setTenantColumn(tenantColumn);
}
}
{
Boolean selelctAllow = getBoolean(properties, "druid.wall.selelctAllow");
if (selelctAllow != null) {
this.setSelelctAllow(selelctAllow);
}
}
{
Boolean updateAllow = getBoolean(properties, "druid.wall.updateAllow");
if (updateAllow != null) {
this.setUpdateAllow(updateAllow);
}
}
{
Boolean deleteAllow = getBoolean(properties, "druid.wall.deleteAllow");
if (deleteAllow != null) {
this.setDeleteAllow(deleteAllow);
}
}
{
Boolean insertAllow = getBoolean(properties, "druid.wall.insertAllow");
if (insertAllow != null) {
this.setInsertAllow(insertAllow);
}
}
}
}
@@ -98,11 +98,9 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean {
this.throwException = value;
}
}
{
String tenantColumn = properties.getProperty("druid.wall.tenantColumn");
if (tenantColumn != null) {
this.config.setTenantColumn(tenantColumn);
}
if (this.config != null) {
this.config.configFromProperties(properties);
}
}
@@ -161,7 +159,7 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean {
} else {
throw new IllegalStateException("dbType not support : " + dbType + ", url " + dataSource.getUrl());
}
provider.setName(dataSource.getName());
this.inited = true;
@@ -0,0 +1,84 @@
package com.alibaba.druid.bvt.filter.wall;
import java.util.Properties;
import org.junit.Assert;
import com.alibaba.druid.wall.WallConfig;
import junit.framework.TestCase;
public class WallConfigTest extends TestCase {
public void test_selectAllow() throws Exception {
Properties properties = new Properties();
properties.setProperty("druid.wall.selelctAllow", "true");
WallConfig config = new WallConfig();
config.configFromProperties(properties);
Assert.assertTrue(config.isSelelctAllow());
}
public void test_selectAllow_false() throws Exception {
Properties properties = new Properties();
properties.setProperty("druid.wall.selelctAllow", "false");
WallConfig config = new WallConfig();
config.configFromProperties(properties);
Assert.assertFalse(config.isSelelctAllow());
}
public void test_deleteAllow() throws Exception {
Properties properties = new Properties();
properties.setProperty("druid.wall.deleteAllow", "true");
WallConfig config = new WallConfig();
config.configFromProperties(properties);
Assert.assertTrue(config.isDeleteAllow());
}
public void test_deleteAllow_false() throws Exception {
Properties properties = new Properties();
properties.setProperty("druid.wall.deleteAllow", "false");
WallConfig config = new WallConfig();
config.configFromProperties(properties);
Assert.assertFalse(config.isDeleteAllow());
}
public void test_updateAllow() throws Exception {
Properties properties = new Properties();
properties.setProperty("druid.wall.updateAllow", "true");
WallConfig config = new WallConfig();
config.configFromProperties(properties);
Assert.assertTrue(config.isUpdateAllow());
}
public void test_updateAllow_false() throws Exception {
Properties properties = new Properties();
properties.setProperty("druid.wall.updateAllow", "false");
WallConfig config = new WallConfig();
config.configFromProperties(properties);
Assert.assertFalse(config.isUpdateAllow());
}
public void test_insertAllow() throws Exception {
Properties properties = new Properties();
properties.setProperty("druid.wall.insertAllow", "true");
WallConfig config = new WallConfig();
config.configFromProperties(properties);
Assert.assertTrue(config.isInsertAllow());
}
public void test_insertAllow_false() throws Exception {
Properties properties = new Properties();
properties.setProperty("druid.wall.insertAllow", "false");
WallConfig config = new WallConfig();
config.configFromProperties(properties);
Assert.assertFalse(config.isInsertAllow());
}
}