Merge remote-tracking branch 'upstream/master'

This commit is contained in:
kiki
2013-09-02 11:38:33 +08:00
16 changed files with 427 additions and 14 deletions
@@ -83,6 +83,8 @@ import com.alibaba.druid.sql.parser.Token;
public class OracleExprParser extends SQLExprParser {
public boolean allowStringAdditive = false;
/**
@@ -480,12 +482,37 @@ public class OracleExprParser extends SQLExprParser {
protected SQLExpr methodRest(SQLExpr expr, boolean acceptLPAREN) {
if (acceptLPAREN) {
accept(Token.LPAREN);
if (lexer.token() == Token.PLUS) {
lexer.nextToken();
}
if (lexer.token() == Token.PLUS) {
lexer.nextToken();
accept(Token.RPAREN);
return new OracleOuterExpr(expr);
}
if (expr instanceof SQLIdentifierExpr) {
String methodName = ((SQLIdentifierExpr) expr).getName();
SQLMethodInvokeExpr methodExpr = new SQLMethodInvokeExpr(methodName);
if ("trim".equalsIgnoreCase(methodName)) {
if (identifierEquals("LEADING") //
|| identifierEquals("TRAILING") //
|| identifierEquals("BOTH")
) {
methodExpr.putAttribute("trim_option", lexer.stringVal());
lexer.nextToken();
}
SQLExpr trim_character = this.primary();
trim_character.setParent(methodExpr);
methodExpr.putAttribute("trim_character", trim_character);
accept(Token.FROM);
SQLExpr trim_source = this.expr();
methodExpr.addParameter(trim_source);
accept(Token.RPAREN);
return new OracleOuterExpr(expr);
return primaryRest(methodExpr);
}
}
return super.methodRest(expr, false);
}
@@ -3383,4 +3383,27 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
protected void printCascade() {
print(" CASCADE CONSTRAINTS");
}
@Override
public boolean visit(SQLMethodInvokeExpr x) {
if ("trim".equalsIgnoreCase(x.getMethodName())) {
SQLExpr trim_character = (SQLExpr) x.getAttribute("trim_character");
if (trim_character != null) {
print(x.getMethodName());
print("(");
String trim_option = (String) x.getAttribute("trim_option");
if (trim_option != null && trim_option.length() != 0) {
print(trim_option);
print(' ');
}
trim_character.accept(this);
print(" FROM ");
x.getParameters().get(0).accept(this);
print(")");
return false;
}
}
return super.visit(x);
}
}
@@ -365,7 +365,7 @@ public class SQLExprParser extends SQLParser {
return primaryRest(sqlExpr);
} else {
SQLExpr restExpr = equality();
SQLExpr restExpr = relational();
sqlExpr = new SQLNotExpr(restExpr);
}
break;
@@ -1032,7 +1032,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
return false;
}
public boolean visit(SQLInListExpr x) {
if (x.isNot()) {
handleCondition(x.getExpr(), "NOT IN", x.getTargetList());
@@ -42,6 +42,7 @@ public abstract class ResourceSerlvet extends HttpServlet {
public static final String PARAM_NAME_PASSWORD = "loginPassword";
public static final String PARAM_NAME_ALLOW = "allow";
public static final String PARAM_NAME_DENY = "deny";
public static final String PARAM_REMOTE_ADDR = "remoteAddress";
protected String username = null;
protected String password = null;
@@ -51,6 +52,8 @@ public abstract class ResourceSerlvet extends HttpServlet {
protected final String resourcePath;
protected String remoteAddressHeader = null;
public ResourceSerlvet(String resourcePath){
this.resourcePath = resourcePath;
}
@@ -70,6 +73,11 @@ public abstract class ResourceSerlvet extends HttpServlet {
this.password = paramPassword;
}
String paramRemoteAddressHeader = getInitParameter(PARAM_REMOTE_ADDR);
if (!StringUtils.isEmpty(paramRemoteAddressHeader)) {
this.remoteAddressHeader = paramRemoteAddressHeader;
}
try {
String param = getInitParameter(PARAM_NAME_ALLOW);
if (param != null && param.trim().length() != 0) {
@@ -218,7 +226,11 @@ public abstract class ResourceSerlvet extends HttpServlet {
if (contextPath == null || contextPath.equals("") || contextPath.equals("/")) {
response.sendRedirect("/druid/login.html");
} else {
response.sendRedirect("druid/login.html");
if ("".equals(path)) {
response.sendRedirect("druid/login.html");
} else {
response.sendRedirect("login.html");
}
}
return;
}
@@ -263,9 +275,23 @@ public abstract class ResourceSerlvet extends HttpServlet {
}
public boolean isPermittedRequest(HttpServletRequest request) {
String remoteAddress = request.getRemoteAddr();
String remoteAddress = getRemoteAddress(request);
return isPermittedRequest(remoteAddress);
}
protected String getRemoteAddress(HttpServletRequest request) {
String remoteAddr = null;
if (remoteAddressHeader != null) {
remoteAddr = request.getHeader(remoteAddressHeader);
}
if (remoteAddr == null) {
remoteAddr = request.getRemoteAddr();
}
return remoteAddr;
}
protected abstract String process(String url);
}
@@ -108,10 +108,20 @@ public class WallConfig implements WallConfigMBean {
private boolean conditionOpXorAllow = false;
private boolean conditionOpBitwseAllow = true;
private boolean caseConditionAllow = false;
public WallConfig(){
}
public boolean isCaseConditionAllow() {
return caseConditionAllow;
}
public void setCaseConditionAllow(boolean caseConditionAllow) {
this.caseConditionAllow = caseConditionAllow;
}
public boolean isConditionDoubleConstAllow() {
return conditionDoubleConstAllow;
}
@@ -44,6 +44,7 @@ import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitorAdapter;
@@ -152,6 +153,10 @@ public class SQLServerWallVisitor extends SQLServerASTVisitorAdapter implements
return true;
}
@Override
public boolean visit(SQLServerExecStatement x) {
return false;
}
public boolean visit(SQLExprTableSource x) {
WallVisitorUtils.check(this, x);
@@ -257,7 +257,7 @@ public class WallVisitorUtils {
boolean isSimpleConstExpr = false;
SQLExpr first = getFirst(where);
if (first == where) {
if (first == where || first instanceof SQLLiteralExpr) {
isSimpleConstExpr = true;
} else if (first instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) first;
@@ -278,7 +278,6 @@ public class WallVisitorUtils {
addViolation(visitor, ErrorCode.ALWAY_TRUE, "select alway true condition not allow", x);
}
}
}
checkConditionForMultiTenant(visitor, x.getWhere(), x);
} finally {
@@ -1046,9 +1045,18 @@ public class WallVisitorUtils {
return SQLEvalVisitorUtils.eval(dbType, x, Collections.emptyList(), false);
}
if (x instanceof SQLCaseExpr) {
if (visitor != null && (!visitor.getConfig().isCaseConditionAllow()) && x instanceof SQLCaseExpr) {
SQLCaseExpr caseExpr = (SQLCaseExpr) x;
if (caseExpr.getItems().size() > 0) {
boolean leftIsName = false;
if (caseExpr.getParent() instanceof SQLBinaryOpExpr) {
SQLExpr left = ((SQLBinaryOpExpr) caseExpr.getParent()).getLeft();
if (left instanceof SQLName) {
leftIsName = true;
}
}
if ((!leftIsName) && caseExpr.getItems().size() > 0) {
SQLCaseExpr.Item item = caseExpr.getItems().get(0);
Object conditionVal = getValue(visitor, item.getConditionExpr());
Object itemVal = getValue(visitor, item.getValueExpr());