Browse Source

修改敏感词过滤器过滤规则

suntg 8 years ago
parent
commit
bb13731642

+ 14 - 3
src/main/java/com/uas/platform/b2c/core/filter/KeyWordFilter.java

@@ -14,6 +14,7 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.log4j.Logger;
 import org.springframework.util.StringUtils;
 import org.springframework.web.context.support.WebApplicationContextUtils;
 import org.springframework.web.context.support.XmlWebApplicationContext;
@@ -23,12 +24,19 @@ import org.springframework.web.context.support.XmlWebApplicationContext;
  * @author liusw
  */
 public class KeyWordFilter implements Filter {
+
     public static Set<String> keyworsSet = null;
 
+    /**
+     * hessian 请求路径前缀
+     */
+    private static String HESSIAN_URI_PREFIX = "/api/service/";
+
+    private Logger logger = Logger.getLogger(this.getClass());
+
     @Override
     public void destroy() {
         // TODO Auto-generated method stub
-
     }
 
     @Override
@@ -40,8 +48,11 @@ public class KeyWordFilter implements Filter {
         response.setContentType("application/json; charset=utf-8");
         String contentType = req.getContentType();
         String method = req.getMethod();
-        // POST请求 或 PUT请求,并且不是附件上传请求
-        if(("POST".equals(method) || "PUT".equals(method)) && (StringUtils.isEmpty(contentType) || !contentType.contains("multipart"))){
+        String uri = req.getRequestURI();
+        // POST请求 或 PUT请求,并且不是附件上传请求,并且不是hessian请求
+        if(("POST".equals(method) || "PUT".equals(method)) &&
+                (StringUtils.isEmpty(contentType) || !contentType.contains("multipart")) &&
+                !uri.startsWith(HESSIAN_URI_PREFIX)){
             //注入Service
             ServletContext sc = req.getSession().getServletContext();
             XmlWebApplicationContext cxt = (XmlWebApplicationContext) WebApplicationContextUtils.getWebApplicationContext(sc);

+ 1 - 0
src/main/webapp/WEB-INF/spring/hessian.xml

@@ -8,6 +8,7 @@
 	<bean id="defaultHandlerMapping"
 		class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
 	<!-- 提供用于验证签名的私钥 -->
+	<!-- 注意保持name 链接规则一直,/api/service/** 否则会被过滤器KeyWordFilter过滤,验证无法通过 -->
 	<bean id="apiSecretKeyService" class="com.uas.platform.b2c.external.erp.support.SecretKeyServiceImpl" />
 	<!-- 验证成功后执行(将用户信息写到SystemSession) -->
 	<bean id="apiHandlerInterceptor"