View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.web.util;
20  
21  import java.util.Date;
22  import java.util.HashMap;
23  
24  /**
25   * Seems to manage the Web Sessions...
26   *
27   * @author ready
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  }