提交 | 用户 | 时间
|
58d006
|
1 |
package com.mandi.servlet; |
A |
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.net.URLEncoder; |
|
5 |
|
|
6 |
import javax.servlet.Filter; |
|
7 |
import javax.servlet.FilterChain; |
|
8 |
import javax.servlet.FilterConfig; |
|
9 |
import javax.servlet.ServletException; |
|
10 |
import javax.servlet.ServletRequest; |
|
11 |
import javax.servlet.ServletResponse; |
|
12 |
import javax.servlet.annotation.WebFilter; |
|
13 |
import javax.servlet.http.HttpServletRequest; |
|
14 |
import javax.servlet.http.HttpServletResponse; |
|
15 |
import javax.servlet.http.HttpSession; |
|
16 |
|
|
17 |
import org.apache.log4j.Logger; |
|
18 |
import org.springframework.context.ApplicationContext; |
|
19 |
|
|
20 |
import com.mandi.common.SessionMethod; |
|
21 |
import com.mandi.common.SpringContext; |
|
22 |
import com.mandi.system.persist.Login; |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* Function: TODO <br/> |
|
27 |
* Date: 2016骞�3鏈�12鏃� 涓嬪崍5:00:29 <br/> |
|
28 |
* @author guolq |
|
29 |
*/ |
|
30 |
//@WebFilter(filterName="permissionfilter",urlPatterns={"*.htm","*.jsf"})// |
|
31 |
public class PermissionFilter implements Filter{ |
|
32 |
private Logger log=Logger.getLogger(PermissionFilter.class); |
|
33 |
|
|
34 |
private ApplicationContext ac; |
|
35 |
@Override |
|
36 |
public void destroy() { |
|
37 |
} |
|
38 |
@Override |
|
39 |
public void doFilter(ServletRequest arg0, ServletResponse arg1, |
|
40 |
FilterChain arg2) throws IOException, ServletException { |
|
41 |
if(ac==null) |
|
42 |
ac=SpringContext.getAppContext(); |
|
43 |
HttpServletRequest r=(HttpServletRequest)arg0; |
|
44 |
HttpServletResponse re=(HttpServletResponse)arg1; |
|
45 |
HttpSession s=r.getSession(); |
|
46 |
String url=r.getRequestURI(); |
|
47 |
String[] noPermiss={"/basic/dayinzcd.jsf","/task/printbycard.htm","/api/scxt/batchdelZcInfo.htm","/api/scxt/batchsubZcInfo.htm","/system/login.htm","/api/scxt/subZcInfo.htm","/api/scxt/delZcInfo.htm","/api/scxt/getClInfo.htm","/api/xscccheck.htm","/api/xsincheck.htm","/login.jsf","/api/xscccheck.htm","/api/xsincheck.htm"}; |
|
48 |
boolean boo=false; |
|
49 |
for (String Str : noPermiss) { |
|
50 |
if(Str.equals(url)){ |
|
51 |
boo=true; |
|
52 |
break; |
|
53 |
} |
|
54 |
} |
|
55 |
if(boo){ |
|
56 |
arg2.doFilter(arg0, arg1); |
|
57 |
return; |
|
58 |
}else{ |
|
59 |
Login lg=SessionMethod.getlogin(r.getSession()); |
|
60 |
if(lg==null){ |
|
61 |
String redirectURL=URLEncoder.encode(url, "UTF-8"); |
|
62 |
re.sendRedirect(r.getServletContext().getContextPath()+"/login.jsf"); |
|
63 |
return; |
|
64 |
}else{ |
|
65 |
arg2.doFilter(arg0, arg1); |
|
66 |
return; |
|
67 |
} |
|
68 |
} |
|
69 |
// arg2.doFilter(arg0, arg1); |
|
70 |
// return ; |
|
71 |
|
|
72 |
|
|
73 |
// IPermcheckService pcheckservice=ac.getBean(PermcheckService.class); |
|
74 |
// if(!pcheckservice.rescheck_eq(url)) |
|
75 |
// { |
|
76 |
// arg2.doFilter(arg0, arg1); |
|
77 |
// return; |
|
78 |
// }else{ |
|
79 |
//// LoginSide resSide=rsService.checkSide(url); |
|
80 |
//// LoginSide lside=SessionMethod.getloginside(s); |
|
81 |
// Login lg=SessionMethod.getlogin(r.getSession()); |
|
82 |
// if(lg==null) |
|
83 |
// { |
|
84 |
//// String redirectURL=URLEncoder.encode(url, "UTF-8"); |
|
85 |
// re.sendRedirect(r.getServletContext().getContextPath()+"/login.jsf");//鍚庣鐧诲綍椤甸潰 |
|
86 |
// return; |
|
87 |
// }else |
|
88 |
// { |
|
89 |
// arg2.doFilter(arg0, arg1); |
|
90 |
// return; |
|
91 |
// } |
|
92 |
// } |
|
93 |
// if(id!=null && id!="") |
|
94 |
// { |
|
95 |
// String redirectURL=URLEncoder.encode(url, "UTF-8"); |
|
96 |
// if(resSide==LoginSide.front) |
|
97 |
// { |
|
98 |
// re.sendRedirect(r.getServletContext().getContextPath()+"/index/login.jsf?url="+redirectURL);//鍓嶇鐧诲綍椤甸潰 |
|
99 |
// }else{ |
|
100 |
// re.sendRedirect(r.getServletContext().getContextPath()+"/blogin.jsf");//鍚庣鐧诲綍椤甸潰 |
|
101 |
// } |
|
102 |
// }else{ |
|
103 |
// if(resSide!=lside) |
|
104 |
// { |
|
105 |
// re.sendRedirect(r.getServletContext().getContextPath()+"/nopermission.html");//娌℃湁鏉冮檺鐨勯敊璇〉闈� |
|
106 |
// }else{ |
|
107 |
// arg2.doFilter(arg0, arg1); |
|
108 |
// } |
|
109 |
// } |
|
110 |
// } |
|
111 |
// return ; |
|
112 |
|
|
113 |
} |
|
114 |
@Override |
|
115 |
public void init(FilterConfig arg0) throws ServletException { |
|
116 |
ac=SpringContext.getAppContext(); |
|
117 |
} |
|
118 |
|
|
119 |
} |