SessionManager.java

  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. package org.itracker.web.util;

  19. import java.util.Date;
  20. import java.util.HashMap;

  21. /**
  22.  * Seems to manage the Web Sessions...
  23.  *
  24.  * @author ready
  25.  */
  26. public class SessionManager {
  27.     private static HashMap<String, Date> activeSessionsStarted = new HashMap<String, Date>();
  28.     private static HashMap<String, Date> activeSessionsLastAccess = new HashMap<String, Date>();
  29.     private static HashMap<String, Integer> activeSessionsReset = new HashMap<String, Integer>();
  30.     private static HashMap<String, String> renamedLogins = new HashMap<String, String>();

  31.     public SessionManager() {
  32.     }

  33.     public static int getNumActiveSessions() {
  34.         return activeSessionsStarted.size();
  35.     }

  36.     public static Date getSessionStart(String login) {
  37.         return activeSessionsStarted.get(login);
  38.     }

  39.     public static Date getSessionLastAccess(String login) {
  40.         return  activeSessionsLastAccess.get(login);
  41.     }

  42.     public static boolean getSessionNeedsReset(String login) {
  43.         return activeSessionsReset.get(login) != null ? true : false;
  44.     }

  45.     public static void createSession(String login) {
  46.         Date now = new Date();
  47.         activeSessionsStarted.put(login, now);
  48.         activeSessionsLastAccess.put(login, now);
  49.     }

  50.     public static void invalidateSession(String login) {
  51.         activeSessionsLastAccess.remove(login);
  52.         activeSessionsStarted.remove(login);
  53.         activeSessionsReset.remove(login);
  54.     }

  55.     public static void setSessionNeedsReset(String login) {
  56.         activeSessionsReset.put(login, 1);
  57.     }

  58.     public static void addRenamedLogin(String prevLogin, String newLogin) {
  59.         renamedLogins.put(prevLogin, newLogin);
  60.     }

  61.     public static void removeRenamedLogin(String prevLogin) {
  62.         renamedLogins.remove(prevLogin);
  63.     }

  64.     public static String checkRenamedLogin(String prevLogin) {
  65.         if (renamedLogins.containsKey(prevLogin)) {
  66.             return renamedLogins.get(prevLogin);
  67.         }

  68.         return null;
  69.     }

  70.     public static void clearSessionNeedsReset(String login) {
  71.         activeSessionsReset.remove(login);
  72.     }
  73. }