1 2 24 25 package com.lutris.appserver.server.sessionEnhydra; 26 27 import java.util.Enumeration ; 28 29 import com.lutris.appserver.server.session.Session; 30 import com.lutris.appserver.server.session.SessionData; 31 import com.lutris.appserver.server.session.SessionException; 32 import com.lutris.appserver.server.session.SessionManager; 33 import com.lutris.appserver.server.user.User; 34 35 41 public class SessionUtil { 42 43 46 private SessionUtil() { 47 } 48 49 59 public static void logIn(User user, Session session, boolean multiple) 60 throws SessionException { 61 SessionManager mgr = session.getSessionManager(); 62 synchronized(mgr) { 63 if (!multiple) { 64 Enumeration e = mgr.getSessionKeys(user); 65 while (e.hasMoreElements()) { 66 String key = (String )e.nextElement(); 67 mgr.deleteSession(key); 68 } 69 } 70 session.setUser(user); 71 } 72 } 73 74 82 public static void logOut(Session session) 83 throws SessionException { 84 if (session != null) { 85 SessionManager mgr = session.getSessionManager(); 86 mgr.deleteSession(session); 87 } 88 } 89 90 103 public static boolean resumeLogIn(User user, Session session) 104 throws SessionException { 105 SessionManager mgr = session.getSessionManager(); 106 try { 107 synchronized (mgr) { 108 Enumeration e = mgr.getSessionKeys(user); 109 if (e.hasMoreElements()) { 110 String key = (String )e.nextElement(); 111 if (e.hasMoreElements()) { 112 return false; 114 } 115 Session oldSession = mgr.getSession(Thread.currentThread(), key); 116 SessionData dataSrc = oldSession.getSessionData(); 117 SessionData dataDst = session.getSessionData(); 118 String [] k = dataSrc.keys(); 120 for (int i=0; i<k.length; i++) { 121 dataDst.set(k[i], dataSrc.get(k[i])); 122 } 123 SessionUtil.logIn(user, session, false); 124 return true; 125 } 126 } 127 } catch (SessionException e) { 128 throw e; 129 } catch (Exception e) { 130 throw new SessionException(e); 131 } 132 return false; 133 } 134 } 135 | Popular Tags |