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();
|
}
|
|
}
|