Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2012  |  syntax: None  |  size: 65.89 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  2.  
  3. package com.ibm.ws.webcontainer.httpsession;
  4.  
  5. import com.ibm.ejs.ras.Tr;
  6. import com.ibm.ejs.ras.TraceComponent;
  7. import com.ibm.ejs.sm.client.ui.NLS;
  8. import com.ibm.ejs.util.am.Alarm;
  9. import com.ibm.websphere.security.WSSecurityHelper;
  10. import com.ibm.websphere.servlet.session.IBMSessionListener;
  11. import com.ibm.websphere.servlet.session.UnauthorizedSessionRequestException;
  12. import com.ibm.ws.ffdc.FFDCFilter;
  13. import com.ibm.ws.management.AdminHelper;
  14. import com.ibm.ws.security.core.SecurityContext;
  15. import com.ibm.ws.security.util.AccessController;
  16. import com.ibm.ws.util.WSThreadLocal;
  17. import com.ibm.ws.webcontainer.session.IHttpSessionContext;
  18. import com.ibm.ws.webcontainer.srt.IExtendedRequest;
  19. import com.ibm.ws.webcontainer.srt.IExtendedResponse;
  20. import com.ibm.ws.webcontainer.util.EncodeCloneID;
  21. import com.ibm.ws390.rt.HTTPSessionAffinity;
  22. import com.ibm.wsspi.hamanager.HAGroup;
  23. import com.ibm.wsspi.hamanager.datastack.MsgQoS;
  24. import com.ibm.wsspi.webcontainer.servlet.IServletContext;
  25. import java.io.UnsupportedEncodingException;
  26. import java.net.InetAddress;
  27. import java.net.UnknownHostException;
  28. import java.security.PrivilegedActionException;
  29. import java.security.PrivilegedExceptionAction;
  30. import java.util.*;
  31. import javax.servlet.ServletContext;
  32. import javax.servlet.http.*;
  33.  
  34. // Referenced classes of package com.ibm.ws.webcontainer.httpsession:
  35. //            BaseSessionContext, SessionContextMBeanAdapter, SessionTrackingPMIApplicationData, SessionData,
  36. //            SessionIDGen, SessionSimpleHashMap, IHttpSession, SessionContextParameterException,
  37. //            TooManySessionsException, SessionCrossoverStackTrace, SessionApplicationParameters, SessionMgrComponentImpl,
  38. //            SessionAlarmListener, SessionContextRegistry, IDFactory, SessionContextParameters,
  39. //            HttpSessionSystemProperties
  40.  
  41. public abstract class SessionContext extends BaseSessionContext implements
  42.                 IHttpSessionContext {
  43.  
  44.         SessionContext(SessionContextParameters sessioncontextparameters,
  45.                         SessionApplicationParameters sessionapplicationparameters) {
  46.                 tableSize = 1000;
  47.                 allowInfinite = true;
  48.                 overflowData = null;
  49.                 mInvalidationCheckPollInterval = -1L;
  50.                 mSessionInvalidationTime = 1800L;
  51.                 mSessionTrackingActive = true;
  52.                 mUsingCookies = true;
  53.                 mUsingURL = false;
  54.                 mURLProtocolSwitchRewritingActive = false;
  55.                 mSessionCookieName = "JSESSION";
  56.                 mSessionCookieComment = "Session id";
  57.                 mSessionCookieMaxAge = -1;
  58.                 mSessionCookiePath = "/";
  59.                 mSessionCookieSecure = false;
  60.                 counterSyncher = new Object();
  61.                 mSessions = null;
  62.                 mSessionIdCounter = 0;
  63.                 mParams = null;
  64.                 scAppParms = null;
  65.                 scPmiData = null;
  66.                 scEnablePmi = true;
  67.                 stopSession = false;
  68.                 integrateWASSec = false;
  69.                 useSSLId = false;
  70.                 sessionAttributeListener = false;
  71.                 sessionListener = false;
  72.                 mHttpSessionAttributeListeners = new ArrayList();
  73.                 mHttpSessionListeners = new ArrayList();
  74.                 mServletContext = null;
  75.                 timedOutAffinityEnabled = true;
  76.                 affinityTimeOut = 30L;
  77.                 allowSerializedSessionAccess = false;
  78.                 serializedSessionAccessMaxWaitTime = 0;
  79.                 accessSessionOnTimeout = false;
  80.                 mbeanAdapter = null;
  81.                 cacheIdLength = 4;
  82.                 cacheIdPlusIdlength = cacheIdLength + sessionIDLength;
  83.                 createSync = new HashMap();
  84.                 mIBMSessionListenerImplemented = false;
  85.                 crossoverUserThreadWarningIssued = false;
  86.                 onlyCheckInCacheDuringPreInvoke = false;
  87.                 cloneIdWithSep = null;
  88.                 _refCount = 1;
  89.                 maxSessionIdentifierLength = 1024;
  90.                 mParams = sessioncontextparameters;
  91.                 scAppParms = sessionapplicationparameters;
  92.                 if (mParams == null && scAppParms == null)
  93.                         return;
  94.                 if (randIdGen == null)
  95.                         randIdGen = new Random(System.currentTimeMillis());
  96.                 self = this;
  97.                 mbeanAdapter = new SessionContextMBeanAdapter(this);
  98.                 scPmiData = new SessionTrackingPMIApplicationData(
  99.                                 sessionapplicationparameters, mbeanAdapter);
  100.                 try {
  101.                         setServletContext(scAppParms.getServletContext());
  102.                 } catch (Exception exception) {
  103.                         FFDCFilter
  104.                                         .processException(
  105.                                                         exception,
  106.                                                         "com.ibm.ws.webcontainer.httpsession.SessionContext.moreInit",
  107.                                                         "294", this);
  108.                         Tr.error(tc, "SessionContext.exception", exception);
  109.                 }
  110.         }
  111.  
  112.         void init()
  113.     {
  114.         is_zOS = SessionMgrComponentImpl.is_zOS();
  115.         setProperties(SessionMgrComponentImpl.getWebContainerProperties());
  116.         setThreadContext();
  117.         initializeParameters();
  118.         moreInit();
  119.         unsetThreadContext();
  120.         break MISSING_BLOCK_LABEL_39;
  121.         Exception exception;
  122.         exception;
  123.         unsetThreadContext();
  124.         throw exception;
  125.     }
  126.  
  127.         void moreInit() {
  128.                 mSessions = createSessionTable();
  129.                 if (!allowInfinite && overflowData == null) {
  130.                         overflowData = (SessionData) createSessionData("overflowed-session");
  131.                         overflowData.setValidity(false);
  132.                         overflowData.overflowed = true;
  133.                         overflowData.setSessionContext(this);
  134.                 }
  135.                 if (sessionIdsUsedMoreThanOnce == null)
  136.                         sessionIdsUsedMoreThanOnce = new Hashtable();
  137.                 if (useJCE && sessionIDFactory == null)
  138.                         try {
  139.                                 if (useBase32)
  140.                                         sessionIDFactory = new SessionIDGen(sessionIDLength, BASE32);
  141.                                 else
  142.                                         sessionIDFactory = new SessionIDGen(sessionIDLength, BASE64);
  143.                         } catch (Throwable throwable) {
  144.                                 FFDCFilter
  145.                                                 .processException(
  146.                                                                 throwable,
  147.                                                                 "com.ibm.ws.webcontainer.httpsession.SessionContext.moreInit",
  148.                                                                 "264", this);
  149.                                 Tr.error(tc, "SessionContext.loadJCEFail");
  150.                                 Tr.error(tc, "SessionContext.exception", throwable);
  151.                                 sessionIDFactory = null;
  152.                         }
  153.                 startSessionContext();
  154.                 if (debugSessionCrossover)
  155.                         currentThreadSessionId = new WSThreadLocal();
  156.                 completedStartup = true;
  157.         }
  158.  
  159.         static String getXString(String s, String s1) {
  160.                 if (rb == null)
  161.                         rb = new NLS("com.ibm.servlet.resources.personalization");
  162.                 if (rb != null)
  163.                         return rb.getString(s, s1);
  164.                 else
  165.                         return s1;
  166.         }
  167.  
  168.         void startAlarms() {
  169.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  170.                         Tr.entry(tc, "SessionContext.startAlarms");
  171.                 invalidaterAlarm = SessionAlarmListener.startInvalidationAlarm(this,
  172.                                 mInvalidationCheckPollInterval * 1000L);
  173.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  174.                         Tr.exit(tc, "SessionContext.startAlarms");
  175.         }
  176.  
  177.         void stopAlarms() {
  178.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  179.                         Tr.entry(tc, "SessionContext.stopAlarms");
  180.                 SessionAlarmListener.stopListening(invalidaterAlarm);
  181.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  182.                         Tr.exit(tc, "SessionContext.stopAlarms");
  183.         }
  184.  
  185.         HashMap createSessionTable() {
  186.                 return new SessionSimpleHashMap(tableSize, allowInfinite);
  187.         }
  188.  
  189.         void startSessionContext() {
  190.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  191.                         Tr.entry(tc, "SessionContext.startSessionContext");
  192.                 if (sessionIDFactory == null)
  193.                         initializeSessionIdTemplate();
  194.                 startAlarms();
  195.                 stopSession = false;
  196.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  197.                         Tr.exit(tc, "SessionContext.startSessionContext");
  198.         }
  199.  
  200.         void stopSessionContext(String s) {
  201.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  202.                         Tr.entry(tc, "SessionContext.stopSessionContext");
  203.                 if (getAppName() == "GLOBAL_HTTP_SESSION_CONTEXT")
  204.                         stopListeners(s);
  205.                 decrementRefCount();
  206.                 if (_refCount > 0) {
  207.                         if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  208.                                 Tr
  209.                                                 .exit(
  210.                                                                 tc,
  211.                                                                 "SessionContext.stopSessionContext: Reference count is not zero, so returning without stopping");
  212.                         return;
  213.                 }
  214.                 invalidateAllMemorySessions();
  215.                 stopSession = true;
  216.                 tableClear();
  217.                 try {
  218.                         SessionContextRegistry.remove(scAppParms.getAppName());
  219.                 } catch (Throwable throwable) {
  220.                         FFDCFilter.processException(throwable,
  221.                                         "com.ibm.ws.webcontainer.httpsession.SessionContext.stop",
  222.                                         "2237", this);
  223.                         Tr.error(tc, "SessionContext.exception", throwable);
  224.                 }
  225.                 scPmiData.unregister();
  226.                 mbeanAdapter.unregisterMBean();
  227.                 mSessionIdCounter = 0;
  228.                 stopAlarms();
  229.                 completedStartup = false;
  230.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  231.                         Tr.exit(tc, "SessionContext.stopSessionContext");
  232.         }
  233.  
  234.         void stopListeners(String s) {
  235.                 if (s == null) {
  236.                         Tr.warning(tc, "SessionContext.stopListeners: j2eename is null");
  237.                         return;
  238.                 }
  239.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  240.                         Tr.entry(tc, "SessionContext.stopListeners for " + s);
  241.                 for (int i = mHttpSessionListeners.size() - 1; i >= 0; i--) {
  242.                         ArrayList arraylist = (ArrayList) mHttpSessionListeners.get(i);
  243.                         if (!s.equals((String) arraylist.get(0)))
  244.                                 continue;
  245.                         mHttpSessionListeners.remove(i);
  246.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  247.                                 Tr.debug(tc,
  248.                                                 "SessionContext.stopListeners: stopping http session listener for: "
  249.                                                                 + s);
  250.                 }
  251.  
  252.                 if (mHttpSessionListeners.size() == 0) {
  253.                         sessionListener = false;
  254.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  255.                                 Tr
  256.                                                 .debug(tc,
  257.                                                                 "SessionContext.stopListeners: stopped all http session listeners");
  258.                 }
  259.                 for (int j = mHttpSessionAttributeListeners.size() - 1; j >= 0; j--) {
  260.                         ArrayList arraylist1 = (ArrayList) mHttpSessionAttributeListeners
  261.                                         .get(j);
  262.                         if (!s.equals((String) arraylist1.get(0)))
  263.                                 continue;
  264.                         mHttpSessionAttributeListeners.remove(j);
  265.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  266.                                 Tr.debug(tc,
  267.                                                 "SessionContext.stopListeners: stopping http session attribute listener for: "
  268.                                                                 + s);
  269.                 }
  270.  
  271.                 if (mHttpSessionAttributeListeners.size() == 0) {
  272.                         sessionAttributeListener = false;
  273.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  274.                                 Tr
  275.                                                 .debug(tc,
  276.                                                                 "SessionContext.stopListeners: stopped all http session attribute listeners");
  277.                 }
  278.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  279.                         Tr.exit(tc, "SessionContext.stopListeners");
  280.         }
  281.  
  282.         void resetmSessions() {
  283.                 mSessions = null;
  284.         }
  285.  
  286.         private void setSessionContextParameters(
  287.                         SessionContextParameters sessioncontextparameters) {
  288.                 mParams = sessioncontextparameters;
  289.                 initializeParameters();
  290.         }
  291.  
  292.         SessionContextParameters getSessionContextParameters() {
  293.                 return mParams;
  294.         }
  295.  
  296.         private InetAddress getLocalHost()
  297.     {
  298.         if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  299.             Tr.debug(tc, "SessionContext.getLocalHost");
  300.         if(mLocalHost == null)
  301.             synchronized(this)
  302.             {
  303.                 try
  304.                 {
  305.                     if(is_zOS)
  306.                         mLocalHost = AdminHelper.getInstance().getLocalHost();
  307.                     else
  308.                         mLocalHost = (InetAddress)AccessController.doPrivileged(new PrivilegedExceptionAction() {
  309.  
  310.                             public Object run()
  311.                                 throws UnknownHostException
  312.                             {
  313.                                 return InetAddress.getLocalHost();
  314.                             }
  315.  
  316.            
  317.                 throws UnknownHostException
  318.             {
  319.                 super();
  320.             }
  321.                         }
  322. );
  323.                     if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  324.                         Tr.debug(tc, "SessionContext:getLocalHost: InetAddress = " + mLocalHost);
  325.                 }
  326.                 catch(PrivilegedActionException privilegedactionexception)
  327.                 {
  328.                     FFDCFilter.processException(privilegedactionexception, "com.ibm.ws.webcontainer.httpsession.SessionContext.getLocalHost", "423", this);
  329.                     Tr.error(tc, "SessionContext.getLocalHostError");
  330.                     Tr.error(tc, "SessionContext.exception", privilegedactionexception);
  331.                 }
  332.                 catch(Exception exception)
  333.                 {
  334.                     FFDCFilter.processException(exception, "com.ibm.ws.webcontainer.httpsession.SessionContext.getLocalHost", "427", this);
  335.                     Tr.error(tc, "SessionContext.getLocalHostError");
  336.                     Tr.error(tc, "SessionContext.exception", exception);
  337.                 }
  338.             }
  339.         return mLocalHost;
  340.     }
  341.  
  342.         void initializeSessionIdTemplate() {
  343.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  344.                         Tr.entry(tc, "SessionContext.initializeSessionIdTemplate");
  345.                 int i = 14;
  346.                 if (useBase32)
  347.                         i = (sessionIDLength * 5) / 8 + 1;
  348.                 else
  349.                         i = (sessionIDLength * 6) / 8 + 1;
  350.                 mSessionIdTemplate = new byte[i];
  351.                 int j = 8;
  352.                 byte abyte0[] = getLocalHost().getAddress();
  353.                 System.arraycopy(abyte0, 0, mSessionIdTemplate, j, 4);
  354.                 j += 4;
  355.                 int k = randIdGen.nextInt();
  356.                 mSessionIdTemplate[j++] = (byte) (k >> 8 & 255);
  357.                 mSessionIdTemplate[j++] = (byte) (k & 255);
  358.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  359.                         Tr.exit(tc, "SessionContext.initializeSessionIdTemplate");
  360.         }
  361.  
  362.         int generateSessionIdCount() {
  363.                 int i = 0;
  364.                 synchronized (counterSyncher) {
  365.                         i = mSessionIdCounter++;
  366.                 }
  367.                 return i;
  368.         }
  369.  
  370.         String generateSessionId() {
  371.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  372.                         Tr.entry(tc, "SessionContext.generateSessionId");
  373.                 if (sessionIDFactory != null) {
  374.                         return sessionIDFactory.getNextID();
  375.                 } else {
  376.                         byte abyte0[] = new byte[mSessionIdTemplate.length];
  377.                         System.arraycopy(mSessionIdTemplate, 0, abyte0, 0,
  378.                                         mSessionIdTemplate.length);
  379.                         int i = 0;
  380.                         int j = generateSessionIdCount();
  381.                         int k = j;
  382.                         long l = System.currentTimeMillis();
  383.                         k = k * 39 + (int) (l >> 32 & -1L);
  384.                         k = k * 39 + (int) (l & -1L);
  385.                         abyte0[i++] = (byte) (k >> 24 & 255);
  386.                         abyte0[i++] = (byte) (k >> 16 & 255);
  387.                         abyte0[i++] = (byte) (k >> 8 & 255);
  388.                         abyte0[i++] = (byte) (k & 255);
  389.                         abyte0[i++] = (byte) (j >> 24 & 255);
  390.                         abyte0[i++] = (byte) (j >> 16 & 255);
  391.                         abyte0[i++] = (byte) (j >> 8 & 255);
  392.                         abyte0[i++] = (byte) (j & 255);
  393.                         return convertSessionIdBytesToSessionId(abyte0);
  394.                 }
  395.         }
  396.  
  397.         static String convertSessionIdBytesToSessionId(byte abyte0[]) {
  398.                 if (useBase32)
  399.                         return convertSessionIdBytesToSessionIdBase32(abyte0);
  400.                 else
  401.                         return convertSessionIdBytesToSessionIdBase64(abyte0);
  402.         }
  403.  
  404.         static String convertSessionIdBytesToSessionIdBase32(byte abyte0[]) {
  405.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  406.                         Tr.entry(tc,
  407.                                         "SessionContext.convertSessionIdBytesToSessionIdBase32");
  408.                 int i = abyte0.length * 8;
  409.                 char ac[] = new char[sessionIDLength];
  410.                 int j = 0;
  411.                 int k = 0;
  412.                 int l = 0;
  413.                 do {
  414.                         if (j >= abyte0.length || l >= sessionIDLength)
  415.                                 break;
  416.                         int i1 = 0;
  417.                         if (k <= 3) {
  418.                                 i1 = abyte0[j] >> 3 - k & 31;
  419.                         } else {
  420.                                 i1 = abyte0[j] << 5 - (8 - k);
  421.                                 if (j + 1 < abyte0.length) {
  422.                                         int j1 = (abyte0[j + 1] & 255) >> 8 - (5 - (8 - k));
  423.                                         j1 &= sSecondByteMasks[5 - (8 - k)];
  424.                                         i1 |= j1;
  425.                                 }
  426.                                 i1 &= 31;
  427.                         }
  428.                         ac[l++] = sBitChars[i1];
  429.                         if ((k += 5) >= 8) {
  430.                                 j++;
  431.                                 k -= 8;
  432.                         }
  433.                 } while (true);
  434.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  435.                         Tr
  436.                                         .exit(tc,
  437.                                                         "SessionContext.convertSessionIdBytesToSessionIdBase32");
  438.                 return new String(ac);
  439.         }
  440.  
  441.         static String convertSessionIdBytesToSessionIdBase64(byte abyte0[]) {
  442.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  443.                         Tr.entry(tc,
  444.                                         "SessionContext.convertSessionIdBytesToSessionIdBase64");
  445.                 int i = abyte0.length * 8;
  446.                 char ac[] = new char[sessionIDLength];
  447.                 int j = 0;
  448.                 int k = 0;
  449.                 int l = 0;
  450.                 do {
  451.                         if (j >= abyte0.length || l >= sessionIDLength)
  452.                                 break;
  453.                         int i1 = 0;
  454.                         if (k < 3) {
  455.                                 i1 = abyte0[j] >> 2 - k & 63;
  456.                         } else {
  457.                                 i1 = abyte0[j] << 6 - (8 - k);
  458.                                 if (j + 1 < abyte0.length) {
  459.                                         int j1 = (abyte0[j + 1] & 255) >> 8 - (6 - (8 - k));
  460.                                         j1 &= sSecondByteMasks[6 - (8 - k)];
  461.                                         i1 |= j1;
  462.                                 }
  463.                                 i1 &= 63;
  464.                         }
  465.                         ac[l++] = sBitChars[i1];
  466.                         if ((k += 6) >= 8) {
  467.                                 j++;
  468.                                 k -= 8;
  469.                         }
  470.                 } while (true);
  471.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  472.                         Tr
  473.                                         .exit(tc,
  474.                                                         "SessionContext.convertSessionIdBytesToSessionIdBase64");
  475.                 return new String(ac);
  476.         }
  477.  
  478.         boolean insertSessionOnCreation(String s, SessionData sessiondata) {
  479.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  480.                         Tr.entry(tc, "SessionContext.insertSessionOnCreation" + s);
  481.                 Object obj = tableGet(s);
  482.                 if (obj != null) {
  483.                         if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  484.                                 Tr
  485.                                                 .exit(tc,
  486.                                                                 "SessionContext:insertSessionOnCreation: Detected duplicate id.  Return true.");
  487.                         return true;
  488.                 }
  489.                 tablePut(s, sessiondata);
  490.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  491.                         Tr
  492.                                         .exit(tc,
  493.                                                         "SessionContext:insertSessionOnCreation: Return false.");
  494.                 return false;
  495.         }
  496.  
  497.         private String getAuthenticatedUser() {
  498.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  499.                         Tr.entry(tc, "SessionContext.getAuthenticatedUser");
  500.                 String s = SecurityContext.getUser();
  501.                 if (s == null)
  502.                         return "anonymous";
  503.                 else
  504.                         return s;
  505.         }
  506.  
  507.         public Enumeration getIds() {
  508.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  509.                         Tr.entry(tc, "SessionContext.getIds");
  510.                 return (new Hashtable()).keys();
  511.         }
  512.  
  513.         IHttpSession createSession(HttpServletRequest httpservletrequest, String s, boolean flag)
  514.     {
  515.         String s1;
  516.         boolean flag1;
  517.         String s3;
  518.         String s4;
  519.         String s5;
  520.         int j;
  521.         if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  522.             Tr.entry(tc, "SessionContext.createSession");
  523.         s1 = null;
  524.         flag1 = false;
  525.         if(stopSession)
  526.         {
  527.             String s2 = getXString("SessionContext.createWhenStop", "SESN0006E: SessionContext: an attempt to create a session while WebSphere Session Manager was turned off was made");
  528.             RuntimeException runtimeexception = new RuntimeException(s2);
  529.             throw runtimeexception;
  530.         }
  531.         if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  532.             Tr.debug(tc, "SessionContext:createSession entered with long id = " + s);
  533.         s3 = s;
  534.         s4 = null;
  535.         s5 = null;
  536.         if(s != null)
  537.         {
  538.             s5 = s.substring(0, cacheIdLength);
  539.             int i = s.indexOf(cloneSeparator);
  540.             if(i == -1)
  541.             {
  542.                 s = s.substring(cacheIdLength);
  543.             } else
  544.             {
  545.                 s = s.substring(cacheIdLength, i);
  546.                 s4 = s3.substring(i);
  547.             }
  548.         }
  549.         if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  550.             Tr.debug(tc, "SessionContext:createSession id without cacheId and clone info is now = " + s);
  551.         Object obj = null;
  552.         Object obj1 = null;
  553.         j = 0;
  554. _L2:
  555.         SessionData sessiondata;
  556.         String s6;
  557.         j++;
  558.         if(s == null || flag1)
  559.         {
  560.             s = generateSessionId();
  561.             if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  562.                 Tr.debug(tc, "SessionContext:createSession: generated new sessionid = " + s);
  563.         }
  564.         if(allowInfinite)
  565.         {
  566.             IHttpSession ihttpsession = createSessionData(s);
  567.             sessiondata = (SessionData)ihttpsession;
  568.         } else
  569.         {
  570.             if(isMaxAllowedReached())
  571.             {
  572.                 sessiondata = overflowData;
  573.                 scPmiData.incNoRoomForNewSession();
  574.                 if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  575.                     Tr.debug(tc, "SessionContext:createSession: overflow session ");
  576.                 return sessiondata;
  577.             }
  578.             IHttpSession ihttpsession1 = createSessionData(s);
  579.             sessiondata = (SessionData)ihttpsession1;
  580.         }
  581.         sessiondata.initSession(this);
  582.         sessiondata.setValidity(true);
  583.         long l = System.currentTimeMillis();
  584.         sessiondata.setCreationTime(l);
  585.         sessiondata.setLastAccessedTime(l);
  586.         updateCloneInfo(sessiondata, s4, true);
  587.         if(s5 != null && cacheIdLength > 0)
  588.             sessiondata.setCacheId(s5);
  589.         if(integrateWASSec)
  590.             if(securityEnabled)
  591.                 s1 = getAuthenticatedUser();
  592.             else
  593.                 s1 = httpservletrequest.getRemoteUser();
  594.         if(s1 == null)
  595.             s1 = "anonymous";
  596.         sessiondata.setUser(s1);
  597.         sessiondata.setMaxInactInterval((int)mSessionInvalidationTime);
  598.         if(flag)
  599.             sessiondata.setUsingSSL(flag);
  600.         if(s3 == null)
  601.             break MISSING_BLOCK_LABEL_622;
  602.         s6 = null;
  603.         Object obj2 = null;
  604.         synchronized(this)
  605.         {
  606.             s6 = (String)createSync.get(s);
  607.             if(s6 == null)
  608.             {
  609.                 s6 = s;
  610.                 createSync.put(s, s6);
  611.             }
  612.         }
  613.         String s7 = s6;
  614.         JVM INSTR monitorenter ;
  615.         IHttpSession ihttpsession2 = (IHttpSession)getFromMemory(s);
  616.         if(ihttpsession2 == null)
  617.         {
  618.             flag1 = processSessionOnCreation(s, sessiondata);
  619.             createSync.remove(s);
  620.         } else
  621.         {
  622.             createSync.remove(s);
  623.             return ihttpsession2;
  624.         }
  625.         s7;
  626.         JVM INSTR monitorexit ;
  627.         continue; /* Loop/switch isn't completed */
  628.         Exception exception1;
  629.         exception1;
  630.         throw exception1;
  631.         flag1 = processSessionOnCreation(s, sessiondata);
  632.         if(flag1 && j < 10) goto _L2; else goto _L1
  633. _L1:
  634.         if(j == 10 && flag1)
  635.         {
  636.             if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  637.                 Tr.debug(tc, "SessionContext:createSession: Almost stuck in createLoop");
  638.             Tr.warning(tc, "SessionManager unable to generate unique session id in 10 tries, so gave up");
  639.             return null;
  640.         }
  641.         int k = establishAffinity(sessiondata);
  642.         if(k != 0)
  643.         {
  644.             Tr.error(tc, "SessionContext:createSession - call to establishAffinity for id " + s + " failed with rc " + k);
  645.             return null;
  646.         }
  647.         if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  648.             Tr.debug(tc, "!!!!!SessionContext:createSession: about to increment inServiceMethodCount!!!!!!");
  649.         bumpCreateCount();
  650.         sessiondata.incrementInServiceMethodCount();
  651.         sessiondata.setActive(true, -1L);
  652.         if(sessionListener)
  653.         {
  654.             HttpSessionEvent httpsessionevent = new HttpSessionEvent(sessiondata);
  655.             if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  656.                 Tr.debug(tc, "SessionContext:createSession: calling sessionCreatedEvent()");
  657.             sessionCreatedEvent(httpsessionevent);
  658.         }
  659.         if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  660.             Tr.exit(tc, "SessionContext.createSession");
  661.         return sessiondata;
  662.     }
  663.  
  664.         private final boolean processSessionOnCreation(String s,
  665.                         SessionData sessiondata) {
  666.                 return insertSessionOnCreation(s, sessiondata);
  667.         }
  668.  
  669.         boolean isMaxAllowedReached() {
  670.                 return mSessions.size() == tableSize;
  671.         }
  672.  
  673.         abstract IHttpSession createSessionData(String s);
  674.  
  675.         abstract void performInvalidation();
  676.  
  677.         void pollInvalidations()
  678.     {
  679.         if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  680.             Tr.entry(tc, "SessionContext.pollInvalidations " + getAppName());
  681.         setThreadContext();
  682.         if(debugSessionCrossover)
  683.             currentThreadSessionId.set("WAS-SYSTEM-THREAD");
  684.         performInvalidation();
  685.         unsetThreadContext();
  686.         if(debugSessionCrossover)
  687.             currentThreadSessionId.set(null);
  688.         break MISSING_BLOCK_LABEL_148;
  689.         Throwable throwable;
  690.         throwable;
  691.         FFDCFilter.processException(throwable, "com.ibm.ws.webcontainer.httpsession.SessionContext.pollInvalidations", "818", this);
  692.         Tr.error(tc, "SessionContext.exception", throwable);
  693.         unsetThreadContext();
  694.         if(debugSessionCrossover)
  695.             currentThreadSessionId.set(null);
  696.         break MISSING_BLOCK_LABEL_148;
  697.         Exception exception;
  698.         exception;
  699.         unsetThreadContext();
  700.         if(debugSessionCrossover)
  701.             currentThreadSessionId.set(null);
  702.         throw exception;
  703.         scPmiData.incInvalidatorExecutedCount();
  704.         invalidaterAlarm = SessionAlarmListener.startInvalidationAlarm(this, mInvalidationCheckPollInterval * 1000L);
  705.         if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  706.             Tr.exit(tc, "SessionContext.pollInvalidations " + getAppName());
  707.         return;
  708.     }
  709.  
  710.         void asyncExternalWrite() {
  711.         }
  712.  
  713.         boolean isIBMSessionListenerImplemented() {
  714.                 ArrayList arraylist = getHttpSessionListeners();
  715.                 for (int i = 0; i < arraylist.size(); i++) {
  716.                         HttpSessionListener httpsessionlistener = (HttpSessionListener) (HttpSessionListener) ((ArrayList) arraylist
  717.                                         .get(i)).get(1);
  718.                         if (httpsessionlistener != null
  719.                                         && (httpsessionlistener instanceof IBMSessionListener))
  720.                                 return true;
  721.                 }
  722.  
  723.                 return false;
  724.         }
  725.  
  726.         void notifySessionRemovedFromCache(String s) {
  727.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  728.                         Tr.entry(tc, "SessionContext.notifySessionRemovedFromCache for "
  729.                                         + s);
  730.                 ArrayList arraylist = getHttpSessionListeners();
  731.                 for (int i = 0; i < arraylist.size(); i++) {
  732.                         HttpSessionListener httpsessionlistener = (HttpSessionListener) (HttpSessionListener) ((ArrayList) arraylist
  733.                                         .get(i)).get(1);
  734.                         if (httpsessionlistener == null
  735.                                         || !(httpsessionlistener instanceof IBMSessionListener))
  736.                                 continue;
  737.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  738.                                 Tr.debug(tc, "calling " + httpsessionlistener
  739.                                                 + ".sessionremovedFromCache(" + s + ")");
  740.                         ((IBMSessionListener) httpsessionlistener)
  741.                                         .sessionRemovedFromCache(s);
  742.                 }
  743.  
  744.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  745.                         Tr.exit(tc, "SessionContext.notifySessionRemovedFromCache");
  746.         }
  747.  
  748.         public void notifySessionInvalidated(SessionData sessiondata) {
  749.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  750.                         Tr.entry(tc, "SessionContext.notifySessionInvalidated");
  751.                 removeAffinity(sessiondata);
  752.                 try {
  753.                         sessiondata.sessionUnbound(this);
  754.                         removeSessionFromTable(sessiondata);
  755.                         sessiondata.setValidity(false);
  756.                 } catch (Exception exception) {
  757.                         exception.printStackTrace();
  758.                 }
  759.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  760.                         Tr.exit(tc, "SessionContext.notifySessionInvalidated");
  761.         }
  762.  
  763.         void removeSessionFromTable(SessionData sessiondata) {
  764.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  765.                         Tr.entry(tc, "SessionContext.removeSessionFromTable");
  766.                 tableRemove(sessiondata.getId());
  767.         }
  768.  
  769.         public void notifySessionAccessed(SessionData sessiondata) {
  770.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  771.                         Tr.entry(tc, "SessionContext.notifySessionAccessed");
  772.                 if (sessiondata.isValid())
  773.                         scPmiData.incSessionAccessCount();
  774.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  775.                         Tr.exit(tc, "SessionContext.notifySessionAccessed");
  776.         }
  777.  
  778.         long getSessionInvalidationTime() {
  779.                 return mSessionInvalidationTime;
  780.         }
  781.  
  782.         public void setSessionInvalidationTime(long l) {
  783.                 mSessionInvalidationTime = l;
  784.         }
  785.  
  786.         boolean isSessionTrackingActive() {
  787.                 return mSessionTrackingActive;
  788.         }
  789.  
  790.         public boolean isUsingCookies() {
  791.                 return mUsingCookies;
  792.         }
  793.  
  794.         public void setUsingCookies(boolean flag) {
  795.                 mUsingCookies = flag;
  796.         }
  797.  
  798.         public boolean isUsingURL() {
  799.                 return mUsingURL;
  800.         }
  801.  
  802.         public void setUsingURL(boolean flag) {
  803.                 mUsingURL = flag;
  804.         }
  805.  
  806.         public boolean isURLProtocolSwitchRewritingActive() {
  807.                 return mURLProtocolSwitchRewritingActive;
  808.         }
  809.  
  810.         public void setURLProtocolSwitchRewritingActive(boolean flag) {
  811.                 mURLProtocolSwitchRewritingActive = flag;
  812.         }
  813.  
  814.         String getSessionCookieName() {
  815.                 return mSessionCookieName;
  816.         }
  817.  
  818.         public void setSessionCookieName(String s) {
  819.                 mSessionCookieName = s;
  820.         }
  821.  
  822.         String getSessionCookieComment() {
  823.                 return mSessionCookieComment;
  824.         }
  825.  
  826.         public void setSessionCookieComment(String s) {
  827.                 mSessionCookieComment = s;
  828.         }
  829.  
  830.         String getSessionCookieDomain() {
  831.                 return mSessionCookieDomain;
  832.         }
  833.  
  834.         public void setSessionCookieDomain(String s) {
  835.                 if (s != null && s.length() > 0)
  836.                         mSessionCookieDomain = s;
  837.                 else
  838.                         mSessionCookieDomain = null;
  839.         }
  840.  
  841.         int getSessionCookieMaxAge() {
  842.                 return mSessionCookieMaxAge;
  843.         }
  844.  
  845.         public void setSessionCookieMaxAge(int i) {
  846.                 mSessionCookieMaxAge = i;
  847.         }
  848.  
  849.         String getSessionCookiePath() {
  850.                 return mSessionCookiePath;
  851.         }
  852.  
  853.         public void setSessionCookiePath(String s) {
  854.                 mSessionCookiePath = s;
  855.         }
  856.  
  857.         boolean getSessionCookieSecure() {
  858.                 return mSessionCookieSecure;
  859.         }
  860.  
  861.         public void setSessionCookieSecure(boolean flag) {
  862.                 mSessionCookieSecure = flag;
  863.         }
  864.  
  865.         void updateCloneInfo(SessionData sessiondata, String s, boolean flag) {
  866.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  867.                         Tr.entry(tc, "SessionContext.updateCloneInfo - input cloneInfo="
  868.                                         + s + " newSession=" + flag);
  869.                 String s1 = getCloneIdWithSeparator();
  870.                 if (s != null)
  871.                         synchronized (sessiondata) {
  872.                                 if (!sessiondata.isCloneIdUpdated()) {
  873.                                         sessiondata.setPreviousClones(s);
  874.                                         int i = s.indexOf(s1);
  875.                                         if (i == -1) {
  876.                                                 StringBuffer stringbuffer = new StringBuffer();
  877.                                                 if (!noSwitchOver) {
  878.                                                         stringbuffer.append(s);
  879.                                                         stringbuffer.append(s1);
  880.                                                 } else {
  881.                                                         stringbuffer.append(s1);
  882.                                                         stringbuffer.append(s);
  883.                                                 }
  884.                                                 sessiondata.setPreviousClones(stringbuffer.toString());
  885.                                                 sessiondata.setCloneIdUpdated(true);
  886.                                                 scPmiData.incAffinityBreaks();
  887.                                                 if (cacheIdLength + sessionIDLength
  888.                                                                 + sessiondata.getPreviousClones().length() > maxSessionIdentifierLength) {
  889.                                                         String as[] = {
  890.                                                                         sessiondata.getBrowserToken(sessiondata
  891.                                                                                         .usingSSL()),
  892.                                                                         (new Integer(maxSessionIdentifierLength))
  893.                                                                                         .toString() };
  894.                                                         Tr
  895.                                                                         .warning(
  896.                                                                                         tc,
  897.                                                                                         "SessionContext.maxSessionIdLengthExceeded",
  898.                                                                                         as);
  899.                                                 }
  900.                                         }
  901.                                 }
  902.                         }
  903.                 else if (flag) {
  904.                         sessiondata.setPreviousClones(s1);
  905.                         sessiondata.setCloneIdUpdated(true);
  906.                 }
  907.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  908.                         Tr.exit(tc, "SessionContext.updateCloneInfo");
  909.         }
  910.  
  911.         SessionData findSession(String s) {
  912.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  913.                         Tr.entry(tc, "SessionContext.findSession id=" + s);
  914.                 SessionData sessiondata = null;
  915.                 String s1 = null;
  916.                 Object obj = null;
  917.                 String s2 = null;
  918.                 if (s.length() <= cacheIdLength) {
  919.                         if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  920.                                 Tr
  921.                                                 .exit(tc,
  922.                                                                 "SessionContext.findSession return null because length is too short");
  923.                         return null;
  924.                 }
  925.                 int i = s.indexOf(cloneSeparator);
  926.                 if (i == -1) {
  927.                         s1 = s.substring(cacheIdLength - getCacheIdLengthInUse());
  928.                 } else {
  929.                         s1 = s.substring(cacheIdLength - getCacheIdLengthInUse(), i);
  930.                         s2 = s.substring(i);
  931.                 }
  932.                 sessiondata = (SessionData) tableGet(s1);
  933.                 if (sessiondata != null)
  934.                         if (sessiondata.isValid()
  935.                                         && sessiondata.getMaxInactiveInterval() == 0) {
  936.                                 sessiondata.invalidate();
  937.                                 sessiondata = null;
  938.                         } else {
  939.                                 updateCloneInfo(sessiondata, s2, false);
  940.                         }
  941.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  942.                         Tr.exit(tc, "SessionContext.findSession");
  943.                 return sessiondata;
  944.         }
  945.  
  946.         int getCacheIdLengthInUse() {
  947.                 return 0;
  948.         }
  949.  
  950.         IHttpSession getIHttpSession(String s, HttpServletRequest httpservletrequest) {
  951.                 return getIHttpSession(s, httpservletrequest, false);
  952.         }
  953.  
  954.         IHttpSession getIHttpSession(String s, HttpServletRequest httpservletrequest, boolean flag)
  955.     {
  956.         SessionData sessiondata;
  957.         boolean flag1 = false;
  958.         if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  959.             Tr.entry(tc, "SessionContext.getIHttpSession:  " + s + "  isSSL " + flag);
  960.         if(stopSession)
  961.         {
  962.             String s1 = getXString("SessionContext.accessWhenStop", "SESN0007E: SessionContext: an attempt to access a session while WebSphere Session Manager was turned off was made");
  963.             RuntimeException runtimeexception = new RuntimeException(s1);
  964.             throw runtimeexception;
  965.         }
  966.         sessiondata = null;
  967.         sessiondata = findSession(s);
  968.         if(sessiondata == null)
  969.             break MISSING_BLOCK_LABEL_306;
  970.         SessionData sessiondata1 = sessiondata;
  971.         JVM INSTR monitorenter ;
  972.         if(!sessiondata.isValid())
  973.         {
  974.             if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  975.                 Tr.debug(tc, "SessionContext:getIHttpSession - session invalidated since  initial retrival;  id - " + s + " session - " + sessiondata);
  976.             return null;
  977.         }
  978.         sessiondata.initSession(this);
  979.         if(integrateWASSec)
  980.             checkSecurity(sessiondata, httpservletrequest);
  981.         long l = sessiondata.getLastAccTime();
  982.         sessiondata.accessSessionData();
  983.         sessiondata.setActive(true, sessiondata.getLastAccTime() - l);
  984.         sessiondata.incrementInServiceMethodCount();
  985.         sessiondata.setNew(false);
  986.         if(flag)
  987.             sessiondata.setUsingSSL(true);
  988.         if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  989.         {
  990.             String s3 = "SessionContext: found the session for the id " + s;
  991.             Tr.exit(tc, s3);
  992.         }
  993.         sessiondata.notifyActivateListeners();
  994.         sessiondata1;
  995.         JVM INSTR monitorexit ;
  996.         break MISSING_BLOCK_LABEL_351;
  997.         Exception exception;
  998.         exception;
  999.         throw exception;
  1000.         if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1001.         {
  1002.             String s2 = "SessionContext: no valid session for the id " + s;
  1003.             Tr.debug(tc, s2);
  1004.         }
  1005.         if(sessiondata == null)
  1006.             scPmiData.IncAttemptToActivateNonExistent();
  1007.         if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1008.             Tr.exit(tc, "SessionContext:getIHttpSession - leaving and returning session of  " + sessiondata);
  1009.         return sessiondata;
  1010.     }
  1011.  
  1012.         private String getSessionIDOnly(String s) {
  1013.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1014.                         Tr.entry(tc,
  1015.                                         "SessionContext.getSessionIDOnly - remove the cloneids");
  1016.                 String s1 = s;
  1017.                 int i = s.indexOf(cloneSeparator);
  1018.                 if (i == -1)
  1019.                         s1 = s.substring(cacheIdLength);
  1020.                 else
  1021.                         s1 = s.substring(cacheIdLength, i);
  1022.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1023.                         Tr.exit(tc, "SessionContext.getSessionIDOnly returning " + s1);
  1024.                 return s1;
  1025.         }
  1026.  
  1027.         public HttpSession getSession(String s) {
  1028.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1029.                         Tr.entry(tc, "SessionContext.getSession");
  1030.                 return null;
  1031.         }
  1032.  
  1033.         ArrayList getHttpSessionAttributeListeners() {
  1034.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1035.                         Tr.entry(tc, "SessionContext:getHttpSessionAttributeListeners");
  1036.                 return mHttpSessionAttributeListeners;
  1037.         }
  1038.  
  1039.         ArrayList getHttpSessionListeners() {
  1040.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1041.                         Tr.entry(tc, "SessionContext:getHttpSessionListeners");
  1042.                 return mHttpSessionListeners;
  1043.         }
  1044.  
  1045.         private void setServletContext(ServletContext servletcontext) {
  1046.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1047.                         Tr.entry(tc, "SessionContext:setServletContext");
  1048.                 mServletContext = servletcontext;
  1049.         }
  1050.  
  1051.         public ServletContext getServletContext() {
  1052.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1053.                         Tr.entry(tc, "SessionContext:getServletContext");
  1054.                 return mServletContext != null ? ((IServletContext) mServletContext)
  1055.                                 .getFacade() : null;
  1056.         }
  1057.  
  1058.         synchronized void initializeParameters() {
  1059.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1060.                         Tr.entry(tc, "SessionContext.initializeParameters");
  1061.                 try {
  1062.                         securityEnabled = WSSecurityHelper.isServerSecurityEnabled();
  1063.                         if (!hideSessionValuesPropertySet)
  1064.                                 hideSessionValues = securityEnabled;
  1065.                         setSessionTimeoutInfo();
  1066.                         tableSize = mParams.getInMemorySize();
  1067.                         if (tableSize <= 0)
  1068.                                 throw new RuntimeException(
  1069.                                                 "In memory session size cannot be less than or equal to 0");
  1070.                         allowInfinite = mParams.getEnableOverflow();
  1071.                         setUsingCookies(mParams.getEnableCookies());
  1072.                         setUsingURL(mParams.getEnableUrlRewriting());
  1073.                         setURLProtocolSwitchRewritingActive(mParams
  1074.                                         .getEnableUrlProtocolSwitchRewriting());
  1075.                         setSessionCookieName(mParams.getSessionCookieName());
  1076.                         setSessionCookieComment(mParams.getSessionCookieComment());
  1077.                         String s = mParams.getSessionCookieDomain();
  1078.                         if (s != null && s.length() > 0)
  1079.                                 setSessionCookieDomain(s);
  1080.                         else
  1081.                                 setSessionCookieDomain(null);
  1082.                         setSessionCookieMaxAge(mParams.getSessionCookieMaxAge());
  1083.                         setSessionCookiePath(mParams.getSessionCookiePath());
  1084.                         setSessionCookieSecure(mParams.getSessionCookieSecure());
  1085.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1086.                                 Tr.debug(tc,
  1087.                                                 "SessionContext:initializeParameters - cloneId for this JVM is "
  1088.                                                                 + cloneId);
  1089.                         if (cloneId != null)
  1090.                                 cloneIdLength = cloneId.length();
  1091.                         if (mParams.usingDatabase() && !mParams.getEnableTimeBasedWrite())
  1092.                                 pinSR = false;
  1093.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1094.                                 Tr.debug(tc,
  1095.                                                 "SessionContext:initializeParameters - pinSR set to "
  1096.                                                                 + pinSR);
  1097.                         useSSLId = mParams.useSSLId();
  1098.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1099.                                 Tr.debug(tc,
  1100.                                                 "SessionContext.initializeParameters : UseSSLId = "
  1101.                                                                 + useSSLId);
  1102.                         integrateWASSec = mParams.getIntegrateSecurity();
  1103.                         timedOutAffinityEnabled = mParams.getEnableAffinityTimeout();
  1104.                         if (timedOutAffinityEnabled)
  1105.                                 affinityTimeOut = mParams.getAffinityTimeoutInterval();
  1106.                         allowSerializedSessionAccess = mParams
  1107.                                         .getAllowSerializedSessionAccess();
  1108.                         serializedSessionAccessMaxWaitTime = mParams
  1109.                                         .getSerializedSessionAccessMaxWaitTime();
  1110.                         accessSessionOnTimeout = mParams.getAccessSessionOnTimeout();
  1111.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
  1112.                                 Tr.debug(tc, " ");
  1113.                                 Tr.debug(tc,
  1114.                                                 "SessionContext:initializeParameters - timedOutAffinityEnabled is : "
  1115.                                                                 + timedOutAffinityEnabled);
  1116.                                 Tr.debug(tc,
  1117.                                                 "SessionContext:initializeParameters - affinityTimeOut is : "
  1118.                                                                 + affinityTimeOut);
  1119.                         }
  1120.                         zAffinityCloneId = cloneId;
  1121.                         if (turnOffCloneId
  1122.                                         && (SessionMgrComponentImpl.getServerId().equals("-1") || is_zOS
  1123.                                                         && !SessionMgrComponentImpl.getClusterServerMode())) {
  1124.                                 cloneId = "";
  1125.                                 cloneIdLength = 0;
  1126.                                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1127.                                         Tr
  1128.                                                         .debug(
  1129.                                                                         tc,
  1130.                                                                         "SessionContext:initializeParameters - Remove CloneID because NoAdditionalSessionInfo=true.");
  1131.                         }
  1132.                         cloneSeparator = cloneSep.charAt(0);
  1133.                         if (cloneId != null && cloneId.length() > 0)
  1134.                                 cloneIdWithSep = cloneSep + cloneId;
  1135.                         else
  1136.                                 cloneIdWithSep = "";
  1137.                         cacheIdPlusIdlength = cacheIdLength + sessionIDLength;
  1138.                 } catch (SessionContextParameterException sessioncontextparameterexception) {
  1139.                         FFDCFilter
  1140.                                         .processException(
  1141.                                                         sessioncontextparameterexception,
  1142.                                                         "com.ibm.ws.webcontainer.httpsession.SessionContext.initializeParameters",
  1143.                                                         "1555", this);
  1144.                         Tr.error(tc, "SessionContext.exception",
  1145.                                         sessioncontextparameterexception);
  1146.                 }
  1147.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1148.                         Tr.exit(tc, "SessionContext.initializeParameters");
  1149.         }
  1150.  
  1151.         void setSessionTimeoutInfo() {
  1152.                 setSessionTimeoutInfo(0);
  1153.         }
  1154.  
  1155.         synchronized void setSessionTimeoutInfo(int i) {
  1156.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1157.                         Tr.entry(tc, "SessionContext.setSessionTimeoutInfo");
  1158.                 long l1 = 0L;
  1159.                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1160.                         if (i == 0)
  1161.                                 Tr
  1162.                                                 .debug(tc,
  1163.                                                                 "SessionContext:setSessionTimeoutInfo --  Normal Update");
  1164.                         else
  1165.                                 Tr.debug(tc,
  1166.                                                 "SessionContext:setSessionTimeoutInfo -- Dynamic Global Update.. input parm = "
  1167.                                                                 + i);
  1168.                 try {
  1169.                         long l = scAppParms.getSessionTimeout();
  1170.                         long l3 = l;
  1171.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1172.                                 Tr.debug(tc,
  1173.                                                 "SessionContext:setSessionTimeoutInfo timeout value in WebApp is"
  1174.                                                                 + l3);
  1175.                         if (l == 0L) {
  1176.                                 long l2;
  1177.                                 if (i != 0)
  1178.                                         l2 = i;
  1179.                                 else
  1180.                                         l2 = mParams.getSessionInvalidationTime();
  1181.                                 l3 = l2;
  1182.                                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1183.                                         Tr.debug(tc,
  1184.                                                         "SessionContext:setSessionTimeoutInfo Global timeout is: "
  1185.                                                                         + l3);
  1186.                         }
  1187.                         if (i == 0 || l == 0L) {
  1188.                                 l3 = checkMinimumInvalidation(l3);
  1189.                                 setSessionInvalidationTime(l3);
  1190.                                 int j = randIdGen.nextInt() % 30;
  1191.                                 if (j < 0)
  1192.                                         j *= -1;
  1193.                                 if (mInvalidationCheckPollInterval <= 0L) {
  1194.                                         if (l3 < 120L)
  1195.                                                 mInvalidationCheckPollInterval = 60 - j;
  1196.                                         if (l3 >= 120L && l3 < 900L)
  1197.                                                 mInvalidationCheckPollInterval = 60 + j;
  1198.                                         if (l3 >= 900L)
  1199.                                                 mInvalidationCheckPollInterval = 300 + 2 * j;
  1200.                                 }
  1201.                                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
  1202.                                         Tr.debug(tc,
  1203.                                                         "SessionContext:setSessionTimeoutInfo -- Updating timeout value to: "
  1204.                                                                         + l3);
  1205.                                         Tr
  1206.                                                         .debug(
  1207.                                                                         tc,
  1208.                                                                         "SessionContext:setSessionTimeoutInfo -- mInvalidationCheckPollInterval is now: "
  1209.                                                                                         + mInvalidationCheckPollInterval);
  1210.                                 }
  1211.                         } else if (TraceComponent.isAnyTracingEnabled()
  1212.                                         && tc.isDebugEnabled())
  1213.                                 Tr
  1214.                                                 .debug(tc,
  1215.                                                                 "SessionContext:setSessionTimeoutInfo -- Timeout Value NOT Updated");
  1216.                 } catch (Throwable throwable) {
  1217.                         FFDCFilter
  1218.                                         .processException(
  1219.                                                         throwable,
  1220.                                                         "com.ibm.ws.webcontainer.httpsession.SessionContext.setSessionTimeoutInfo",
  1221.                                                         "1646", this);
  1222.                         Tr.error(tc, "SessionContext.exception", throwable);
  1223.                 }
  1224.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1225.                         Tr.exit(tc, "SessionContext.setSessionTimeoutInfo");
  1226.         }
  1227.  
  1228.         long checkMinimumInvalidation(long l) {
  1229.                 return l;
  1230.         }
  1231.  
  1232.         public boolean shouldEncodeURL(String s,
  1233.                         HttpServletRequest httpservletrequest) {
  1234.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1235.                         Tr.entry(tc, "SessionContext.shouldEncodeURL");
  1236.                 if (!isUsingURL()) {
  1237.                         if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1238.                                 Tr.exit(tc, "SessionContext.encodeOff");
  1239.                         return false;
  1240.                 }
  1241.                 if (!isProtocolSwitch(s, httpservletrequest))
  1242.                         return true;
  1243.                 if (isURLProtocolSwitchRewritingActive()) {
  1244.                         if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1245.                                 Tr.exit(tc, "SessionContext.encodeProtocolSwitchon");
  1246.                         return true;
  1247.                 } else {
  1248.                         return false;
  1249.                 }
  1250.         }
  1251.  
  1252.         public boolean shouldEncodeRedirectURL(String s) {
  1253.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1254.                         Tr.entry(tc, "SessionContext.shouldEncodeRedirectURL");
  1255.                 if (!isUsingURL()) {
  1256.                         if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1257.                                 Tr.exit(tc, "SessionContext.encodeOff");
  1258.                         return false;
  1259.                 } else {
  1260.                         return true;
  1261.                 }
  1262.         }
  1263.  
  1264.         private boolean isProtocolSwitch(String s,
  1265.                         HttpServletRequest httpservletrequest) {
  1266.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1267.                         Tr.entry(tc, "SessionContext.isProtocolSwitch");
  1268.                 int i = s.indexOf("://");
  1269.                 if (i < 0)
  1270.                         return false;
  1271.                 String s1 = s.substring(0, i);
  1272.                 if ((!s1.equalsIgnoreCase("http") || !httpservletrequest.getScheme()
  1273.                                 .equalsIgnoreCase("https"))
  1274.                                 && (!s1.equalsIgnoreCase("https") || !httpservletrequest
  1275.                                                 .getScheme().equalsIgnoreCase("http")))
  1276.                         return false;
  1277.                 int j = i + 3;
  1278.                 int k = j;
  1279.                 int l = s.length();
  1280.                 do {
  1281.                         if (k >= l)
  1282.                                 break;
  1283.                         char c = s.charAt(k);
  1284.                         if (c == ':' || c == '/')
  1285.                                 break;
  1286.                         k++;
  1287.                 } while (true);
  1288.                 String s2 = s.substring(j, k);
  1289.                 InetAddress inetaddress;
  1290.                 try {
  1291.                         inetaddress = InetAddress.getByName(s2);
  1292.                 } catch (UnknownHostException unknownhostexception) {
  1293.                         FFDCFilter
  1294.                                         .processException(
  1295.                                                         unknownhostexception,
  1296.                                                         "com.ibm.ws.webcontainer.httpsession.SessionContext.isProtocolSwitch",
  1297.                                                         "1760", this);
  1298.                         Tr.error(tc, "SessionContext.exception", unknownhostexception);
  1299.                         return false;
  1300.                 }
  1301.                 return inetaddress.equals(getLocalHost());
  1302.         }
  1303.  
  1304.         public void sync(HttpSession httpsession) {
  1305.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1306.                         Tr.entry(tc, "SessionContext.sync");
  1307.         }
  1308.  
  1309.         public void reload(String s) {
  1310.                 stopSessionContext(s);
  1311.         }
  1312.  
  1313.         public String toHTML() {
  1314.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1315.                         Tr.entry(tc, "SessionContext.toHTML");
  1316.                 String s = scAppParms.getJ2EEName();
  1317.                 String s1 = "<b> (for this webapp) : </b> ";
  1318.                 StringBuffer stringbuffer = new StringBuffer();
  1319.                 stringbuffer
  1320.                                 .append(
  1321.                                                 "<center><h3>J2EE NAME(AppName#WebModuleName):: " + s
  1322.                                                                 + " </h3></center>" + "<UL>\n")
  1323.                                 .append("<b>  cloneId</b> : ")
  1324.                                 .append(cloneId)
  1325.                                 .append("<BR>")
  1326.                                 .append("<BR>")
  1327.                                 .append("<b>  Number of sessions in memory: </b>")
  1328.                                 .append(s1)
  1329.                                 .append(mSessions == null ? 0 : mSessions.size())
  1330.                                 .append("<BR>")
  1331.                                 .append("<b>  use overflow</b> : ")
  1332.                                 .append(allowInfinite)
  1333.                                 .append("<BR>")
  1334.                                 .append("<b>  overflow size</b> ")
  1335.                                 .append(s1)
  1336.                                 .append("<BR>")
  1337.                                 .append(
  1338.                                                 "<b>  Invalidation alarm poll interval (for this webapp) </b> : ")
  1339.                                 .append(mInvalidationCheckPollInterval)
  1340.                                 .append("<BR>")
  1341.                                 .append(
  1342.                                                 "<b> Max invalidation timeout (for this webapp) </b> : ")
  1343.                                 .append(mSessionInvalidationTime).append("<BR>").append(
  1344.                                                 "<b> Using Cookies </b> : ").append(mUsingCookies)
  1345.                                 .append("<BR>").append("<b> Using URL Rewriting </b> : ")
  1346.                                 .append(mUsingURL).append("<BR>").append(
  1347.                                                 "<b> use SSLId </b> : ").append(useSSLId)
  1348.                                 .append("<BR>").append(
  1349.                                                 "<b> URL Protocol Switch Rewriting </b> : ").append(
  1350.                                                 mURLProtocolSwitchRewritingActive).append("<BR>")
  1351.                                 .append("<b> Session Cookie Name </b> : ").append(
  1352.                                                 mSessionCookieName).append("<BR>").append(
  1353.                                                 "<b> Session Cookie Comment </b> : ").append(
  1354.                                                 mSessionCookieComment).append("<BR>").append(
  1355.                                                 "<b> Session Cookie Domain </b> : ").append(
  1356.                                                 mSessionCookieDomain).append("<BR>").append(
  1357.                                                 "<b> Session Cookie Path </b> : ").append(
  1358.                                                 mSessionCookiePath).append("<BR>").append(
  1359.                                                 "<b> Session Cookie MaxAge </b> : ").append(
  1360.                                                 mSessionCookieMaxAge).append("<BR>").append(
  1361.                                                 "<b> Session Cookie Secure </b> : ").append(
  1362.                                                 mSessionCookieSecure).append("<BR>").append(
  1363.                                                 "<b> Maximum in memory table size </b> : ").append(
  1364.                                                 tableSize).append("<BR>").append(
  1365.                                                 "<b> current time </b> : ").append(
  1366.                                                 (new Date(System.currentTimeMillis())).toString())
  1367.                                 .append("<BR>").append("<b>  integrateWASSec</b> :").append(
  1368.                                                 integrateWASSec)
  1369.                                 .append("<BR><b>Session locking </b>: ").append(
  1370.                                                 allowSerializedSessionAccess).append(
  1371.                                                 "<BR><b>Session locking timeout</b>: ").append(
  1372.                                                 serializedSessionAccessMaxWaitTime).append(
  1373.                                                 "<BR><b>Allow access on lock timeout</b>:").append(
  1374.                                                 accessSessionOnTimeout).append(scPmiData.toHTML())
  1375.                                 .append(mbeanAdapter.toHTML());
  1376.                 return stringbuffer.toString();
  1377.         }
  1378.  
  1379.         public String toHTML2() {
  1380.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1381.                         Tr.entry(tc, "SessionContext.toHTML");
  1382.                 StringBuffer stringbuffer = new StringBuffer();
  1383.                 stringbuffer.append(
  1384.                                 "<center><h3>Session Tracking Internals</h3></center><UL>\n")
  1385.                                 .append("<b>  mSessions </b> : ").append(
  1386.                                                 mSessions == null ? null : mSessions.toString())
  1387.                                 .append("<BR>");
  1388.                 return stringbuffer.toString();
  1389.         }
  1390.  
  1391.         public String toString() {
  1392.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1393.                         Tr.entry(tc, "SessionContext.toString");
  1394.                 StringBuffer stringbuffer = new StringBuffer();
  1395.                 stringbuffer.append(
  1396.                                 "\nSession Tracking Internals for webapp "
  1397.                                                 + scAppParms.getJ2EEName() + ": \n").append("\n")
  1398.                                 .append("  mSessions size : ").append(
  1399.                                                 mSessions == null ? 0 : mSessions.size()).append("\n")
  1400.                                 .append("  use overflow : ").append(allowInfinite).append("\n")
  1401.                                 .append("  overflow size : ").append("\n").append(
  1402.                                                 "mInvalidationCheckPollInterval : ").append(
  1403.                                                 mInvalidationCheckPollInterval).append("\n").append(
  1404.                                                 "mSessionInvalidationTime  : ").append(
  1405.                                                 getSessionInvalidationTime()).append("\n").append(
  1406.                                                 "mSessionTrackingActive  : ").append(
  1407.                                                 isSessionTrackingActive()).append("\n").append(
  1408.                                                 "mUsingCookies  : ").append(isUsingCookies()).append(
  1409.                                                 "\n").append("mUsingURL  : ").append(isUsingURL())
  1410.                                 .append("\n").append("useSSLId  : ").append(useSSLId).append(
  1411.                                                 "\n").append("mURLProtocolSwitchRewritingActive  : ")
  1412.                                 .append(isURLProtocolSwitchRewritingActive()).append("\n")
  1413.                                 .append("mSessionCookieName  : ")
  1414.                                 .append(getSessionCookieName()).append("\n").append(
  1415.                                                 "mSessionCookieComment  : ").append(
  1416.                                                 getSessionCookieComment()).append("\n").append(
  1417.                                                 "mSessionCookieDomain  : ").append(
  1418.                                                 getSessionCookieDomain()).append("\n").append(
  1419.                                                 "mSessionCookiePath  : ")
  1420.                                 .append(getSessionCookiePath()).append("\n").append(
  1421.                                                 "mSessionCookieSecure  : ").append(
  1422.                                                 getSessionCookieSecure()).append("\n").append(
  1423.                                                 "mSessionCookieMaxAge  : ").append(
  1424.                                                 getSessionCookieMaxAge()).append("\n").append(
  1425.                                                 "in memory table size : ").append(tableSize).append(
  1426.                                                 "\n").append("current time : ").append(
  1427.                                                 (new Date(System.currentTimeMillis())).toString())
  1428.                                 .append("\n").append("integrateWASSec :").append(
  1429.                                                 integrateWASSec).append("\n").append(
  1430.                                                 "\nSession serialization: ").append(
  1431.                                                 allowSerializedSessionAccess).append(
  1432.                                                 "\nSession serialization timeout: ").append(
  1433.                                                 serializedSessionAccessMaxWaitTime).append(
  1434.                                                 "Allow access on serialization timeout:").append(
  1435.                                                 accessSessionOnTimeout);
  1436.                 return stringbuffer.toString();
  1437.         }
  1438.  
  1439.         String toString2() {
  1440.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1441.                         Tr.entry(tc, "SessionContext.toString2");
  1442.                 StringBuffer stringbuffer = new StringBuffer(toString());
  1443.                 stringbuffer.append("mSessions : ").append(
  1444.                                 mSessions == null ? null : mSessions.toString()).append("\n");
  1445.                 return stringbuffer.toString();
  1446.         }
  1447.  
  1448.         void tablePut(Object obj, Object obj1) {
  1449.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1450.                         Tr.entry(tc, "SessionContext.tablePut");
  1451.                 try {
  1452.                         mSessions.put(obj, obj1);
  1453.                         incMemoryCount();
  1454.                 } catch (TooManySessionsException toomanysessionsexception) {
  1455.                         FFDCFilter
  1456.                                         .processException(
  1457.                                                         toomanysessionsexception,
  1458.                                                         "com.ibm.ws.webcontainer.httpsession.SessionContext.tablePut",
  1459.                                                         "2008", this);
  1460.                         Tr.error(tc, "SessionContext.exception", toomanysessionsexception);
  1461.                 }
  1462.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1463.                         Tr.exit(tc, "SessionContext.tablePut");
  1464.         }
  1465.  
  1466.         void incMemoryCount() {
  1467.                 scPmiData.incMemoryCount();
  1468.         }
  1469.  
  1470.         void decMemoryCount() {
  1471.                 scPmiData.decMemoryCount();
  1472.         }
  1473.  
  1474.         Object tableGet(Object obj) {
  1475.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1476.                         Tr.entry(tc, "SessionContext.tableGet");
  1477.                 return mSessions.get(obj);
  1478.         }
  1479.  
  1480.         void tableRemove(Object obj) {
  1481.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1482.                         Tr.entry(tc, "SessionContext.tableRemove " + obj);
  1483.                 Object obj1 = mSessions.remove(obj);
  1484.                 if (obj1 != null) {
  1485.                         decMemoryCount();
  1486.                         if (mIBMSessionListenerImplemented)
  1487.                                 notifySessionRemovedFromCache((String) obj);
  1488.                 }
  1489.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1490.                         Tr.exit(tc, "SessionContext.tableRemove");
  1491.         }
  1492.  
  1493.         void tableClear() {
  1494.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1495.                         Tr.entry(tc, "SessionContext.tableClear");
  1496.                 HashSet hashset = new HashSet(mSessions.keySet());
  1497.                 mSessions.clear();
  1498.                 if (mIBMSessionListenerImplemented) {
  1499.                         for (Iterator iterator = hashset.iterator(); iterator.hasNext(); notifySessionRemovedFromCache((String) iterator
  1500.                                         .next()))
  1501.                                 ;
  1502.                 }
  1503.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1504.                         Tr.exit(tc, "SessionContext.tableClear");
  1505.         }
  1506.  
  1507.         HashMap getHashMap() {
  1508.                 return mSessions;
  1509.         }
  1510.  
  1511.         boolean isSessionIdInUse(String s) {
  1512.                 if (tc.isEntryEnabled())
  1513.                         Tr.entry(tc, "SessionContext.IsSessionIdInUse: entered with " + s);
  1514.                 boolean flag = false;
  1515.                 Enumeration enumeration = SessionContextRegistry
  1516.                                 .getScrSessionContexts();
  1517.                 do {
  1518.                         if (!enumeration.hasMoreElements() || flag)
  1519.                                 break;
  1520.                         SessionContext sessioncontext = (SessionContext) enumeration
  1521.                                         .nextElement();
  1522.                         if (sessioncontext != this) {
  1523.                                 Object obj = sessioncontext.getFromMemory(s);
  1524.                                 if (obj != null)
  1525.                                         flag = true;
  1526.                         }
  1527.                 } while (true);
  1528.                 if (flag) {
  1529.                         if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1530.                                 Tr.exit(tc,
  1531.                                                 "SessionContext.IsSessionIdInUse Found in Cache/Mem");
  1532.                         return flag;
  1533.                 }
  1534.                 flag = isPresentInExternalStore(s);
  1535.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1536.                         Tr.exit(tc,
  1537.                                         "SessionContext:isSessionIdInUse: after persistent store scan returning: "
  1538.                                                         + flag);
  1539.                 return flag;
  1540.         }
  1541.  
  1542.         Object getFromMemory(Object obj) {
  1543.                 return mSessions.get(obj);
  1544.         }
  1545.  
  1546.         boolean isPresentInExternalStore(Object obj) {
  1547.                 return false;
  1548.         }
  1549.  
  1550.         Enumeration tableKeys() {
  1551.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1552.                         Tr.entry(tc, "SessionContext.tableKeys");
  1553.                 Set set = mSessions == null ? (new HashMap(1)).keySet() : mSessions
  1554.                                 .keySet();
  1555.                 final Iterator iter = set.iterator();
  1556.                 return new Enumeration() {
  1557.  
  1558.                         public boolean hasMoreElements() {
  1559.                                 return iter.hasNext();
  1560.                         }
  1561.  
  1562.                         public Object nextElement() {
  1563.                                 return iter.next();
  1564.                         }
  1565.  
  1566.                         {
  1567.                                 super();
  1568.                         }
  1569.                 };
  1570.         }
  1571.  
  1572.         int getCloneIdLength() {
  1573.                 return cloneIdLength;
  1574.         }
  1575.  
  1576.         String getCloneId() {
  1577.                 return cloneId;
  1578.         }
  1579.  
  1580.         String getIDFromBytes(byte abyte0[]) {
  1581.                 return convertSessionIdBytesToSessionId(abyte0);
  1582.         }
  1583.  
  1584.         public boolean isSSLSessions() {
  1585.                 return useSSLId;
  1586.         }
  1587.  
  1588.         boolean getAllowSerializedSessionAccess() {
  1589.                 return allowSerializedSessionAccess;
  1590.         }
  1591.  
  1592.         int getSerializedSessionAccessMaxWaitTime() {
  1593.                 return serializedSessionAccessMaxWaitTime;
  1594.         }
  1595.  
  1596.         boolean getAccessSessionOnTimeout() {
  1597.                 return accessSessionOnTimeout;
  1598.         }
  1599.  
  1600.         void invalidateAllMemorySessions() {
  1601.         }
  1602.  
  1603.         public synchronized void stop(String s) {
  1604.                 stopSessionContext(s);
  1605.         }
  1606.  
  1607.         public String getCloneSeparator() {
  1608.                 return cloneSep;
  1609.         }
  1610.  
  1611.         String getCloneIdWithSeparator() {
  1612.                 return cloneIdWithSep;
  1613.         }
  1614.  
  1615.         String getAppName() {
  1616.                 try {
  1617.                         return scAppParms.getAppName();
  1618.                 } catch (Throwable throwable) {
  1619.                         FFDCFilter
  1620.                                         .processException(
  1621.                                                         throwable,
  1622.                                                         "com.ibm.ws.webcontainer.httpsession.SessionContext.getAppName",
  1623.                                                         "2256", this);
  1624.                         Tr.error(tc, "SessionContext.exception", throwable);
  1625.                         return null;
  1626.                 }
  1627.         }
  1628.  
  1629.         public HttpSession getIHttpSession(HttpServletRequest httpservletrequest,
  1630.                         HttpServletResponse httpservletresponse, boolean flag) {
  1631.                 return getIHttpSession(httpservletrequest, httpservletresponse, flag,
  1632.                                 false);
  1633.         }
  1634.  
  1635.         private HttpSession getIHttpSession(HttpServletRequest httpservletrequest,
  1636.                         HttpServletResponse httpservletresponse, boolean flag, boolean flag1) {
  1637.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1638.                         Tr.entry(tc,
  1639.                                         "SessionContext.getIHttpSession(req,res,create,cacheOnly): create = "
  1640.                                                         + flag + " cacheOnly= " + flag1);
  1641.                 boolean flag2 = false;
  1642.                 boolean flag3 = false;
  1643.                 IHttpSession ihttpsession = null;
  1644.                 String s = null;
  1645.                 String s1 = ((IExtendedRequest) httpservletrequest)
  1646.                                 .getUpdatedSessionId();
  1647.                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1648.                         Tr.debug(tc,
  1649.                                         "SessionContext.getIHttpSession: id from request object is "
  1650.                                                         + s1);
  1651.                 if (s1 != null)
  1652.                         s = s1;
  1653.                 if (s == null) {
  1654.                         s = getFullSessionId(httpservletrequest);
  1655.                         if (!useSSLId && s != null) {
  1656.                                 flag3 = true;
  1657.                                 if (s.length() < cacheIdPlusIdlength) {
  1658.                                         Tr.warning(tc, "SessionContext.getIHttpSession: id " + s
  1659.                                                         + " failed length check against "
  1660.                                                         + cacheIdPlusIdlength);
  1661.                                         s = null;
  1662.                                 }
  1663.                         }
  1664.                 }
  1665.                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1666.                         Tr.debug(tc, "SessionContext.getIHttpSession : UseSSLId = "
  1667.                                         + useSSLId);
  1668.                 if (useSSLId
  1669.                                 && ((IExtendedRequest) httpservletrequest).getSSLId() != null)
  1670.                         flag2 = true;
  1671.                 if (s != null && (!flag1 || getFromMemory(getSessionIDOnly(s)) != null))
  1672.                         ihttpsession = getIHttpSession(s, httpservletrequest, flag2);
  1673.                 if (ihttpsession == null && flag3) {
  1674.                         List list = getAllRequestedSessionIdsFromCookies(httpservletrequest);
  1675.                         if (list != null && list.size() > 1) {
  1676.                                 ihttpsession = checkAllCookies(list, 1, httpservletrequest,
  1677.                                                 flag2);
  1678.                                 if (ihttpsession != null)
  1679.                                         s = ((SessionData) ihttpsession).getCacheId()
  1680.                                                         + ihttpsession.getId();
  1681.                         }
  1682.                 }
  1683.                 if (ihttpsession != null) {
  1684.                         String s2 = getSessionIDOnly(s);
  1685.                         if (!s2.equals(ihttpsession.getId())) {
  1686.                                 Object aobj[] = { getAppName(), ihttpsession.getId(), s2,
  1687.                                                 new SessionCrossoverStackTrace() };
  1688.                                 Tr.error(tc, "SessionContext.CrossoverOnRetrieve",
  1689.                                                 ((Object) (aobj)));
  1690.                                 ihttpsession = null;
  1691.                         } else if (crossoverCheck(ihttpsession.getId())) {
  1692.                                 Object aobj1[] = { getAppName(), ihttpsession.getId(),
  1693.                                                 (String) currentThreadSessionId.get(),
  1694.                                                 new SessionCrossoverStackTrace() };
  1695.                                 Tr.error(tc, "SessionContext.CrossoverOnRetrieve",
  1696.                                                 ((Object) (aobj1)));
  1697.                                 ihttpsession = null;
  1698.                         }
  1699.                 }
  1700.                 if (ihttpsession == null && flag)
  1701.                         if (s != null) {
  1702.                                 if (flag2) {
  1703.                                         ihttpsession = createSession(httpservletrequest, s, true);
  1704.                                         if (TraceComponent.isAnyTracingEnabled()
  1705.                                                         && tc.isDebugEnabled())
  1706.                                                 Tr.debug(tc,
  1707.                                                                 "SessionContext.getIHttpSession : sslReq path so create session with Id = "
  1708.                                                                                 + s);
  1709.                                 } else {
  1710.                                         String s3 = null;
  1711.                                         if (!idReuse && s.length() >= cacheIdPlusIdlength)
  1712.                                                 s3 = s.substring(cacheIdLength, cacheIdPlusIdlength);
  1713.                                         if (idReuse || s1 != null || isSessionIdInUse(s3))
  1714.                                                 ihttpsession = createSession(httpservletrequest, s,
  1715.                                                                 false);
  1716.                                         else
  1717.                                                 ihttpsession = createSession(httpservletrequest, null,
  1718.                                                                 false);
  1719.                                 }
  1720.                         } else {
  1721.                                 ihttpsession = createSession(httpservletrequest, null, false);
  1722.                         }
  1723.                 if (ihttpsession != null) {
  1724.                         if (((SessionData) ihttpsession).internalIsNew())
  1725.                                 updateCurrentThreadSessionId((SessionData) ihttpsession);
  1726.                         ((SessionData) ihttpsession).setPathInfo(httpservletrequest
  1727.                                         .getPathInfo());
  1728.                         Object obj = null;
  1729.                         boolean flag4 = ihttpsession.usingSSL();
  1730.                         if (mUsingCookies && ihttpsession.isBrowserTokenUpdated()) {
  1731.                                 String s4 = ihttpsession.testAndGetBrowserToken(flag4);
  1732.                                 setCookie(httpservletrequest, httpservletresponse, s4, flag4);
  1733.                         }
  1734.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1735.                                 Tr.debug(tc, "calling req.setSessionid  "
  1736.                                                 + ihttpsession.getBrowserToken(flag4));
  1737.                         ((IExtendedRequest) httpservletrequest).setSessionId(ihttpsession
  1738.                                         .getBrowserToken(flag4));
  1739.                 } else if (idReuse && s != null && s1 == null)
  1740.                         ((IExtendedRequest) httpservletrequest).setSessionId(s);
  1741.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1742.                         Tr.exit(tc,
  1743.                                         "SessionContext.getIHttpSession(req,res,create,cacheOnly)");
  1744.                 return ihttpsession;
  1745.         }
  1746.  
  1747.         private IHttpSession checkAllCookies(List list, int i,
  1748.                         HttpServletRequest httpservletrequest, boolean flag) {
  1749.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1750.                         Tr.entry(tc,
  1751.                                         "SessionContext.checkAllCookies got this many cookies: "
  1752.                                                         + list.size());
  1753.                 IHttpSession ihttpsession = null;
  1754.                 for (int j = i; j < list.size(); j++) {
  1755.                         String s1 = (String) list.get(j);
  1756.                         if (s1 == null || s1.length() < cacheIdPlusIdlength)
  1757.                                 continue;
  1758.                         ihttpsession = getIHttpSession(s1, httpservletrequest, flag);
  1759.                         if (ihttpsession == null)
  1760.                                 continue;
  1761.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1762.                                 Tr.debug(tc,
  1763.                                                 "SessionContext.checkAllCookies found session using cookie index "
  1764.                                                                 + j + " with id " + s1);
  1765.                         break;
  1766.                 }
  1767.  
  1768.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
  1769.                         String s = ihttpsession != null ? "non-null" : "null";
  1770.                         Tr.exit(tc, "SessionContext.checkAllCookies returning " + s);
  1771.                 }
  1772.                 return ihttpsession;
  1773.         }
  1774.  
  1775.         private String getFullSessionId(HttpServletRequest httpservletrequest) {
  1776.                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1777.                         Tr.debug(tc, "SessionContext.getFullSessionId");
  1778.                 Object obj = null;
  1779.                 if (useSSLId) {
  1780.                         String s = getRequestedSessionIdFromSSL(httpservletrequest);
  1781.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1782.                                 Tr.debug(tc, "SessionContext.getFullSessionId: SSL Id = " + s);
  1783.                         if (s != null)
  1784.                                 return s;
  1785.                 }
  1786.                 if (mUsingCookies) {
  1787.                         String s1 = getRequestedSessionIdFromCookie(httpservletrequest);
  1788.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1789.                                 Tr.debug(tc, "SessionContext.getFullSessionId: Cookie Id = "
  1790.                                                 + s1);
  1791.                         if (s1 != null)
  1792.                                 return s1;
  1793.                 }
  1794.                 if (mUsingURL) {
  1795.                         String s2 = getRequestedSessionIdFromURL(httpservletrequest);
  1796.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1797.                                 Tr.debug(tc, "SessionContext.getFullSessionId: URL Id = " + s2);
  1798.                         if (s2 != null)
  1799.                                 return s2;
  1800.                 }
  1801.                 return null;
  1802.         }
  1803.  
  1804.         public String getRequestedSessionId(HttpServletRequest httpservletrequest) {
  1805.                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1806.                         Tr.debug(tc, "SessionContext.getRequestedSessionId");
  1807.                 Object obj = null;
  1808.                 if (useSSLId) {
  1809.                         String s = getRequestedSessionIdFromSSL(httpservletrequest);
  1810.                         if (s != null)
  1811.                                 return getSessionIDOnly(s);
  1812.                 }
  1813.                 if (mUsingCookies) {
  1814.                         List list = getAllRequestedSessionIdsFromCookies(httpservletrequest);
  1815.                         if (list != null) {
  1816.                                 if (list.size() > 1) {
  1817.                                         IHttpSession ihttpsession = checkAllCookies(list, 0,
  1818.                                                         httpservletrequest, false);
  1819.                                         if (ihttpsession != null)
  1820.                                                 return ihttpsession.getId();
  1821.                                 }
  1822.                                 if (list.size() > 0) {
  1823.                                         String s1 = (String) list.get(0);
  1824.                                         if (s1 != null)
  1825.                                                 return getSessionIDOnly(s1);
  1826.                                 }
  1827.                         }
  1828.                 }
  1829.                 if (mUsingURL) {
  1830.                         String s2 = getRequestedSessionIdFromURL(httpservletrequest);
  1831.                         if (s2 != null)
  1832.                                 return getSessionIDOnly(s2);
  1833.                 }
  1834.                 return null;
  1835.         }
  1836.  
  1837.         public boolean isRequestedSessionIdFromCookie(
  1838.                         HttpServletRequest httpservletrequest) {
  1839.                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1840.                         Tr.debug(tc, "SessionContext.isRequestedSessionIdFromCookie");
  1841.                 Object obj = null;
  1842.                 if (useSSLId) {
  1843.                         String s = getRequestedSessionIdFromSSL(httpservletrequest);
  1844.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1845.                                 Tr.debug(tc,
  1846.                                                 "SessionContext.isRequestedSessionIdFromCookie: SSL Id = "
  1847.                                                                 + s);
  1848.                         if (s != null)
  1849.                                 return false;
  1850.                 }
  1851.                 if (mUsingCookies) {
  1852.                         String s1 = getRequestedSessionIdFromCookie(httpservletrequest);
  1853.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1854.                                 Tr.debug(tc,
  1855.                                                 "SessionContext.isRequestedSessionIdFromCookie: Cookie Id = "
  1856.                                                                 + s1);
  1857.                         if (s1 != null)
  1858.                                 return true;
  1859.                 }
  1860.                 return false;
  1861.         }
  1862.  
  1863.         public boolean isRequestedSessionIdFromUrl(
  1864.                         HttpServletRequest httpservletrequest) {
  1865.                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1866.                         Tr.debug(tc, "SessionContext.isRequestedSessionIdFromUrl");
  1867.                 Object obj = null;
  1868.                 if (useSSLId) {
  1869.                         String s = getRequestedSessionIdFromSSL(httpservletrequest);
  1870.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1871.                                 Tr.debug(tc,
  1872.                                                 "SessionContext.isRequestedSessionIdFromURL: SSL Id = "
  1873.                                                                 + s);
  1874.                         if (s != null)
  1875.                                 return false;
  1876.                 }
  1877.                 if (mUsingCookies) {
  1878.                         String s1 = getRequestedSessionIdFromCookie(httpservletrequest);
  1879.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1880.                                 Tr.debug(tc,
  1881.                                                 "SessionContext.isRequestedSessionIdFromURL: Cookie Id = "
  1882.                                                                 + s1);
  1883.                         if (s1 != null)
  1884.                                 return false;
  1885.                 }
  1886.                 if (mUsingURL) {
  1887.                         String s2 = getRequestedSessionIdFromURL(httpservletrequest);
  1888.                         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1889.                                 Tr.debug(tc,
  1890.                                                 "SessionContext.isRequestedSessionIdFromURL: URL Id = "
  1891.                                                                 + s2);
  1892.                         if (s2 != null)
  1893.                                 return true;
  1894.                 }
  1895.                 return false;
  1896.         }
  1897.  
  1898.         public boolean isRequestedSessionIdValid(
  1899.                         HttpServletRequest httpservletrequest, HttpSession httpsession) {
  1900.                 if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
  1901.                         Tr.debug(tc, "SessionContext.isRequestedSessionIdValid");
  1902.                 String s = getFullSessionId(httpservletrequest);
  1903.                 if (s == null)
  1904.                         return false;
  1905.                 if (httpsession == null)
  1906.                         return false;
  1907.                 if (httpsession.isNew())
  1908.                         return false;
  1909.                 s = getSessionIDOnly(s);
  1910.                 if (s.equals(httpsession.getId()))
  1911.                         return true;
  1912.                 List list = getAllRequestedSessionIdsFromCookies(httpservletrequest);
  1913.                 if (list != null && list.size() > 1) {
  1914.                         for (int i = 1; i < list.size(); i++) {
  1915.                                 String s2 = (String) list.get(i);
  1916.                                 if (s2 == null || s2.length() <= cacheIdLength)
  1917.                                         continue;
  1918.                                 String s1 = getSessionIDOnly(s2);
  1919.                                 if (s1.equals(httpsession.getId()))
  1920.                                         return true;
  1921.                         }
  1922.  
  1923.                 }
  1924.                 return false;
  1925.         }
  1926.  
  1927.         public HttpSession sessionPreInvoke(HttpServletRequest httpservletrequest,
  1928.                         HttpServletResponse httpservletresponse) {
  1929.                 if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
  1930.                         Tr.entry(tc, "SessionContext.sessionPreInvoke");
  1931.                 if (debugSessionCrossover) {
  1932.                         String s = ((IExtendedRequest) httpservletrequest)
  1933.                                         .getUpdatedSessionId();
  1934.                         if (s == null)
  1935.                                 s = getFullSessionId(httpservletrequest);
  1936.                         if (s != null) {
  1937.                                 String s1 = getSessionIDOnly(s);
  1938.                                 currentThreadSessionId.set(s1);
  1939.                         } else {