116 lines
4.2 KiB
Plaintext
116 lines
4.2 KiB
Plaintext
package th.co.muangthai.endrprint.controller.interceptor;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import th.co.muangthai.endrprint.controller.interceptor.Interceptor.*;
|
|
import th.co.muangthai.endrprint.dao.serviceImp.CommonServiceImp;
|
|
import th.co.muangthai.endrprint.dao.serviceInterface.CommonServiceInterface;
|
|
import th.co.muangthai.endrprint.model.bean.form.master.EndrUserLoginForm;
|
|
import th.co.muangthai.endrprint.util.DateUtil;
|
|
import th.co.muangthai.endrprint.util.TextContent;
|
|
import th.co.muangthai.endrprint.util.VSMUtil;
|
|
|
|
import javax.servlet.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpSession;
|
|
import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.text.ParseException;
|
|
import java.util.Date;
|
|
|
|
public class SessionCheckFilter implements Filter {
|
|
|
|
private static Logger log = Logger.getLogger(SessionCheckFilter.class);
|
|
|
|
private String contextPath;
|
|
|
|
@Override
|
|
public void init(FilterConfig fc) throws ServletException {
|
|
// contextPath = fc.getServletContext().getServletContextName();
|
|
}
|
|
|
|
@Override
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain fc) throws IOException, ServletException {
|
|
HttpServletRequest req = (HttpServletRequest) request;
|
|
HttpServletResponse res = (HttpServletResponse) response;
|
|
|
|
HttpSession session = req.getSession(true);
|
|
// HttpSession session = req.getSession();
|
|
|
|
|
|
try {
|
|
if(VSMUtil.isEmpty(TextContent.DEPLOYMENT_VERSION)){
|
|
TextContent.DEPLOYMENT_VERSION = DateUtil.toFormatString(new Date(), "yyyyMMdd-HHmmss");
|
|
session.setAttribute("dv", TextContent.DEPLOYMENT_VERSION);
|
|
}
|
|
|
|
} catch (ParseException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
|
|
|
|
//log.info("DEPLOYMENT_VERSION > " + TextContent.DEPLOYMENT_VERSION);
|
|
|
|
// req.getSession().getAttribute(TextContent.sessionLogin);
|
|
//String loginurl = "http://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath() + "/login.jsp";
|
|
String loginurl = "http://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath();
|
|
//
|
|
// String uri = req.getScheme() + "://" + // "http" + "://
|
|
// req.getServerName() + // "myhost"
|
|
// ":" + // ":"
|
|
// req.getServerPort() + // "8080"
|
|
// req.getRequestURI(); // "/people"
|
|
//
|
|
// if (req.getQueryString() != null)
|
|
// {
|
|
// uri += "?" + req.getQueryString();
|
|
// }
|
|
|
|
// log.info("[Session Filter] User RequestURI : " + uri + " , IP : " + request.getRemoteAddr());
|
|
// log.info("URI > " +req.getRequestURI());
|
|
// log.info("URI > " +req.getContextPath());
|
|
// log.info("URI > " +loginurl);
|
|
// if(1 == 1) return;
|
|
try
|
|
{
|
|
|
|
// return;
|
|
if (req.getRequestURI().indexOf("index.jsp") >= 0
|
|
|| req.getRequestURI().indexOf("endrlog.jsp") >= 0
|
|
|| req.getRequestURI().indexOf("endrlistfile.jsp") >= 0
|
|
|| req.getRequestURI().indexOf("endrpathfile.jsp") >= 0
|
|
|| req.getRequestURI().equals(req.getContextPath()+"/")
|
|
|| req.getRequestURI().indexOf("logout.jsp") >= 0
|
|
|| req.getRequestURI().indexOf("login") >= 0
|
|
|| req.getRequestURI().indexOf("logout") >= 0
|
|
|| req.getRequestURI().indexOf("indexWF.jsp") >= 0
|
|
)
|
|
{
|
|
return;
|
|
}
|
|
//
|
|
EndrUserLoginForm userLoginBean = (EndrUserLoginForm) session.getAttribute(TextContent.sessionLogin);
|
|
if (userLoginBean != null) {
|
|
if("0".equals(userLoginBean.getFlagLogin())){
|
|
|
|
}else{
|
|
return;
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
//log.info("9. redirect login " + loginurl + "?warn=1");
|
|
res.sendRedirect(loginurl + "/index.jsp#/login");
|
|
}
|
|
finally {
|
|
fc.doFilter(request, response);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void destroy() {
|
|
}
|
|
}
|