1 23 24 25 package com.lutris.appserver.server.sessionEnhydra; 26 27 import java.lang.reflect.Constructor ; 28 import java.util.Date ; 29 import java.util.Enumeration ; 30 31 import javax.servlet.http.HttpSession ; 32 import javax.servlet.http.HttpSessionBindingEvent ; 33 import javax.servlet.http.HttpSessionBindingListener ; 34 35 import com.lutris.appserver.server.Application; 36 import com.lutris.appserver.server.Enhydra; 37 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 38 import com.lutris.appserver.server.httpPresentation.HttpPresentationException; 39 import com.lutris.appserver.server.session.MemoryPersistence; 40 import com.lutris.appserver.server.session.Session; 41 import com.lutris.appserver.server.session.SessionException; 42 import com.lutris.appserver.server.session.SessionManager; 43 import com.lutris.appserver.server.sessionEnhydra.persistent.PersistentSessionHome; 44 import com.lutris.appserver.server.sessionEnhydra.persistent.PersistentSessionUserTable; 45 import com.lutris.appserver.server.user.User; 46 import com.lutris.logging.LogChannel; 47 import com.lutris.logging.Logger; 48 import com.lutris.util.Config; 49 import com.lutris.util.ConfigException; 50 import com.lutris.util.KeywordValueException; 51 52 53 151 public class StandardSessionManager 152 implements SessionManager, StandardSessionIdleHandler { 153 156 protected int mode; 157 163 public static final int MODE_BASIC = 1; 164 170 public static final int MODE_PAGE_TO_DISK = 2; 171 177 public static final int MODE_PAGE_TO_DB = 3; 178 183 public static final int MODE_CUSTOM = 4; 184 188 public static final String ENCODE_URL_NEVER = "Never"; 189 193 public static final String ENCODE_URL_ALWAYS = "Always"; 194 200 public static final String ENCODE_URL_AUTO = "Auto"; 201 public static final String ENCODE_RANDOM_YES = "Yes"; 202 public static final String ENCODE_RANDOM_NO = "No"; 203 211 protected static long defaultMaxSessionLifeTime = 0; 212 222 protected static long defaultMaxSessionIdleTime = 30*60; 223 236 protected static String defaultEncodeUrlState = "Auto"; 237 242 protected static long defaultIdleScanInterval = 30; 243 248 protected static long[] defaultRandomizerIntervals = { 249 301, 1001, 5003 250 }; 251 254 public static final String CFG_LIFE = "SessionLifetimeMax"; 255 258 public static final String CFG_IDLE = "SessionIdleTimeMax"; 259 262 public static final String CFG_ENCODE_URL_STATE = "SessionEncodeUrlState"; 263 267 public static final String CFG_ENCODE_FIRST_URL = "SessionEncodeFirstUrl"; 268 272 public static final String CFG_NOUSER_IDLE = "SessionNoUserIdleTimeMax"; 273 277 public static final String CFG_SCAN = "IdleScanInterval"; 278 282 public static final String CFG_RANDOM = "RandomizerIntervals"; 283 286 public static final String CFG_SESSION_HOME = "SessionHome"; 287 290 public static final String CFG_SESSION_HOME_TYPE = "SessionHome.Mode"; 291 296 public static final int SESSION_ACTIVE = 0; 297 303 public static final int SESSION_MAX_TIME = 1; 304 310 public static final int SESSION_IDLE_EXPIRE = 2; 311 316 public static final int SESSION_EXPLICT_DELETE = 3; 317 323 protected StandardSessionHome sessionHome; 325 331 private StandardSessionUserTable sessionUserTable; 332 protected int maxSessions; 334 protected Date maxSessionsDate; 335 341 private StandardSessionKeyGen keyGenerator; 342 348 private long maxSessionLifeTime; 349 355 protected long maxSessionIdleTime; 356 360 protected String encodeUrlState; 361 364 protected boolean encodeFirstUrl; 365 372 private StandardSessionIdleTimer idleTimer; 373 380 protected long maxNoUserSessionIdleTime; 381 384 protected long scanInterval; 385 388 LogChannel logChannel = null; 389 392 Application app = null; 393 396 ClassLoader classLoader; 397 400 private static final String BASIC = "BASIC"; 401 private static final String PAGE_TO_DISK = "PAGE_TO_DISK"; 402 private static final String PAGE_TO_DB = "PAGE_TO_DB"; 403 private static final String CUSTOM = "CUSTOM"; 404 407 String sessionHomeType = BASIC; 408 412 private boolean isMemoryPersistence = false; 413 414 417 private void logConfig () { 418 if (logChannel != null) { 419 logChannel.write(Logger.DEBUG, 420 "SessionManager." + CFG_LIFE + " = " 421 + maxSessionLifeTime + " sec"); 422 logChannel.write(Logger.DEBUG, 423 "SessionManager." + CFG_IDLE + " = " 424 + maxSessionIdleTime + " sec"); 425 logChannel.write(Logger.DEBUG, 426 "SessionManager." + CFG_NOUSER_IDLE + " = " 427 + maxNoUserSessionIdleTime + " sec"); 428 logChannel.write(Logger.DEBUG, 429 "SessionManager." + CFG_SCAN + " = " 430 + scanInterval + " sec"); 431 logChannel.write(Logger.DEBUG, 432 "SessionManager." + CFG_ENCODE_URL_STATE + " = " 433 + encodeUrlState); 434 logChannel.write(Logger.DEBUG, 435 "SessionManager." + CFG_ENCODE_FIRST_URL + " = " 436 + encodeFirstUrl); 437 } 438 } 439 public StandardSessionManager (){} 440 459 public StandardSessionManager (Application application, Config config, 460 LogChannel sessionMgrLogChannel) 461 throws ConfigException, SessionException { 462 app = application; 464 initManager(application.getClass().getClassLoader(),config,sessionMgrLogChannel); 465 } 466 467 public StandardSessionManager (ClassLoader classLoader, Config config, 468 LogChannel sessionMgrLogChannel) throws ConfigException, SessionException { 469 initManager(classLoader,config,sessionMgrLogChannel); 470 } 471 472 private void initManager (ClassLoader classLoader, Config config, 473 LogChannel sessionMgrLogChannel) throws ConfigException, SessionException { 474 this.classLoader = classLoader; 475 logChannel = sessionMgrLogChannel; 476 maxSessions = 0; 478 maxSessionsDate = new Date (); 479 483 if (config.containsKey("MemoryPersistence")) { 484 String mp = config.getString("MemoryPersistence"); 485 if (mp.equals("true")) 486 isMemoryPersistence = true; 487 } 488 492 if (config.containsKey(CFG_LIFE)) { 494 maxSessionLifeTime = config.getLong(CFG_LIFE)*60; 495 } 496 else if (config.containsKey("Lifetime")) { 497 maxSessionLifeTime = config.getLong("Lifetime")*60; 499 } 500 else { 501 maxSessionLifeTime = defaultMaxSessionLifeTime; 502 } 503 if (config.containsKey(CFG_IDLE)) { 505 maxSessionIdleTime = config.getLong(CFG_IDLE)*60; 506 } 507 else if (config.containsKey("MaxIdleTime")) { 508 maxSessionIdleTime = config.getLong("MaxIdleTime")*60; 510 } 511 else { 512 maxSessionIdleTime = defaultMaxSessionIdleTime; 513 } 514 if (config.containsKey(CFG_ENCODE_URL_STATE)) { 516 encodeUrlState = config.getString(CFG_ENCODE_URL_STATE); 517 } 518 else if (config.containsKey("EncodeUrlState")) { 519 encodeUrlState = config.getString("EncodeUrlState"); 521 } 522 else { 523 encodeUrlState = defaultEncodeUrlState; 524 } 525 if (!encodeUrlState.equalsIgnoreCase(ENCODE_URL_NEVER) && !encodeUrlState.equalsIgnoreCase(ENCODE_URL_ALWAYS) 526 && !encodeUrlState.equalsIgnoreCase(ENCODE_URL_AUTO)) { 527 throw new ConfigException("EncodeUrlState must be one of the following: " 528 + ENCODE_URL_NEVER + ", " + ENCODE_URL_ALWAYS + ", or " + ENCODE_URL_AUTO 529 + "."); 530 } 531 532 536 if (config.containsKey(CFG_ENCODE_FIRST_URL)) { 537 encodeFirstUrl = config.getBoolean(CFG_ENCODE_FIRST_URL, false); 538 } else { 539 encodeFirstUrl = false; 540 } 541 542 547 if (encodeUrlState.equalsIgnoreCase(ENCODE_URL_ALWAYS)){ 548 encodeFirstUrl = true; 549 } else if (encodeUrlState.equalsIgnoreCase(ENCODE_URL_NEVER)) { 550 encodeFirstUrl = false; 551 } 552 553 if (config.containsKey(CFG_NOUSER_IDLE)) { 554 maxNoUserSessionIdleTime = config.getLong(CFG_NOUSER_IDLE)*60; 555 } 556 else if (config.containsKey("MaxNoUserIdleTime")) { 557 maxNoUserSessionIdleTime = config.getLong("MaxNoUserIdleTime")*60; 559 } 560 else { 561 maxNoUserSessionIdleTime = maxSessionIdleTime; 562 } 563 scanInterval = defaultIdleScanInterval; 564 if (config.containsKey(CFG_SCAN)) { 565 scanInterval = config.getLong(CFG_SCAN); 566 } 567 else if (config.containsKey("IdleScanInterval")) { 568 scanInterval = config.getLong("IdleScanInterval"); 570 } 571 if (scanInterval <= 0) { 572 throw new ConfigException("IdleScanInterval must be greater than zero."); 573 } 574 idleTimer = new StandardSessionIdleTimer(this, app, scanInterval); 575 if (config.containsKey(CFG_SESSION_HOME_TYPE)) { 576 sessionHomeType = config.getString(CFG_SESSION_HOME_TYPE); 577 } 578 if (!sessionHomeType.equalsIgnoreCase(BASIC) && !sessionHomeType.equalsIgnoreCase(PAGE_TO_DISK) 579 && !sessionHomeType.equalsIgnoreCase(PAGE_TO_DB) && !sessionHomeType.equalsIgnoreCase(CUSTOM)) { 580 throw new ConfigException("Invalid " + CFG_SESSION_HOME_TYPE + ": '" 581 + sessionHomeType + "'"); 582 } 583 sessionHome = loadSessionHome(config); 585 sessionUserTable = loadSessionUserTable(config); 587 long[] intervals = config.getLongs(CFG_RANDOM, defaultRandomizerIntervals); 589 if (intervals.length == 0) { 590 throw new ConfigException(CFG_RANDOM + " must contain some values."); 591 } 592 for (int i = 0; i < intervals.length; i++) { 593 if (intervals[i] <= 0) { 594 throw new ConfigException(CFG_RANDOM + " must contain positive integers."); 595 } 596 } 597 keyGenerator = new StandardSessionKeyGen(intervals); 598 keyGenerator.start(); 600 idleTimer.start(); 601 logConfig(); 602 } 603 604 614 protected StandardSessionHome loadSessionHome (Config config) throws ConfigException, 615 SessionException { 616 try { 617 StandardSessionHome sessionHome = null; 618 Config homeConfig = null; 619 if (config.containsKey(CFG_SESSION_HOME)) { 620 homeConfig = (Config)config.getSection(CFG_SESSION_HOME); 621 } 622 else { 623 homeConfig = new Config(); 624 } 625 if (sessionHomeType.equalsIgnoreCase(CUSTOM)) { 626 if (homeConfig.containsKey("Class")) { 627 String homeClassName = homeConfig.getString("Class"); 628 try { 629 Class [] paramTypes = new Class [3]; 630 Object [] args = new Object [3]; 631 paramTypes[0] = Class.forName("com.lutris.appserver.server.sessionEnhydra.StandardSessionManager"); 632 paramTypes[1] = Class.forName("com.lutris.util.Config"); 633 paramTypes[2] = Class.forName("java.lang.ClassLoader"); 634 args[0] = this; 635 args[1] = homeConfig; 636 args[2] = classLoader; 637 Constructor c = Class.forName(homeClassName).getConstructor(paramTypes); 638 sessionHome = (StandardSessionHome)c.newInstance(args); 639 if (logChannel != null) { 640 logChannel.write(Logger.DEBUG, "SessionMgr: " 641 + "StandardSessionHome: " + homeClassName); 642 } 643 } catch (Exception e) { 644 throw new SessionException("Unable to load " + homeClassName, 645 e); 646 } 647 } 648 mode = MODE_CUSTOM; 649 } 650 else if (sessionHomeType.equalsIgnoreCase(PAGE_TO_DISK)) { 651 sessionHome = new DiskPagedSessionHome(this, homeConfig, classLoader); 652 mode = MODE_PAGE_TO_DISK; 653 } 654 else if (sessionHomeType.equalsIgnoreCase(PAGE_TO_DB)) { 655 sessionHome = new PersistentSessionHome(this, homeConfig, classLoader); 656 mode = MODE_PAGE_TO_DB; 657 } 658 else { 659 sessionHome = new BasicSessionHome(this, homeConfig); 660 mode = MODE_BASIC; 661 } 662 if (logChannel != null) { 663 logChannel.write(Logger.DEBUG, "SessionMgr: " 664 + "StandardSessionHome: " + sessionHomeType + "\n"); 665 } 666 return sessionHome; 667 } catch (KeywordValueException e) { 668 e.printStackTrace(); 669 throw new ConfigException("SessionMgr: unable to load StandardSessionHome: " 670 + e); 671 } 672 } 673 674 682 protected StandardSessionUserTable loadSessionUserTable (Config config) throws ConfigException, 683 SessionException { 684 try { 685 StandardSessionUserTable sessionUserTable = null; 686 Config userTableConfig = null; 687 if (config.containsKey("SessionUserTable")) { 688 userTableConfig = (Config)config.getSection("SessionUserTable"); 689 } 690 else { 691 userTableConfig = new Config(); 692 } 693 if (sessionHomeType.equalsIgnoreCase(CUSTOM)) { 694 String tableClassName = userTableConfig.getString("Class"); 695 try { 696 Class [] paramTypes = new Class [1]; 697 Object [] args = new Object [1]; 698 paramTypes[0] = Class.forName("com.lutris.util.Config"); 699 args[0] = userTableConfig; 700 Constructor c = Class.forName(tableClassName).getConstructor(paramTypes); 701 sessionUserTable = (StandardSessionUserTable)c.newInstance(args); 702 if (logChannel != null) { 703 logChannel.write(Logger.DEBUG, "SessionMgr: " 704 + "StandardSessionUserTable: " + tableClassName); 705 } 706 } catch (NoSuchMethodException e) { 707 throw new SessionException("Unable to load " + tableClassName + 708 ": " + "Constructor not found.", e); 709 } catch (Exception e) { 710 throw new SessionException("Unable to create instance of " + tableClassName, 711 e); 712 } 713 } 714 else if (sessionHomeType.equalsIgnoreCase(PAGE_TO_DISK)) { 715 sessionUserTable = new PagedSessionUserTable(userTableConfig); 716 } 717 else if (sessionHomeType.equalsIgnoreCase(PAGE_TO_DB)) { 718 sessionUserTable = new PersistentSessionUserTable(userTableConfig); 719 } 720 else { 721 sessionUserTable = new BasicSessionUserTable(userTableConfig); 722 } 723 return sessionUserTable; 724 } catch (KeywordValueException e) { 725 throw new ConfigException("SessionMgr: unable to load StandardSessionUserTable: " 726 + e); 727 } 728 } 729 730 734 public synchronized void shutdown () { 735 if (isMemoryPersistence) 736 MemoryPersistence.putSessionManager(app.getName(), this); 737 else { 738 if (keyGenerator != null) { 739 keyGenerator.shutdown(); 740 keyGenerator = null; 741 } 742 if (idleTimer != null) { 743 idleTimer.shutdown(); 744 idleTimer = null; 745 } 746 if (sessionHome != null) { 747 sessionHome.shutdown(); 748 sessionHome = null; 749 } 750 if (sessionUserTable != null) { 751 sessionUserTable.shutdown(); 752 sessionUserTable = null; 753 } 754 } 755 } 756 757 770 protected StandardSession newSession (String sessionKey) throws CreateSessionException, 771 SessionException { 772 return (StandardSession)sessionHome.createSession(sessionKey); 773 } 774 775 785 public Session createSession () throws SessionException { 786 return createSession(""); 787 } 788 789 801 public Session createSession (String ipPortToken) throws SessionException { 802 StandardSession session = null; 803 String sessionKey = null; 804 809 do { 810 try { 811 sessionKey = keyGenerator.newSessionKey(); 812 if (ipPortToken != null && ipPortToken.length() > 0) { 813 sessionKey = sessionKey.substring(0,sessionKey.length()-2)+ipPortToken; 814 } 815 session = sessionHome.createSession(sessionKey); 816 } catch (DuplicateKeyException e) { 817 session = null; 819 } 820 } while (session == null); 821 int currentSize = sessionHome.size(); 822 if (currentSize > maxSessions) { 823 maxSessions = currentSize; 824 maxSessionsDate = new Date (); 825 } 826 keyGenerator.incrementRandomCounter(); 827 if (logChannel != null) { 828 logChannel.write(Logger.DEBUG, "SessionMgr: createSession: " + sessionKey); 829 } 830 return session; 831 } 832 833 public Session createSession (HttpPresentationComms comms) throws SessionException { 834 Session s = null; 835 String saTok = null; 836 try { 837 saTok = comms.request.getHeader(":aff:"); 838 } catch (HttpPresentationException hpe) { 839 saTok = null; 840 } 841 if (saTok == null) { 842 s = createSession(); 843 } 844 else { 845 s = createSession(saTok); 846 if (logChannel != null) { 847 logChannel.write(Logger.DEBUG, 848 "SessionKey created for EnhydraDirector"); 849 } 850 } 851 return s; 852 } 853 854 857 private void logRegisterUser (Session session, String which) { 858 if (logChannel != null) { 859 String userName = null; 860 User user = session.getUser(); 861 if (user != null) { 862 userName = user.getName(); 863 } 864 logChannel.write(Logger.DEBUG, "SessionMgr: " 865 + which + ": " + session.getSessionKey() + 866 " user = \"" + userName + "\""); 867 } 868 } 869 870 883 protected synchronized void registerUser (Session session) throws SessionException { 884 sessionUserTable.add(session.getSessionKey(), session.getUser()); 885 logRegisterUser(session, "registerUser"); 886 } 887 888 899 protected synchronized void unregisterUser (Session session) throws SessionException { 900 logRegisterUser(session, "unregisterUser"); 901 sessionUserTable.remove(session.getSessionKey(), session.getUser()); 902 } 903 904 920 protected int isSessionExpired (StandardSession session) { 921 long now = System.currentTimeMillis(); 922 926 long maxAge = session.getTimeExpires(); 927 if ((maxAge > 0) && (now > maxAge)) { 928 return SESSION_MAX_TIME; 929 } 930 935 long idle = now - session.getTimeLastUsed(); 936 long maxIdle; 937 if (session.getUser() != null) { 938 maxIdle = session.getMaxIdleTime(); 939 } 940 else { 941 maxIdle = session.getMaxNoUserIdleTime(); 942 } 943 if ((maxIdle > 0) && (idle > maxIdle)) { 944 return SESSION_IDLE_EXPIRE; 945 } 946 949 return SESSION_ACTIVE; 950 } 951 952 966 protected void sessionDeleted (Session session, int reason) { 967 } 969 970 978 private void doDeleteSession (StandardSession session, int reason) throws SessionException { 979 keyGenerator.incrementRandomCounter(); 980 if (logChannel != null) { 981 String userName = null; 982 User user = session.getUser(); 983 if (user != null) { 984 userName = user.getName(); 985 } 986 String reasonMsg; 987 switch (reason) { 988 case SESSION_ACTIVE: 989 reasonMsg = "SESSION_ACTIVE"; 990 break; 991 case SESSION_MAX_TIME: 992 reasonMsg = "SESSION_MAX_TIME"; 993 break; 994 case SESSION_IDLE_EXPIRE: 995 reasonMsg = "SESSION_IDLE_EXPIRE"; 996 break; 997 case SESSION_EXPLICT_DELETE: 998 reasonMsg = "SESSION_EXPLICT_DELETE"; 999 break; 1000 default: 1001 reasonMsg = "bad reason code " + reason; 1002 break; 1003 } 1004 logChannel.write(Logger.DEBUG, "SessionMgr deleteSession: " 1005 + session.getSessionKey() + " user = \"" + userName 1006 + "\" reason = " + reasonMsg); 1007 } 1008 HttpSession hs = session.getHttpSession(); 1011 for (Enumeration e = hs.getAttributeNames(); e.hasMoreElements();) { 1012 String key = (String )e.nextElement(); 1013 Object value = hs.getAttribute(key); 1014 if (value instanceof HttpSessionBindingListener ) { 1015 try { 1016 ((HttpSessionBindingListener )value).valueUnbound(new HttpSessionBindingEvent (hs, 1017 key)); 1018 } catch (Exception ex) { 1019 } 1021 } 1022 } 1023 if (session.getUser() != null) { 1024 sessionUserTable.remove(session.getSessionKey(), session.getUser()); 1025 } 1026 sessionHome.removeSession(session.getSessionKey()); 1027 } 1028 1029 1038 public synchronized void deleteSession (Session session) throws SessionException { 1039 sessionDeleted((StandardSession)session, SESSION_EXPLICT_DELETE); 1040 doDeleteSession((StandardSession)session, SESSION_EXPLICT_DELETE); 1041 } 1042 1043 1053 public synchronized void deleteSession (String sessionKey) throws SessionException { 1054 Session session = (Session )sessionHome.getSession(Thread.currentThread(), sessionKey); 1055 if (session != null) { 1056 deleteSession(session); 1057 } 1058 } 1059 1060 1070 public void passivateSession (Thread thread, String sessionKey) throws SessionException { 1071 sessionHome.passivateSession(thread, sessionKey); 1072 } 1073 1074 1081 public void cleanUpIdleSessions () throws SessionException { 1082 Enumeration e = sessionHome.keys(); 1083 StandardSession session; 1084 String sessionKey; 1085 debug(3, "checking for idle sessions... "); 1086 while (e.hasMoreElements()) { 1087 sessionKey = (String )e.nextElement(); 1088 session = (StandardSession)sessionHome.getSession(Thread.currentThread(), 1089 sessionKey); 1090 if (session != null) { 1091 int stat = isSessionExpired(session); 1092 if (stat != SESSION_ACTIVE) { 1093 debug(3, "cleaning up idle session: " + sessionKey); 1094 sessionDeleted(session, stat); 1095 doDeleteSession(session, stat); 1096 } else { 1097 sessionHome.passivateSession(Thread.currentThread(), sessionKey); 1098 } 1099 } 1100 } 1101 } 1102 1103 1114 public synchronized boolean sessionExists (String sessionKey) throws SessionException { 1115 if (sessionKey == null) { 1116 return false; 1117 } 1118 return sessionHome.containsKey(sessionKey); 1119 } 1120 1121 1138 public synchronized Session getSession (String sessionKey) throws SessionException { 1139 keyGenerator.incrementRandomCounter(); 1140 StandardSession session = (StandardSession)sessionHome.getSession(sessionKey); 1141 if (session != null) { 1142 session.touch(); 1143 } 1144 else { 1145 sessionUserTable.remove(sessionKey); 1146 } 1147 return session; 1148 } 1149 1150 1168 public synchronized Session getSession (Thread thread, String sessionKey) throws SessionException { 1169 keyGenerator.incrementRandomCounter(); 1170 StandardSession session = (StandardSession)sessionHome.getSession(thread, 1171 sessionKey); 1172 if (session != null) { 1173 session.touch(); 1174 } 1175 else { 1176 sessionUserTable.remove(sessionKey); 1177 } 1178 return session; 1179 } 1180 1181 1185public synchronized Session getSession (Thread thread, String sessionKey, HttpPresentationComms comms) throws SessionException { 1186 1187 Session session=getSession (thread, sessionKey); 1188 1189String saTokChangeRequest=null; 1190 1196 if(saTokChangeRequest!=null&&session!=null) 1197 { 1198 deleteSession(session); 1199 return null; 1200 } 1201 else 1202 { 1203 return session; 1204 } 1205} 1206 1227 public synchronized Session getSaveSession (Thread thread, String sessionKey) throws SessionException { 1228 keyGenerator.incrementRandomCounter(); 1229 StandardSession session = (StandardSession)sessionHome.getSession(thread, 1230 sessionKey); 1231 if (session != null) { 1232 } 1234 else { 1235 sessionUserTable.remove(sessionKey); 1236 } 1237 return session; 1238 } 1239 1240 1247 public synchronized Enumeration getSessionKeys () throws SessionException { 1248 return sessionHome.keys(); 1249 } 1250 1251 1262 public synchronized Enumeration getSessionKeys (User user) throws SessionException { 1263 return sessionUserTable.getSessionKeys(user); 1264 } 1265 1266 1273 public int activeSessionCount () throws SessionException { 1274 return sessionHome.size(); 1275 } 1276 1277 1284 public int pagedSessionCount () throws SessionException { 1285 return sessionHome.pagedSize(); 1286 } 1287 1288 1299 public int getMode () throws SessionException { 1300 return mode; 1301 } 1302 1303 1311 public int maxSessionCount () { 1312 return maxSessions; 1313 } 1314 1315 1321 public Date maxSessionCountDate () { 1322 return maxSessionsDate; 1323 } 1324 1325 1332 public void resetMaxSessionCount () throws SessionException { 1333 maxSessions = sessionHome.size(); 1334 maxSessionsDate = new Date (); 1335 } 1336 1337 1340 public long getMaxSessionLifeTime () { 1341 return maxSessionLifeTime; 1342 } 1343 1344 1347 public void setMaxSessionIdleTime (long maxSessionIdleTime) { 1348 this.maxSessionIdleTime = maxSessionIdleTime; 1349 } 1350 1351 1354 public long getMaxSessionIdleTime () { 1355 return maxSessionIdleTime; 1356 } 1357 1358 1362 public String getEncodeUrlState () { 1363 return encodeUrlState; 1364 } 1365 1366 1371 public boolean getEncodeFirstUrl() { 1372 return encodeFirstUrl; 1373 } 1374 1375 1378 public long getMaxNoUserSessionIdleTime () { 1379 return maxNoUserSessionIdleTime; 1380 } 1381 1382 1388 protected void debug(int level, String msg) { 1389 int dbg = Logger.DEBUG; 1390 switch (level) { 1391 case 1: 1392 dbg = Logger.DEBUG1; 1393 break; 1394 case 2: 1395 dbg = Logger.DEBUG2; 1396 break; 1397 case 3: 1398 dbg = Logger.DEBUG3; 1399 break; 1400 case 4: 1401 dbg = Logger.DEBUG4; 1402 break; 1403 case 5: 1404 dbg = Logger.DEBUG5; 1405 break; 1406 case 6: 1407 dbg = Logger.DEBUG6; 1408 break; 1409 case 7: 1410 dbg = Logger.DEBUG7; 1411 break; 1412 case 8: 1413 dbg = Logger.DEBUG8; 1414 break; 1415 case 9: 1416 dbg = Logger.DEBUG9; 1417 break; 1418 default: 1419 dbg = Logger.DEBUG; 1420 break; 1421 } 1422 Enhydra.getLogChannel().write(dbg, "PersistentSessionHome(" 1423 + Thread.currentThread().getName() 1424 + "): " + msg); 1425 } 1426} 1427 1428 1429 1430 | Popular Tags |