wall filter

This commit is contained in:
温少
2012-03-16 17:00:46 +08:00
7 changed files with 264 additions and 3 deletions
@@ -7,11 +7,14 @@ import com.alibaba.druid.filter.FilterAdapter;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.filter.wall.spi.MySqlWallProvider;
import com.alibaba.druid.filter.wall.spi.MySqlWallVisitor;
import com.alibaba.druid.filter.wall.spi.OracleWallProvider;
import com.alibaba.druid.filter.wall.spi.OracleWallVisitor;
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
import com.alibaba.druid.proxy.jdbc.DataSourceProxy;
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
import com.alibaba.druid.proxy.jdbc.StatementProxy;
import com.alibaba.druid.util.JdbcUtils;
public class WallFilter extends FilterAdapter {
@@ -97,6 +100,69 @@ public class WallFilter extends FilterAdapter {
check(connection, sql);
return chain.connection_prepareCall(connection, sql, resultSetType, resultSetConcurrency, resultSetHoldability);
}
////////////////
@Override
public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
check(statement.getConnectionProxy(), sql);
return chain.statement_execute(statement, sql);
}
@Override
public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys)
throws SQLException {
check(statement.getConnectionProxy(), sql);
return chain.statement_execute(statement, sql, autoGeneratedKeys);
}
@Override
public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[])
throws SQLException {
check(statement.getConnectionProxy(), sql);
return chain.statement_execute(statement, sql, columnIndexes);
}
@Override
public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, String columnNames[])
throws SQLException {
check(statement.getConnectionProxy(), sql);
return chain.statement_execute(statement, sql, columnNames);
}
@Override
public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql)
throws SQLException {
check(statement.getConnectionProxy(), sql);
return chain.statement_executeQuery(statement, sql);
}
@Override
public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
check(statement.getConnectionProxy(), sql);
return chain.statement_executeUpdate(statement, sql);
}
@Override
public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys)
throws SQLException {
check(statement.getConnectionProxy(), sql);
return chain.statement_executeUpdate(statement, sql, autoGeneratedKeys);
}
@Override
public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[])
throws SQLException {
check(statement.getConnectionProxy(), sql);
return chain.statement_executeUpdate(statement, sql, columnIndexes);
}
@Override
public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, String columnNames[])
throws SQLException {
check(statement.getConnectionProxy(), sql);
return chain.statement_executeUpdate(statement, sql, columnNames);
}
public void check(ConnectionProxy connection, String sql) throws SQLException {
provider.check(sql, true);
@@ -106,6 +172,10 @@ public class WallFilter extends FilterAdapter {
if (JdbcUtils.MYSQL.equals(dbType)) {
return new MySqlWallProvider();
}
if (JdbcUtils.ORACLE.equals(dbType)) {
return new OracleWallProvider();
}
throw new IllegalStateException("dbType not support : " + dbType);
}
@@ -85,8 +85,8 @@ public abstract class WallProvider {
if (visitor.getViolations().size() > 0) {
if (throwException) {
visitor.getViolations().get(0);
throw new WallRuntimeException();
Violation violation = visitor.getViolations().get(0);
throw new WallRuntimeException(violation.toString());
} else {
return false;
}
@@ -0,0 +1,6 @@
package com.alibaba.druid.filter.wall.spi;
public class SQLServerWallVisitor {
}