1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.util;
20
21 import java.util.Date;
22 import java.util.HashMap;
23
24
25
26
27
28
29 public class SessionManager {
30 private static HashMap<String, Date> activeSessionsStarted = new HashMap<String, Date>();
31 private static HashMap<String, Date> activeSessionsLastAccess = new HashMap<String, Date>();
32 private static HashMap<String, Integer> activeSessionsReset = new HashMap<String, Integer>();
33 private static HashMap<String, String> renamedLogins = new HashMap<String, String>();
34
35 public SessionManager() {
36 }
37
38 public static int getNumActiveSessions() {
39 return activeSessionsStarted.size();
40 }
41
42 public static Date getSessionStart(String login) {
43 return activeSessionsStarted.get(login);
44 }
45
46 public static Date getSessionLastAccess(String login) {
47 return activeSessionsLastAccess.get(login);
48 }
49
50 public static boolean getSessionNeedsReset(String login) {
51 return activeSessionsReset.get(login) != null ? true : false;
52 }
53
54 public static void createSession(String login) {
55 Date now = new Date();
56 activeSessionsStarted.put(login, now);
57 activeSessionsLastAccess.put(login, now);
58 }
59
60 public static void invalidateSession(String login) {
61 activeSessionsLastAccess.remove(login);
62 activeSessionsStarted.remove(login);
63 activeSessionsReset.remove(login);
64 }
65
66 public static void setSessionNeedsReset(String login) {
67 activeSessionsReset.put(login, 1);
68 }
69
70 public static void addRenamedLogin(String prevLogin, String newLogin) {
71 renamedLogins.put(prevLogin, newLogin);
72 }
73
74 public static void removeRenamedLogin(String prevLogin) {
75 renamedLogins.remove(prevLogin);
76 }
77
78 public static String checkRenamedLogin(String prevLogin) {
79 if (renamedLogins.containsKey(prevLogin)) {
80 return renamedLogins.get(prevLogin);
81 }
82
83 return null;
84 }
85
86 public static void clearSessionNeedsReset(String login) {
87 activeSessionsReset.remove(login);
88 }
89 }