Search in sources :

Example 66 with WallConfig

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)"));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

Example 67 with WallConfig

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");
}
Also used : WallFilter(com.alibaba.druid.wall.WallFilter) WallConfig(com.alibaba.druid.wall.WallConfig) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) OracleMockDriver(com.alibaba.druid.test.util.OracleMockDriver)

Example 68 with WallConfig

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");
}
Also used : OracleMockDriverJdbc3(com.alibaba.druid.test.util.OracleMockDriverJdbc3) WallFilter(com.alibaba.druid.wall.WallFilter) WallConfig(com.alibaba.druid.wall.WallConfig) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 69 with WallConfig

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();
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ConfigException(io.mycat.config.util.ConfigException) WallConfig(com.alibaba.druid.wall.WallConfig) UserConfig(io.mycat.config.model.UserConfig) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 70 with WallConfig

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));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

Aggregations

WallConfig (com.alibaba.druid.wall.WallConfig)83 Properties (java.util.Properties)8 WallFilter (com.alibaba.druid.wall.WallFilter)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)4 WallCheckResult (com.alibaba.druid.wall.WallCheckResult)3 Filter (com.alibaba.druid.filter.Filter)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 OracleMockDriver (com.alibaba.druid.test.util.OracleMockDriver)2 WallContext (com.alibaba.druid.wall.WallContext)2 MySqlWallProvider (com.alibaba.druid.wall.spi.MySqlWallProvider)2 SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLStartTransactionStatement (com.alibaba.druid.sql.ast.statement.SQLStartTransactionStatement)1 MySqlCommitStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement)1 MySqlDeleteStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement)1 MySqlDescribeStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDescribeStatement)1 MySqlHintStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlHintStatement)1 MySqlLockTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement)1 MySqlRenameTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement)1 MySqlReplaceStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlReplaceStatement)1