Commit 2dd1f3e0ab44ebf6355c94cc8602474e7e85c273
1 parent
6f6469c0
revise
Showing
1 changed file
with
72 additions
and
41 deletions
src/main/java/com/huaheng/framework/config/TestFilter.java
1 | -package com.huaheng.framework.config; | ||
2 | - | ||
3 | -import com.huaheng.framework.aspectj.lang.constant.DataSourceName; | ||
4 | -import com.huaheng.framework.datasource.DynamicDataSourceContextHolder; | ||
5 | - | ||
6 | -import javax.servlet.*; | ||
7 | -import javax.servlet.FilterConfig; | ||
8 | -import javax.servlet.http.HttpServletRequest; | ||
9 | -import javax.servlet.http.HttpSession; | ||
10 | -import java.io.IOException; | ||
11 | - | ||
12 | -public class TestFilter implements Filter { | ||
13 | - @Override | ||
14 | - public void init(FilterConfig filterConfig) throws ServletException { | ||
15 | - | ||
16 | - } | ||
17 | - | ||
18 | - @Override | ||
19 | - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
20 | - HttpServletRequest req=(HttpServletRequest)request; | ||
21 | - System.out.println("自定义过滤器filter触发,拦截url:"+req.getRequestURI()); | ||
22 | - try { | ||
23 | - ServletContext servletContext = req.getServletContext(); | ||
24 | - String warehouseCode = request.getParameter("warehouseCode"); | ||
25 | - if(warehouseCode!=null){ | ||
26 | - servletContext.setAttribute("warehouseCode",warehouseCode); | ||
27 | - } | ||
28 | - if(servletContext.getAttribute("warehouseCode")!=null&&servletContext.getAttribute("warehouseCode").equals("CS0001")) { | ||
29 | - DynamicDataSourceContextHolder.setDB(DataSourceName.SLAVE); | ||
30 | - } | ||
31 | - chain.doFilter(request, response); | ||
32 | - } finally { | ||
33 | - DynamicDataSourceContextHolder.clearDB(); | ||
34 | - } | ||
35 | - } | ||
36 | - | ||
37 | - @Override | ||
38 | - public void destroy() { | ||
39 | - | ||
40 | - } | ||
41 | -} | 1 | +//package com.huaheng.framework.config; |
2 | +// | ||
3 | +//import com.huaheng.common.utils.StringUtils; | ||
4 | +//import com.huaheng.common.utils.security.ShiroUtils; | ||
5 | +//import com.huaheng.framework.aspectj.lang.constant.DataSourceName; | ||
6 | +//import com.huaheng.framework.datasource.DynamicDataSourceContextHolder; | ||
7 | +//import com.huaheng.pc.system.user.domain.User; | ||
8 | +//import org.apache.shiro.SecurityUtils; | ||
9 | +//import org.apache.shiro.subject.Subject; | ||
10 | +//import org.springframework.core.Ordered; | ||
11 | +//import org.springframework.core.annotation.Order; | ||
12 | +// | ||
13 | +//import javax.servlet.*; | ||
14 | +//import javax.servlet.FilterConfig; | ||
15 | +//import javax.servlet.annotation.WebFilter; | ||
16 | +//import javax.servlet.http.HttpServletRequest; | ||
17 | +//import javax.servlet.http.HttpSession; | ||
18 | +//import java.io.IOException; | ||
19 | +// | ||
20 | +////@WebFilter(urlPatterns = "/*",filterName = "TestFilter") | ||
21 | +////@Order(Ordered.LOWEST_PRECEDENCE) | ||
22 | +//public class TestFilter implements Filter { | ||
23 | +// private String[] excludedUris; | ||
24 | +// @Override | ||
25 | +// public void init(FilterConfig filterConfig) throws ServletException { | ||
26 | +// | ||
27 | +// excludedUris=new String[]{".js",".gif",".jpg",".png",".css",".ico",".css","/login","/getWarehouseByUserCode","/index","/main", | ||
28 | +// "/getShipmentsLast7Days","/getLocationProp","/getInventoryStatus","/getCommonData","/getInventoryProp"}; | ||
29 | +//// String param = filterConfig.getInitParameter("excludedUris"); | ||
30 | +//// if(StringUtils.isNotEmpty(param)){ | ||
31 | +//// this.excludedUris=param.split(","); | ||
32 | +//// } | ||
33 | +// } | ||
34 | +// | ||
35 | +// @Override | ||
36 | +// public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
37 | +// HttpServletRequest req=(HttpServletRequest)request; | ||
38 | +// System.out.println("自定义过滤器filter触发,拦截url:"+req.getRequestURI()+"外部"); | ||
39 | +// try { | ||
40 | +// | ||
41 | +// chain.doFilter(request, response); | ||
42 | +// ServletContext servletContext = req.getServletContext(); | ||
43 | +// String warehouseCode = request.getParameter("warehouseCode"); | ||
44 | +// if(warehouseCode!=null){ | ||
45 | +// servletContext.setAttribute("warehouseCode",warehouseCode); | ||
46 | +// } | ||
47 | +// if(servletContext.getAttribute("warehouseCode")!=null&&servletContext.getAttribute("warehouseCode").equals("CS0001")) { | ||
48 | +// // DynamicDataSourceContextHolder.setDB(DataSourceName.SLAVE); | ||
49 | +// } | ||
50 | +// boolean flag=true; | ||
51 | +// for(String s:excludedUris){ | ||
52 | +// if(req.getRequestURI().endsWith(s)){ | ||
53 | +// flag=false; | ||
54 | +// } | ||
55 | +// } | ||
56 | +// if(req.getRequestURI().startsWith("/wms/imserver")){ | ||
57 | +// flag=false; | ||
58 | +// } | ||
59 | +// if(flag){ | ||
60 | +// System.out.println("自定义过滤器filter触发,拦截url:"+req.getRequestURI()+"内部"); | ||
61 | +// SecurityUtils.getSubject(); | ||
62 | +// } | ||
63 | +// } finally { | ||
64 | +// DynamicDataSourceContextHolder.clearDB(); | ||
65 | +// } | ||
66 | +// } | ||
67 | +// | ||
68 | +// @Override | ||
69 | +// public void destroy() { | ||
70 | +// | ||
71 | +// } | ||
72 | +//} |