1 package com.instantbank.collections.util;
2
3 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse;
5 import javax.servlet.http.HttpSession;
6 import javax.servlet.RequestDispatcher;
7 import javax.servlet.ServletContext;
8
9
10 import com.instantbank.common.utilcomponents.Debug;
11
12
13 public class SessionFilter
14 implements Filter {
15
16 private Debug debug = null;
17
18
19 private boolean requiresCompany = true;
20 private ServletContext servletContext;
21
22
23 public SessionFilter() {
24
25 debug = new Debug();
26 debug.setDebugginOn(true);
27 debug.setPreMessage("** COLL:SessionFilter: ");
28
29
30 }
31
32
33 public void clearRequiresCompany() {
34 requiresCompany = false;
35 }
36
37
38 public boolean execute(HttpServletRequest request, HttpServletResponse response) throws InstantbankException {
39 java.util.Date actionTime;
40 String attr;
41 java.util.Date beginTime;
42 Long companyId;
43 boolean hasToLogin = false;
44 Boolean isAttr = new Boolean(false);
45 Long maxTime;
46 HttpSession session;
47 java.util.Date totalTime;
48 Long userId;
49 Object temp;
50
51 try {
52 session = request.getSession();
53
54 if(session == null) {
55 RequestDispatcher rd = servletContext.getRequestDispatcher("Instantbank/main_web/LoginPage.jsp");
56 rd.forward(request, response);
57 return true;
58 }
59 else {
60 beginTime = (java.util.Date)session.getAttribute("sessionInitialTime");
61 maxTime = (Long)session.getAttribute("companySessionTime");
62 actionTime = DateUtils.rightNow();
63
64
65
66 long diff = actionTime.getTime() - beginTime.getTime();
67 long diffMin = diff / 60000L;
68
69 float floatDiffMin = ((float)diff) / 60000L;
70
71
72 if(!maxTime.equals(new Long("0"))) {
73
74 if( floatDiffMin > maxTime.longValue()) {
75 debug.println("timeout in Instantbank ear");
76 response.sendRedirect("../main_web/TimeOutPage.jsp");
77 return true;
78 }
79 else {
80 session.setAttribute("sessionInitialTime", DateUtils.rightNow());
81 java.util.Date t = (java.util.Date)session.getAttribute("sessionInitialTime");
82 debug.println("sessionInitialTime updated to:" + t);
83 }
84
85 }
86 if(requiresCompany) {
87 companyId = (Long)session.getAttribute("companyId");
88 if(companyId.longValue() == 0L) {
89 throw new InstantbankException("000002", "Please select a company before calling this function");
90 }
91 }
92 }
93 }
94 catch(Exception e) {
95 throw new InstantbankException(e, "000003", "Failed to process the request");
96 }
97 return false;
98 }
99
100
101 public void setServletContext(ServletContext sc) {
102 servletContext = sc;
103 }
104 }
105
106