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