use of com.alibaba.druid.wall.WallConfig in project druid by alibaba.
the class OracleWallTest method testWall.
public void testWall() throws Exception {
WallConfig config = new WallConfig();
config.setSelectUnionCheck(true);
Assert.assertTrue(WallUtils.isValidateOracle("select f1, f2 from t where c=1 union select 1, 2", config));
Assert.assertFalse(WallUtils.isValidateOracle("select f1, f2 from t where c=1 union select 1, 2 --", config));
Assert.assertFalse(WallUtils.isValidateOracle("SELECT * FROM T UNION select * from TAB"));
Assert.assertFalse(WallUtils.isValidateOracle("SELECT * FROM T UNION select * from ALL_TABLES where (1=1 or (1+1)=2) and (4=8 or 1=1)"));
}
use of com.alibaba.druid.wall.WallConfig in project druid by alibaba.
the class TestOracleWall3 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
WallFilter wall = new WallFilter();
wall.setConfig(new WallConfig());
wall.getConfig().setWrapAllow(true);
dataSource.setOracle(true);
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(new OracleMockDriver());
dataSource.setPoolPreparedStatements(true);
dataSource.setConnectionProperties("defaultRowPrefetch=50");
dataSource.setFilters("stat");
dataSource.getProxyFilters().add(wall);
dataSource.setDbType("oracle");
// dataSource.setFilters("log4j");
}
use of com.alibaba.druid.wall.WallConfig in project druid by alibaba.
the class TestOracleWallJdbc3 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
WallFilter wall = new WallFilter();
wall.setConfig(new WallConfig());
wall.getConfig().setWrapAllow(true);
dataSource.setOracle(true);
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(new OracleMockDriverJdbc3());
dataSource.setPoolPreparedStatements(true);
dataSource.setConnectionProperties("defaultRowPrefetch=50");
dataSource.setFilters("stat");
dataSource.getProxyFilters().add(wall);
dataSource.setDbType("oracle");
// dataSource.setFilters("log4j");
}
use of com.alibaba.druid.wall.WallConfig in project Mycat-Server by MyCATApache.
the class XMLServerLoader method loadFirewall.
/**
* 初始载入配置获取防火墙配置,配置防火墙方法之一,一共有两处,另一处:
* @see FirewallConfig
*
* @modification 修改增加网段白名单
* @date 2016/12/8
* @modifiedBy Hash Zhang
*/
private void loadFirewall(Element root) throws IllegalAccessException, InvocationTargetException {
NodeList list = root.getElementsByTagName("host");
Map<String, List<UserConfig>> whitehost = new HashMap<>();
Map<Pattern, List<UserConfig>> whitehostMask = new HashMap<>();
for (int i = 0, n = list.getLength(); i < n; i++) {
Node node = list.item(i);
if (node instanceof Element) {
Element e = (Element) node;
String host = e.getAttribute("host").trim();
String userStr = e.getAttribute("user").trim();
if (this.firewall.existsHost(host)) {
throw new ConfigException("host duplicated : " + host);
}
String[] users = userStr.split(",");
List<UserConfig> userConfigs = new ArrayList<UserConfig>();
for (String user : users) {
UserConfig uc = this.users.get(user);
if (null == uc) {
throw new ConfigException("[user: " + user + "] doesn't exist in [host: " + host + "]");
}
if (uc.getSchemas() == null || uc.getSchemas().size() == 0) {
throw new ConfigException("[host: " + host + "] contains one root privileges user: " + user);
}
userConfigs.add(uc);
}
if (host.contains("*") || host.contains("%")) {
whitehostMask.put(FirewallConfig.getMaskPattern(host), userConfigs);
} else {
whitehost.put(host, userConfigs);
}
}
}
firewall.setWhitehost(whitehost);
firewall.setWhitehostMask(whitehostMask);
WallConfig wallConfig = new WallConfig();
NodeList blacklist = root.getElementsByTagName("blacklist");
for (int i = 0, n = blacklist.getLength(); i < n; i++) {
Node node = blacklist.item(i);
if (node instanceof Element) {
Element e = (Element) node;
String check = e.getAttribute("check");
if (null != check) {
firewall.setCheck(Boolean.parseBoolean(check));
}
Map<String, Object> props = ConfigUtil.loadElements((Element) node);
ParameterMapping.mapping(wallConfig, props);
}
}
firewall.setWallConfig(wallConfig);
firewall.init();
}
use of com.alibaba.druid.wall.WallConfig in project druid by alibaba.
the class ConstantArithmeticCheckTest method test_false.
public void test_false() throws Exception {
WallConfig config = new WallConfig();
config.setConstArithmeticAllow(false);
Assert.assertFalse(//
WallUtils.isValidateMySql("SELECT * from t where 3 - 1", //
config));
}
Aggregations