- /*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
- package com.ibm.ws.webcontainer.httpsession;
- import com.ibm.ejs.ras.Tr;
- import com.ibm.ejs.ras.TraceComponent;
- import com.ibm.ejs.sm.client.ui.NLS;
- import com.ibm.ejs.util.am.Alarm;
- import com.ibm.websphere.security.WSSecurityHelper;
- import com.ibm.websphere.servlet.session.IBMSessionListener;
- import com.ibm.websphere.servlet.session.UnauthorizedSessionRequestException;
- import com.ibm.ws.ffdc.FFDCFilter;
- import com.ibm.ws.management.AdminHelper;
- import com.ibm.ws.security.core.SecurityContext;
- import com.ibm.ws.security.util.AccessController;
- import com.ibm.ws.util.WSThreadLocal;
- import com.ibm.ws.webcontainer.session.IHttpSessionContext;
- import com.ibm.ws.webcontainer.srt.IExtendedRequest;
- import com.ibm.ws.webcontainer.srt.IExtendedResponse;
- import com.ibm.ws.webcontainer.util.EncodeCloneID;
- import com.ibm.ws390.rt.HTTPSessionAffinity;
- import com.ibm.wsspi.hamanager.HAGroup;
- import com.ibm.wsspi.hamanager.datastack.MsgQoS;
- import com.ibm.wsspi.webcontainer.servlet.IServletContext;
- import java.io.UnsupportedEncodingException;
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- import java.security.PrivilegedActionException;
- import java.security.PrivilegedExceptionAction;
- import java.util.*;
- import javax.servlet.ServletContext;
- import javax.servlet.http.*;
- // Referenced classes of package com.ibm.ws.webcontainer.httpsession:
- // BaseSessionContext, SessionContextMBeanAdapter, SessionTrackingPMIApplicationData, SessionData,
- // SessionIDGen, SessionSimpleHashMap, IHttpSession, SessionContextParameterException,
- // TooManySessionsException, SessionCrossoverStackTrace, SessionApplicationParameters, SessionMgrComponentImpl,
- // SessionAlarmListener, SessionContextRegistry, IDFactory, SessionContextParameters,
- // HttpSessionSystemProperties
- public abstract class SessionContext extends BaseSessionContext implements
- IHttpSessionContext {
- SessionContext(SessionContextParameters sessioncontextparameters,
- SessionApplicationParameters sessionapplicationparameters) {
- tableSize = 1000;
- allowInfinite = true;
- overflowData = null;
- mInvalidationCheckPollInterval = -1L;
- mSessionInvalidationTime = 1800L;
- mSessionTrackingActive = true;
- mUsingCookies = true;
- mUsingURL = false;
- mURLProtocolSwitchRewritingActive = false;
- mSessionCookieName = "JSESSION";
- mSessionCookieComment = "Session id";
- mSessionCookieMaxAge = -1;
- mSessionCookiePath = "/";
- mSessionCookieSecure = false;
- counterSyncher = new Object();
- mSessions = null;
- mSessionIdCounter = 0;
- mParams = null;
- scAppParms = null;
- scPmiData = null;
- scEnablePmi = true;
- stopSession = false;
- integrateWASSec = false;
- useSSLId = false;
- sessionAttributeListener = false;
- sessionListener = false;
- mHttpSessionAttributeListeners = new ArrayList();
- mHttpSessionListeners = new ArrayList();
- mServletContext = null;
- timedOutAffinityEnabled = true;
- affinityTimeOut = 30L;
- allowSerializedSessionAccess = false;
- serializedSessionAccessMaxWaitTime = 0;
- accessSessionOnTimeout = false;
- mbeanAdapter = null;
- cacheIdLength = 4;
- cacheIdPlusIdlength = cacheIdLength + sessionIDLength;
- createSync = new HashMap();
- mIBMSessionListenerImplemented = false;
- crossoverUserThreadWarningIssued = false;
- onlyCheckInCacheDuringPreInvoke = false;
- cloneIdWithSep = null;
- _refCount = 1;
- maxSessionIdentifierLength = 1024;
- mParams = sessioncontextparameters;
- scAppParms = sessionapplicationparameters;
- if (mParams == null && scAppParms == null)
- return;
- if (randIdGen == null)
- randIdGen = new Random(System.currentTimeMillis());
- self = this;
- mbeanAdapter = new SessionContextMBeanAdapter(this);
- scPmiData = new SessionTrackingPMIApplicationData(
- sessionapplicationparameters, mbeanAdapter);
- try {
- setServletContext(scAppParms.getServletContext());
- } catch (Exception exception) {
- FFDCFilter
- .processException(
- exception,
- "com.ibm.ws.webcontainer.httpsession.SessionContext.moreInit",
- "294", this);
- Tr.error(tc, "SessionContext.exception", exception);
- }
- }
- void init()
- {
- is_zOS = SessionMgrComponentImpl.is_zOS();
- setProperties(SessionMgrComponentImpl.getWebContainerProperties());
- setThreadContext();
- initializeParameters();
- moreInit();
- unsetThreadContext();
- break MISSING_BLOCK_LABEL_39;
- Exception exception;
- exception;
- unsetThreadContext();
- throw exception;
- }
- void moreInit() {
- mSessions = createSessionTable();
- if (!allowInfinite && overflowData == null) {
- overflowData = (SessionData) createSessionData("overflowed-session");
- overflowData.setValidity(false);
- overflowData.overflowed = true;
- overflowData.setSessionContext(this);
- }
- if (sessionIdsUsedMoreThanOnce == null)
- sessionIdsUsedMoreThanOnce = new Hashtable();
- if (useJCE && sessionIDFactory == null)
- try {
- if (useBase32)
- sessionIDFactory = new SessionIDGen(sessionIDLength, BASE32);
- else
- sessionIDFactory = new SessionIDGen(sessionIDLength, BASE64);
- } catch (Throwable throwable) {
- FFDCFilter
- .processException(
- throwable,
- "com.ibm.ws.webcontainer.httpsession.SessionContext.moreInit",
- "264", this);
- Tr.error(tc, "SessionContext.loadJCEFail");
- Tr.error(tc, "SessionContext.exception", throwable);
- sessionIDFactory = null;
- }
- startSessionContext();
- if (debugSessionCrossover)
- currentThreadSessionId = new WSThreadLocal();
- completedStartup = true;
- }
- static String getXString(String s, String s1) {
- if (rb == null)
- rb = new NLS("com.ibm.servlet.resources.personalization");
- if (rb != null)
- return rb.getString(s, s1);
- else
- return s1;
- }
- void startAlarms() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.startAlarms");
- invalidaterAlarm = SessionAlarmListener.startInvalidationAlarm(this,
- mInvalidationCheckPollInterval * 1000L);
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.startAlarms");
- }
- void stopAlarms() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.stopAlarms");
- SessionAlarmListener.stopListening(invalidaterAlarm);
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.stopAlarms");
- }
- HashMap createSessionTable() {
- return new SessionSimpleHashMap(tableSize, allowInfinite);
- }
- void startSessionContext() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.startSessionContext");
- if (sessionIDFactory == null)
- initializeSessionIdTemplate();
- startAlarms();
- stopSession = false;
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.startSessionContext");
- }
- void stopSessionContext(String s) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.stopSessionContext");
- if (getAppName() == "GLOBAL_HTTP_SESSION_CONTEXT")
- stopListeners(s);
- decrementRefCount();
- if (_refCount > 0) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr
- .exit(
- tc,
- "SessionContext.stopSessionContext: Reference count is not zero, so returning without stopping");
- return;
- }
- invalidateAllMemorySessions();
- stopSession = true;
- tableClear();
- try {
- SessionContextRegistry.remove(scAppParms.getAppName());
- } catch (Throwable throwable) {
- FFDCFilter.processException(throwable,
- "com.ibm.ws.webcontainer.httpsession.SessionContext.stop",
- "2237", this);
- Tr.error(tc, "SessionContext.exception", throwable);
- }
- scPmiData.unregister();
- mbeanAdapter.unregisterMBean();
- mSessionIdCounter = 0;
- stopAlarms();
- completedStartup = false;
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.stopSessionContext");
- }
- void stopListeners(String s) {
- if (s == null) {
- Tr.warning(tc, "SessionContext.stopListeners: j2eename is null");
- return;
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.stopListeners for " + s);
- for (int i = mHttpSessionListeners.size() - 1; i >= 0; i--) {
- ArrayList arraylist = (ArrayList) mHttpSessionListeners.get(i);
- if (!s.equals((String) arraylist.get(0)))
- continue;
- mHttpSessionListeners.remove(i);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.stopListeners: stopping http session listener for: "
- + s);
- }
- if (mHttpSessionListeners.size() == 0) {
- sessionListener = false;
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr
- .debug(tc,
- "SessionContext.stopListeners: stopped all http session listeners");
- }
- for (int j = mHttpSessionAttributeListeners.size() - 1; j >= 0; j--) {
- ArrayList arraylist1 = (ArrayList) mHttpSessionAttributeListeners
- .get(j);
- if (!s.equals((String) arraylist1.get(0)))
- continue;
- mHttpSessionAttributeListeners.remove(j);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.stopListeners: stopping http session attribute listener for: "
- + s);
- }
- if (mHttpSessionAttributeListeners.size() == 0) {
- sessionAttributeListener = false;
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr
- .debug(tc,
- "SessionContext.stopListeners: stopped all http session attribute listeners");
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.stopListeners");
- }
- void resetmSessions() {
- mSessions = null;
- }
- private void setSessionContextParameters(
- SessionContextParameters sessioncontextparameters) {
- mParams = sessioncontextparameters;
- initializeParameters();
- }
- SessionContextParameters getSessionContextParameters() {
- return mParams;
- }
- private InetAddress getLocalHost()
- {
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.getLocalHost");
- if(mLocalHost == null)
- synchronized(this)
- {
- try
- {
- if(is_zOS)
- mLocalHost = AdminHelper.getInstance().getLocalHost();
- else
- mLocalHost = (InetAddress)AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run()
- throws UnknownHostException
- {
- return InetAddress.getLocalHost();
- }
- throws UnknownHostException
- {
- super();
- }
- }
- );
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext:getLocalHost: InetAddress = " + mLocalHost);
- }
- catch(PrivilegedActionException privilegedactionexception)
- {
- FFDCFilter.processException(privilegedactionexception, "com.ibm.ws.webcontainer.httpsession.SessionContext.getLocalHost", "423", this);
- Tr.error(tc, "SessionContext.getLocalHostError");
- Tr.error(tc, "SessionContext.exception", privilegedactionexception);
- }
- catch(Exception exception)
- {
- FFDCFilter.processException(exception, "com.ibm.ws.webcontainer.httpsession.SessionContext.getLocalHost", "427", this);
- Tr.error(tc, "SessionContext.getLocalHostError");
- Tr.error(tc, "SessionContext.exception", exception);
- }
- }
- return mLocalHost;
- }
- void initializeSessionIdTemplate() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.initializeSessionIdTemplate");
- int i = 14;
- if (useBase32)
- i = (sessionIDLength * 5) / 8 + 1;
- else
- i = (sessionIDLength * 6) / 8 + 1;
- mSessionIdTemplate = new byte[i];
- int j = 8;
- byte abyte0[] = getLocalHost().getAddress();
- System.arraycopy(abyte0, 0, mSessionIdTemplate, j, 4);
- j += 4;
- int k = randIdGen.nextInt();
- mSessionIdTemplate[j++] = (byte) (k >> 8 & 255);
- mSessionIdTemplate[j++] = (byte) (k & 255);
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.initializeSessionIdTemplate");
- }
- int generateSessionIdCount() {
- int i = 0;
- synchronized (counterSyncher) {
- i = mSessionIdCounter++;
- }
- return i;
- }
- String generateSessionId() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.generateSessionId");
- if (sessionIDFactory != null) {
- return sessionIDFactory.getNextID();
- } else {
- byte abyte0[] = new byte[mSessionIdTemplate.length];
- System.arraycopy(mSessionIdTemplate, 0, abyte0, 0,
- mSessionIdTemplate.length);
- int i = 0;
- int j = generateSessionIdCount();
- int k = j;
- long l = System.currentTimeMillis();
- k = k * 39 + (int) (l >> 32 & -1L);
- k = k * 39 + (int) (l & -1L);
- abyte0[i++] = (byte) (k >> 24 & 255);
- abyte0[i++] = (byte) (k >> 16 & 255);
- abyte0[i++] = (byte) (k >> 8 & 255);
- abyte0[i++] = (byte) (k & 255);
- abyte0[i++] = (byte) (j >> 24 & 255);
- abyte0[i++] = (byte) (j >> 16 & 255);
- abyte0[i++] = (byte) (j >> 8 & 255);
- abyte0[i++] = (byte) (j & 255);
- return convertSessionIdBytesToSessionId(abyte0);
- }
- }
- static String convertSessionIdBytesToSessionId(byte abyte0[]) {
- if (useBase32)
- return convertSessionIdBytesToSessionIdBase32(abyte0);
- else
- return convertSessionIdBytesToSessionIdBase64(abyte0);
- }
- static String convertSessionIdBytesToSessionIdBase32(byte abyte0[]) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc,
- "SessionContext.convertSessionIdBytesToSessionIdBase32");
- int i = abyte0.length * 8;
- char ac[] = new char[sessionIDLength];
- int j = 0;
- int k = 0;
- int l = 0;
- do {
- if (j >= abyte0.length || l >= sessionIDLength)
- break;
- int i1 = 0;
- if (k <= 3) {
- i1 = abyte0[j] >> 3 - k & 31;
- } else {
- i1 = abyte0[j] << 5 - (8 - k);
- if (j + 1 < abyte0.length) {
- int j1 = (abyte0[j + 1] & 255) >> 8 - (5 - (8 - k));
- j1 &= sSecondByteMasks[5 - (8 - k)];
- i1 |= j1;
- }
- i1 &= 31;
- }
- ac[l++] = sBitChars[i1];
- if ((k += 5) >= 8) {
- j++;
- k -= 8;
- }
- } while (true);
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr
- .exit(tc,
- "SessionContext.convertSessionIdBytesToSessionIdBase32");
- return new String(ac);
- }
- static String convertSessionIdBytesToSessionIdBase64(byte abyte0[]) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc,
- "SessionContext.convertSessionIdBytesToSessionIdBase64");
- int i = abyte0.length * 8;
- char ac[] = new char[sessionIDLength];
- int j = 0;
- int k = 0;
- int l = 0;
- do {
- if (j >= abyte0.length || l >= sessionIDLength)
- break;
- int i1 = 0;
- if (k < 3) {
- i1 = abyte0[j] >> 2 - k & 63;
- } else {
- i1 = abyte0[j] << 6 - (8 - k);
- if (j + 1 < abyte0.length) {
- int j1 = (abyte0[j + 1] & 255) >> 8 - (6 - (8 - k));
- j1 &= sSecondByteMasks[6 - (8 - k)];
- i1 |= j1;
- }
- i1 &= 63;
- }
- ac[l++] = sBitChars[i1];
- if ((k += 6) >= 8) {
- j++;
- k -= 8;
- }
- } while (true);
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr
- .exit(tc,
- "SessionContext.convertSessionIdBytesToSessionIdBase64");
- return new String(ac);
- }
- boolean insertSessionOnCreation(String s, SessionData sessiondata) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.insertSessionOnCreation" + s);
- Object obj = tableGet(s);
- if (obj != null) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr
- .exit(tc,
- "SessionContext:insertSessionOnCreation: Detected duplicate id. Return true.");
- return true;
- }
- tablePut(s, sessiondata);
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr
- .exit(tc,
- "SessionContext:insertSessionOnCreation: Return false.");
- return false;
- }
- private String getAuthenticatedUser() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.getAuthenticatedUser");
- String s = SecurityContext.getUser();
- if (s == null)
- return "anonymous";
- else
- return s;
- }
- public Enumeration getIds() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.getIds");
- return (new Hashtable()).keys();
- }
- IHttpSession createSession(HttpServletRequest httpservletrequest, String s, boolean flag)
- {
- String s1;
- boolean flag1;
- String s3;
- String s4;
- String s5;
- int j;
- if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.createSession");
- s1 = null;
- flag1 = false;
- if(stopSession)
- {
- String s2 = getXString("SessionContext.createWhenStop", "SESN0006E: SessionContext: an attempt to create a session while WebSphere Session Manager was turned off was made");
- RuntimeException runtimeexception = new RuntimeException(s2);
- throw runtimeexception;
- }
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext:createSession entered with long id = " + s);
- s3 = s;
- s4 = null;
- s5 = null;
- if(s != null)
- {
- s5 = s.substring(0, cacheIdLength);
- int i = s.indexOf(cloneSeparator);
- if(i == -1)
- {
- s = s.substring(cacheIdLength);
- } else
- {
- s = s.substring(cacheIdLength, i);
- s4 = s3.substring(i);
- }
- }
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext:createSession id without cacheId and clone info is now = " + s);
- Object obj = null;
- Object obj1 = null;
- j = 0;
- _L2:
- SessionData sessiondata;
- String s6;
- j++;
- if(s == null || flag1)
- {
- s = generateSessionId();
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext:createSession: generated new sessionid = " + s);
- }
- if(allowInfinite)
- {
- IHttpSession ihttpsession = createSessionData(s);
- sessiondata = (SessionData)ihttpsession;
- } else
- {
- if(isMaxAllowedReached())
- {
- sessiondata = overflowData;
- scPmiData.incNoRoomForNewSession();
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext:createSession: overflow session ");
- return sessiondata;
- }
- IHttpSession ihttpsession1 = createSessionData(s);
- sessiondata = (SessionData)ihttpsession1;
- }
- sessiondata.initSession(this);
- sessiondata.setValidity(true);
- long l = System.currentTimeMillis();
- sessiondata.setCreationTime(l);
- sessiondata.setLastAccessedTime(l);
- updateCloneInfo(sessiondata, s4, true);
- if(s5 != null && cacheIdLength > 0)
- sessiondata.setCacheId(s5);
- if(integrateWASSec)
- if(securityEnabled)
- s1 = getAuthenticatedUser();
- else
- s1 = httpservletrequest.getRemoteUser();
- if(s1 == null)
- s1 = "anonymous";
- sessiondata.setUser(s1);
- sessiondata.setMaxInactInterval((int)mSessionInvalidationTime);
- if(flag)
- sessiondata.setUsingSSL(flag);
- if(s3 == null)
- break MISSING_BLOCK_LABEL_622;
- s6 = null;
- Object obj2 = null;
- synchronized(this)
- {
- s6 = (String)createSync.get(s);
- if(s6 == null)
- {
- s6 = s;
- createSync.put(s, s6);
- }
- }
- String s7 = s6;
- JVM INSTR monitorenter ;
- IHttpSession ihttpsession2 = (IHttpSession)getFromMemory(s);
- if(ihttpsession2 == null)
- {
- flag1 = processSessionOnCreation(s, sessiondata);
- createSync.remove(s);
- } else
- {
- createSync.remove(s);
- return ihttpsession2;
- }
- s7;
- JVM INSTR monitorexit ;
- continue; /* Loop/switch isn't completed */
- Exception exception1;
- exception1;
- throw exception1;
- flag1 = processSessionOnCreation(s, sessiondata);
- if(flag1 && j < 10) goto _L2; else goto _L1
- _L1:
- if(j == 10 && flag1)
- {
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext:createSession: Almost stuck in createLoop");
- Tr.warning(tc, "SessionManager unable to generate unique session id in 10 tries, so gave up");
- return null;
- }
- int k = establishAffinity(sessiondata);
- if(k != 0)
- {
- Tr.error(tc, "SessionContext:createSession - call to establishAffinity for id " + s + " failed with rc " + k);
- return null;
- }
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "!!!!!SessionContext:createSession: about to increment inServiceMethodCount!!!!!!");
- bumpCreateCount();
- sessiondata.incrementInServiceMethodCount();
- sessiondata.setActive(true, -1L);
- if(sessionListener)
- {
- HttpSessionEvent httpsessionevent = new HttpSessionEvent(sessiondata);
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext:createSession: calling sessionCreatedEvent()");
- sessionCreatedEvent(httpsessionevent);
- }
- if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.createSession");
- return sessiondata;
- }
- private final boolean processSessionOnCreation(String s,
- SessionData sessiondata) {
- return insertSessionOnCreation(s, sessiondata);
- }
- boolean isMaxAllowedReached() {
- return mSessions.size() == tableSize;
- }
- abstract IHttpSession createSessionData(String s);
- abstract void performInvalidation();
- void pollInvalidations()
- {
- if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.pollInvalidations " + getAppName());
- setThreadContext();
- if(debugSessionCrossover)
- currentThreadSessionId.set("WAS-SYSTEM-THREAD");
- performInvalidation();
- unsetThreadContext();
- if(debugSessionCrossover)
- currentThreadSessionId.set(null);
- break MISSING_BLOCK_LABEL_148;
- Throwable throwable;
- throwable;
- FFDCFilter.processException(throwable, "com.ibm.ws.webcontainer.httpsession.SessionContext.pollInvalidations", "818", this);
- Tr.error(tc, "SessionContext.exception", throwable);
- unsetThreadContext();
- if(debugSessionCrossover)
- currentThreadSessionId.set(null);
- break MISSING_BLOCK_LABEL_148;
- Exception exception;
- exception;
- unsetThreadContext();
- if(debugSessionCrossover)
- currentThreadSessionId.set(null);
- throw exception;
- scPmiData.incInvalidatorExecutedCount();
- invalidaterAlarm = SessionAlarmListener.startInvalidationAlarm(this, mInvalidationCheckPollInterval * 1000L);
- if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.pollInvalidations " + getAppName());
- return;
- }
- void asyncExternalWrite() {
- }
- boolean isIBMSessionListenerImplemented() {
- ArrayList arraylist = getHttpSessionListeners();
- for (int i = 0; i < arraylist.size(); i++) {
- HttpSessionListener httpsessionlistener = (HttpSessionListener) (HttpSessionListener) ((ArrayList) arraylist
- .get(i)).get(1);
- if (httpsessionlistener != null
- && (httpsessionlistener instanceof IBMSessionListener))
- return true;
- }
- return false;
- }
- void notifySessionRemovedFromCache(String s) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.notifySessionRemovedFromCache for "
- + s);
- ArrayList arraylist = getHttpSessionListeners();
- for (int i = 0; i < arraylist.size(); i++) {
- HttpSessionListener httpsessionlistener = (HttpSessionListener) (HttpSessionListener) ((ArrayList) arraylist
- .get(i)).get(1);
- if (httpsessionlistener == null
- || !(httpsessionlistener instanceof IBMSessionListener))
- continue;
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "calling " + httpsessionlistener
- + ".sessionremovedFromCache(" + s + ")");
- ((IBMSessionListener) httpsessionlistener)
- .sessionRemovedFromCache(s);
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.notifySessionRemovedFromCache");
- }
- public void notifySessionInvalidated(SessionData sessiondata) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.notifySessionInvalidated");
- removeAffinity(sessiondata);
- try {
- sessiondata.sessionUnbound(this);
- removeSessionFromTable(sessiondata);
- sessiondata.setValidity(false);
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.notifySessionInvalidated");
- }
- void removeSessionFromTable(SessionData sessiondata) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.removeSessionFromTable");
- tableRemove(sessiondata.getId());
- }
- public void notifySessionAccessed(SessionData sessiondata) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.notifySessionAccessed");
- if (sessiondata.isValid())
- scPmiData.incSessionAccessCount();
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.notifySessionAccessed");
- }
- long getSessionInvalidationTime() {
- return mSessionInvalidationTime;
- }
- public void setSessionInvalidationTime(long l) {
- mSessionInvalidationTime = l;
- }
- boolean isSessionTrackingActive() {
- return mSessionTrackingActive;
- }
- public boolean isUsingCookies() {
- return mUsingCookies;
- }
- public void setUsingCookies(boolean flag) {
- mUsingCookies = flag;
- }
- public boolean isUsingURL() {
- return mUsingURL;
- }
- public void setUsingURL(boolean flag) {
- mUsingURL = flag;
- }
- public boolean isURLProtocolSwitchRewritingActive() {
- return mURLProtocolSwitchRewritingActive;
- }
- public void setURLProtocolSwitchRewritingActive(boolean flag) {
- mURLProtocolSwitchRewritingActive = flag;
- }
- String getSessionCookieName() {
- return mSessionCookieName;
- }
- public void setSessionCookieName(String s) {
- mSessionCookieName = s;
- }
- String getSessionCookieComment() {
- return mSessionCookieComment;
- }
- public void setSessionCookieComment(String s) {
- mSessionCookieComment = s;
- }
- String getSessionCookieDomain() {
- return mSessionCookieDomain;
- }
- public void setSessionCookieDomain(String s) {
- if (s != null && s.length() > 0)
- mSessionCookieDomain = s;
- else
- mSessionCookieDomain = null;
- }
- int getSessionCookieMaxAge() {
- return mSessionCookieMaxAge;
- }
- public void setSessionCookieMaxAge(int i) {
- mSessionCookieMaxAge = i;
- }
- String getSessionCookiePath() {
- return mSessionCookiePath;
- }
- public void setSessionCookiePath(String s) {
- mSessionCookiePath = s;
- }
- boolean getSessionCookieSecure() {
- return mSessionCookieSecure;
- }
- public void setSessionCookieSecure(boolean flag) {
- mSessionCookieSecure = flag;
- }
- void updateCloneInfo(SessionData sessiondata, String s, boolean flag) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.updateCloneInfo - input cloneInfo="
- + s + " newSession=" + flag);
- String s1 = getCloneIdWithSeparator();
- if (s != null)
- synchronized (sessiondata) {
- if (!sessiondata.isCloneIdUpdated()) {
- sessiondata.setPreviousClones(s);
- int i = s.indexOf(s1);
- if (i == -1) {
- StringBuffer stringbuffer = new StringBuffer();
- if (!noSwitchOver) {
- stringbuffer.append(s);
- stringbuffer.append(s1);
- } else {
- stringbuffer.append(s1);
- stringbuffer.append(s);
- }
- sessiondata.setPreviousClones(stringbuffer.toString());
- sessiondata.setCloneIdUpdated(true);
- scPmiData.incAffinityBreaks();
- if (cacheIdLength + sessionIDLength
- + sessiondata.getPreviousClones().length() > maxSessionIdentifierLength) {
- String as[] = {
- sessiondata.getBrowserToken(sessiondata
- .usingSSL()),
- (new Integer(maxSessionIdentifierLength))
- .toString() };
- Tr
- .warning(
- tc,
- "SessionContext.maxSessionIdLengthExceeded",
- as);
- }
- }
- }
- }
- else if (flag) {
- sessiondata.setPreviousClones(s1);
- sessiondata.setCloneIdUpdated(true);
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.updateCloneInfo");
- }
- SessionData findSession(String s) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.findSession id=" + s);
- SessionData sessiondata = null;
- String s1 = null;
- Object obj = null;
- String s2 = null;
- if (s.length() <= cacheIdLength) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr
- .exit(tc,
- "SessionContext.findSession return null because length is too short");
- return null;
- }
- int i = s.indexOf(cloneSeparator);
- if (i == -1) {
- s1 = s.substring(cacheIdLength - getCacheIdLengthInUse());
- } else {
- s1 = s.substring(cacheIdLength - getCacheIdLengthInUse(), i);
- s2 = s.substring(i);
- }
- sessiondata = (SessionData) tableGet(s1);
- if (sessiondata != null)
- if (sessiondata.isValid()
- && sessiondata.getMaxInactiveInterval() == 0) {
- sessiondata.invalidate();
- sessiondata = null;
- } else {
- updateCloneInfo(sessiondata, s2, false);
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.findSession");
- return sessiondata;
- }
- int getCacheIdLengthInUse() {
- return 0;
- }
- IHttpSession getIHttpSession(String s, HttpServletRequest httpservletrequest) {
- return getIHttpSession(s, httpservletrequest, false);
- }
- IHttpSession getIHttpSession(String s, HttpServletRequest httpservletrequest, boolean flag)
- {
- SessionData sessiondata;
- boolean flag1 = false;
- if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.getIHttpSession: " + s + " isSSL " + flag);
- if(stopSession)
- {
- String s1 = getXString("SessionContext.accessWhenStop", "SESN0007E: SessionContext: an attempt to access a session while WebSphere Session Manager was turned off was made");
- RuntimeException runtimeexception = new RuntimeException(s1);
- throw runtimeexception;
- }
- sessiondata = null;
- sessiondata = findSession(s);
- if(sessiondata == null)
- break MISSING_BLOCK_LABEL_306;
- SessionData sessiondata1 = sessiondata;
- JVM INSTR monitorenter ;
- if(!sessiondata.isValid())
- {
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext:getIHttpSession - session invalidated since initial retrival; id - " + s + " session - " + sessiondata);
- return null;
- }
- sessiondata.initSession(this);
- if(integrateWASSec)
- checkSecurity(sessiondata, httpservletrequest);
- long l = sessiondata.getLastAccTime();
- sessiondata.accessSessionData();
- sessiondata.setActive(true, sessiondata.getLastAccTime() - l);
- sessiondata.incrementInServiceMethodCount();
- sessiondata.setNew(false);
- if(flag)
- sessiondata.setUsingSSL(true);
- if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- {
- String s3 = "SessionContext: found the session for the id " + s;
- Tr.exit(tc, s3);
- }
- sessiondata.notifyActivateListeners();
- sessiondata1;
- JVM INSTR monitorexit ;
- break MISSING_BLOCK_LABEL_351;
- Exception exception;
- exception;
- throw exception;
- if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- {
- String s2 = "SessionContext: no valid session for the id " + s;
- Tr.debug(tc, s2);
- }
- if(sessiondata == null)
- scPmiData.IncAttemptToActivateNonExistent();
- if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext:getIHttpSession - leaving and returning session of " + sessiondata);
- return sessiondata;
- }
- private String getSessionIDOnly(String s) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc,
- "SessionContext.getSessionIDOnly - remove the cloneids");
- String s1 = s;
- int i = s.indexOf(cloneSeparator);
- if (i == -1)
- s1 = s.substring(cacheIdLength);
- else
- s1 = s.substring(cacheIdLength, i);
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.getSessionIDOnly returning " + s1);
- return s1;
- }
- public HttpSession getSession(String s) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.getSession");
- return null;
- }
- ArrayList getHttpSessionAttributeListeners() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext:getHttpSessionAttributeListeners");
- return mHttpSessionAttributeListeners;
- }
- ArrayList getHttpSessionListeners() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext:getHttpSessionListeners");
- return mHttpSessionListeners;
- }
- private void setServletContext(ServletContext servletcontext) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext:setServletContext");
- mServletContext = servletcontext;
- }
- public ServletContext getServletContext() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext:getServletContext");
- return mServletContext != null ? ((IServletContext) mServletContext)
- .getFacade() : null;
- }
- synchronized void initializeParameters() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.initializeParameters");
- try {
- securityEnabled = WSSecurityHelper.isServerSecurityEnabled();
- if (!hideSessionValuesPropertySet)
- hideSessionValues = securityEnabled;
- setSessionTimeoutInfo();
- tableSize = mParams.getInMemorySize();
- if (tableSize <= 0)
- throw new RuntimeException(
- "In memory session size cannot be less than or equal to 0");
- allowInfinite = mParams.getEnableOverflow();
- setUsingCookies(mParams.getEnableCookies());
- setUsingURL(mParams.getEnableUrlRewriting());
- setURLProtocolSwitchRewritingActive(mParams
- .getEnableUrlProtocolSwitchRewriting());
- setSessionCookieName(mParams.getSessionCookieName());
- setSessionCookieComment(mParams.getSessionCookieComment());
- String s = mParams.getSessionCookieDomain();
- if (s != null && s.length() > 0)
- setSessionCookieDomain(s);
- else
- setSessionCookieDomain(null);
- setSessionCookieMaxAge(mParams.getSessionCookieMaxAge());
- setSessionCookiePath(mParams.getSessionCookiePath());
- setSessionCookieSecure(mParams.getSessionCookieSecure());
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext:initializeParameters - cloneId for this JVM is "
- + cloneId);
- if (cloneId != null)
- cloneIdLength = cloneId.length();
- if (mParams.usingDatabase() && !mParams.getEnableTimeBasedWrite())
- pinSR = false;
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext:initializeParameters - pinSR set to "
- + pinSR);
- useSSLId = mParams.useSSLId();
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.initializeParameters : UseSSLId = "
- + useSSLId);
- integrateWASSec = mParams.getIntegrateSecurity();
- timedOutAffinityEnabled = mParams.getEnableAffinityTimeout();
- if (timedOutAffinityEnabled)
- affinityTimeOut = mParams.getAffinityTimeoutInterval();
- allowSerializedSessionAccess = mParams
- .getAllowSerializedSessionAccess();
- serializedSessionAccessMaxWaitTime = mParams
- .getSerializedSessionAccessMaxWaitTime();
- accessSessionOnTimeout = mParams.getAccessSessionOnTimeout();
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
- Tr.debug(tc, " ");
- Tr.debug(tc,
- "SessionContext:initializeParameters - timedOutAffinityEnabled is : "
- + timedOutAffinityEnabled);
- Tr.debug(tc,
- "SessionContext:initializeParameters - affinityTimeOut is : "
- + affinityTimeOut);
- }
- zAffinityCloneId = cloneId;
- if (turnOffCloneId
- && (SessionMgrComponentImpl.getServerId().equals("-1") || is_zOS
- && !SessionMgrComponentImpl.getClusterServerMode())) {
- cloneId = "";
- cloneIdLength = 0;
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr
- .debug(
- tc,
- "SessionContext:initializeParameters - Remove CloneID because NoAdditionalSessionInfo=true.");
- }
- cloneSeparator = cloneSep.charAt(0);
- if (cloneId != null && cloneId.length() > 0)
- cloneIdWithSep = cloneSep + cloneId;
- else
- cloneIdWithSep = "";
- cacheIdPlusIdlength = cacheIdLength + sessionIDLength;
- } catch (SessionContextParameterException sessioncontextparameterexception) {
- FFDCFilter
- .processException(
- sessioncontextparameterexception,
- "com.ibm.ws.webcontainer.httpsession.SessionContext.initializeParameters",
- "1555", this);
- Tr.error(tc, "SessionContext.exception",
- sessioncontextparameterexception);
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.initializeParameters");
- }
- void setSessionTimeoutInfo() {
- setSessionTimeoutInfo(0);
- }
- synchronized void setSessionTimeoutInfo(int i) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.setSessionTimeoutInfo");
- long l1 = 0L;
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- if (i == 0)
- Tr
- .debug(tc,
- "SessionContext:setSessionTimeoutInfo -- Normal Update");
- else
- Tr.debug(tc,
- "SessionContext:setSessionTimeoutInfo -- Dynamic Global Update.. input parm = "
- + i);
- try {
- long l = scAppParms.getSessionTimeout();
- long l3 = l;
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext:setSessionTimeoutInfo timeout value in WebApp is"
- + l3);
- if (l == 0L) {
- long l2;
- if (i != 0)
- l2 = i;
- else
- l2 = mParams.getSessionInvalidationTime();
- l3 = l2;
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext:setSessionTimeoutInfo Global timeout is: "
- + l3);
- }
- if (i == 0 || l == 0L) {
- l3 = checkMinimumInvalidation(l3);
- setSessionInvalidationTime(l3);
- int j = randIdGen.nextInt() % 30;
- if (j < 0)
- j *= -1;
- if (mInvalidationCheckPollInterval <= 0L) {
- if (l3 < 120L)
- mInvalidationCheckPollInterval = 60 - j;
- if (l3 >= 120L && l3 < 900L)
- mInvalidationCheckPollInterval = 60 + j;
- if (l3 >= 900L)
- mInvalidationCheckPollInterval = 300 + 2 * j;
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
- Tr.debug(tc,
- "SessionContext:setSessionTimeoutInfo -- Updating timeout value to: "
- + l3);
- Tr
- .debug(
- tc,
- "SessionContext:setSessionTimeoutInfo -- mInvalidationCheckPollInterval is now: "
- + mInvalidationCheckPollInterval);
- }
- } else if (TraceComponent.isAnyTracingEnabled()
- && tc.isDebugEnabled())
- Tr
- .debug(tc,
- "SessionContext:setSessionTimeoutInfo -- Timeout Value NOT Updated");
- } catch (Throwable throwable) {
- FFDCFilter
- .processException(
- throwable,
- "com.ibm.ws.webcontainer.httpsession.SessionContext.setSessionTimeoutInfo",
- "1646", this);
- Tr.error(tc, "SessionContext.exception", throwable);
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.setSessionTimeoutInfo");
- }
- long checkMinimumInvalidation(long l) {
- return l;
- }
- public boolean shouldEncodeURL(String s,
- HttpServletRequest httpservletrequest) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.shouldEncodeURL");
- if (!isUsingURL()) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.encodeOff");
- return false;
- }
- if (!isProtocolSwitch(s, httpservletrequest))
- return true;
- if (isURLProtocolSwitchRewritingActive()) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.encodeProtocolSwitchon");
- return true;
- } else {
- return false;
- }
- }
- public boolean shouldEncodeRedirectURL(String s) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.shouldEncodeRedirectURL");
- if (!isUsingURL()) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.encodeOff");
- return false;
- } else {
- return true;
- }
- }
- private boolean isProtocolSwitch(String s,
- HttpServletRequest httpservletrequest) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.isProtocolSwitch");
- int i = s.indexOf("://");
- if (i < 0)
- return false;
- String s1 = s.substring(0, i);
- if ((!s1.equalsIgnoreCase("http") || !httpservletrequest.getScheme()
- .equalsIgnoreCase("https"))
- && (!s1.equalsIgnoreCase("https") || !httpservletrequest
- .getScheme().equalsIgnoreCase("http")))
- return false;
- int j = i + 3;
- int k = j;
- int l = s.length();
- do {
- if (k >= l)
- break;
- char c = s.charAt(k);
- if (c == ':' || c == '/')
- break;
- k++;
- } while (true);
- String s2 = s.substring(j, k);
- InetAddress inetaddress;
- try {
- inetaddress = InetAddress.getByName(s2);
- } catch (UnknownHostException unknownhostexception) {
- FFDCFilter
- .processException(
- unknownhostexception,
- "com.ibm.ws.webcontainer.httpsession.SessionContext.isProtocolSwitch",
- "1760", this);
- Tr.error(tc, "SessionContext.exception", unknownhostexception);
- return false;
- }
- return inetaddress.equals(getLocalHost());
- }
- public void sync(HttpSession httpsession) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.sync");
- }
- public void reload(String s) {
- stopSessionContext(s);
- }
- public String toHTML() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.toHTML");
- String s = scAppParms.getJ2EEName();
- String s1 = "<b> (for this webapp) : </b> ";
- StringBuffer stringbuffer = new StringBuffer();
- stringbuffer
- .append(
- "<center><h3>J2EE NAME(AppName#WebModuleName):: " + s
- + " </h3></center>" + "<UL>\n")
- .append("<b> cloneId</b> : ")
- .append(cloneId)
- .append("<BR>")
- .append("<BR>")
- .append("<b> Number of sessions in memory: </b>")
- .append(s1)
- .append(mSessions == null ? 0 : mSessions.size())
- .append("<BR>")
- .append("<b> use overflow</b> : ")
- .append(allowInfinite)
- .append("<BR>")
- .append("<b> overflow size</b> ")
- .append(s1)
- .append("<BR>")
- .append(
- "<b> Invalidation alarm poll interval (for this webapp) </b> : ")
- .append(mInvalidationCheckPollInterval)
- .append("<BR>")
- .append(
- "<b> Max invalidation timeout (for this webapp) </b> : ")
- .append(mSessionInvalidationTime).append("<BR>").append(
- "<b> Using Cookies </b> : ").append(mUsingCookies)
- .append("<BR>").append("<b> Using URL Rewriting </b> : ")
- .append(mUsingURL).append("<BR>").append(
- "<b> use SSLId </b> : ").append(useSSLId)
- .append("<BR>").append(
- "<b> URL Protocol Switch Rewriting </b> : ").append(
- mURLProtocolSwitchRewritingActive).append("<BR>")
- .append("<b> Session Cookie Name </b> : ").append(
- mSessionCookieName).append("<BR>").append(
- "<b> Session Cookie Comment </b> : ").append(
- mSessionCookieComment).append("<BR>").append(
- "<b> Session Cookie Domain </b> : ").append(
- mSessionCookieDomain).append("<BR>").append(
- "<b> Session Cookie Path </b> : ").append(
- mSessionCookiePath).append("<BR>").append(
- "<b> Session Cookie MaxAge </b> : ").append(
- mSessionCookieMaxAge).append("<BR>").append(
- "<b> Session Cookie Secure </b> : ").append(
- mSessionCookieSecure).append("<BR>").append(
- "<b> Maximum in memory table size </b> : ").append(
- tableSize).append("<BR>").append(
- "<b> current time </b> : ").append(
- (new Date(System.currentTimeMillis())).toString())
- .append("<BR>").append("<b> integrateWASSec</b> :").append(
- integrateWASSec)
- .append("<BR><b>Session locking </b>: ").append(
- allowSerializedSessionAccess).append(
- "<BR><b>Session locking timeout</b>: ").append(
- serializedSessionAccessMaxWaitTime).append(
- "<BR><b>Allow access on lock timeout</b>:").append(
- accessSessionOnTimeout).append(scPmiData.toHTML())
- .append(mbeanAdapter.toHTML());
- return stringbuffer.toString();
- }
- public String toHTML2() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.toHTML");
- StringBuffer stringbuffer = new StringBuffer();
- stringbuffer.append(
- "<center><h3>Session Tracking Internals</h3></center><UL>\n")
- .append("<b> mSessions </b> : ").append(
- mSessions == null ? null : mSessions.toString())
- .append("<BR>");
- return stringbuffer.toString();
- }
- public String toString() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.toString");
- StringBuffer stringbuffer = new StringBuffer();
- stringbuffer.append(
- "\nSession Tracking Internals for webapp "
- + scAppParms.getJ2EEName() + ": \n").append("\n")
- .append(" mSessions size : ").append(
- mSessions == null ? 0 : mSessions.size()).append("\n")
- .append(" use overflow : ").append(allowInfinite).append("\n")
- .append(" overflow size : ").append("\n").append(
- "mInvalidationCheckPollInterval : ").append(
- mInvalidationCheckPollInterval).append("\n").append(
- "mSessionInvalidationTime : ").append(
- getSessionInvalidationTime()).append("\n").append(
- "mSessionTrackingActive : ").append(
- isSessionTrackingActive()).append("\n").append(
- "mUsingCookies : ").append(isUsingCookies()).append(
- "\n").append("mUsingURL : ").append(isUsingURL())
- .append("\n").append("useSSLId : ").append(useSSLId).append(
- "\n").append("mURLProtocolSwitchRewritingActive : ")
- .append(isURLProtocolSwitchRewritingActive()).append("\n")
- .append("mSessionCookieName : ")
- .append(getSessionCookieName()).append("\n").append(
- "mSessionCookieComment : ").append(
- getSessionCookieComment()).append("\n").append(
- "mSessionCookieDomain : ").append(
- getSessionCookieDomain()).append("\n").append(
- "mSessionCookiePath : ")
- .append(getSessionCookiePath()).append("\n").append(
- "mSessionCookieSecure : ").append(
- getSessionCookieSecure()).append("\n").append(
- "mSessionCookieMaxAge : ").append(
- getSessionCookieMaxAge()).append("\n").append(
- "in memory table size : ").append(tableSize).append(
- "\n").append("current time : ").append(
- (new Date(System.currentTimeMillis())).toString())
- .append("\n").append("integrateWASSec :").append(
- integrateWASSec).append("\n").append(
- "\nSession serialization: ").append(
- allowSerializedSessionAccess).append(
- "\nSession serialization timeout: ").append(
- serializedSessionAccessMaxWaitTime).append(
- "Allow access on serialization timeout:").append(
- accessSessionOnTimeout);
- return stringbuffer.toString();
- }
- String toString2() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.toString2");
- StringBuffer stringbuffer = new StringBuffer(toString());
- stringbuffer.append("mSessions : ").append(
- mSessions == null ? null : mSessions.toString()).append("\n");
- return stringbuffer.toString();
- }
- void tablePut(Object obj, Object obj1) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.tablePut");
- try {
- mSessions.put(obj, obj1);
- incMemoryCount();
- } catch (TooManySessionsException toomanysessionsexception) {
- FFDCFilter
- .processException(
- toomanysessionsexception,
- "com.ibm.ws.webcontainer.httpsession.SessionContext.tablePut",
- "2008", this);
- Tr.error(tc, "SessionContext.exception", toomanysessionsexception);
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.tablePut");
- }
- void incMemoryCount() {
- scPmiData.incMemoryCount();
- }
- void decMemoryCount() {
- scPmiData.decMemoryCount();
- }
- Object tableGet(Object obj) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.tableGet");
- return mSessions.get(obj);
- }
- void tableRemove(Object obj) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.tableRemove " + obj);
- Object obj1 = mSessions.remove(obj);
- if (obj1 != null) {
- decMemoryCount();
- if (mIBMSessionListenerImplemented)
- notifySessionRemovedFromCache((String) obj);
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.tableRemove");
- }
- void tableClear() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.tableClear");
- HashSet hashset = new HashSet(mSessions.keySet());
- mSessions.clear();
- if (mIBMSessionListenerImplemented) {
- for (Iterator iterator = hashset.iterator(); iterator.hasNext(); notifySessionRemovedFromCache((String) iterator
- .next()))
- ;
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc, "SessionContext.tableClear");
- }
- HashMap getHashMap() {
- return mSessions;
- }
- boolean isSessionIdInUse(String s) {
- if (tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.IsSessionIdInUse: entered with " + s);
- boolean flag = false;
- Enumeration enumeration = SessionContextRegistry
- .getScrSessionContexts();
- do {
- if (!enumeration.hasMoreElements() || flag)
- break;
- SessionContext sessioncontext = (SessionContext) enumeration
- .nextElement();
- if (sessioncontext != this) {
- Object obj = sessioncontext.getFromMemory(s);
- if (obj != null)
- flag = true;
- }
- } while (true);
- if (flag) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc,
- "SessionContext.IsSessionIdInUse Found in Cache/Mem");
- return flag;
- }
- flag = isPresentInExternalStore(s);
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc,
- "SessionContext:isSessionIdInUse: after persistent store scan returning: "
- + flag);
- return flag;
- }
- Object getFromMemory(Object obj) {
- return mSessions.get(obj);
- }
- boolean isPresentInExternalStore(Object obj) {
- return false;
- }
- Enumeration tableKeys() {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.tableKeys");
- Set set = mSessions == null ? (new HashMap(1)).keySet() : mSessions
- .keySet();
- final Iterator iter = set.iterator();
- return new Enumeration() {
- public boolean hasMoreElements() {
- return iter.hasNext();
- }
- public Object nextElement() {
- return iter.next();
- }
- {
- super();
- }
- };
- }
- int getCloneIdLength() {
- return cloneIdLength;
- }
- String getCloneId() {
- return cloneId;
- }
- String getIDFromBytes(byte abyte0[]) {
- return convertSessionIdBytesToSessionId(abyte0);
- }
- public boolean isSSLSessions() {
- return useSSLId;
- }
- boolean getAllowSerializedSessionAccess() {
- return allowSerializedSessionAccess;
- }
- int getSerializedSessionAccessMaxWaitTime() {
- return serializedSessionAccessMaxWaitTime;
- }
- boolean getAccessSessionOnTimeout() {
- return accessSessionOnTimeout;
- }
- void invalidateAllMemorySessions() {
- }
- public synchronized void stop(String s) {
- stopSessionContext(s);
- }
- public String getCloneSeparator() {
- return cloneSep;
- }
- String getCloneIdWithSeparator() {
- return cloneIdWithSep;
- }
- String getAppName() {
- try {
- return scAppParms.getAppName();
- } catch (Throwable throwable) {
- FFDCFilter
- .processException(
- throwable,
- "com.ibm.ws.webcontainer.httpsession.SessionContext.getAppName",
- "2256", this);
- Tr.error(tc, "SessionContext.exception", throwable);
- return null;
- }
- }
- public HttpSession getIHttpSession(HttpServletRequest httpservletrequest,
- HttpServletResponse httpservletresponse, boolean flag) {
- return getIHttpSession(httpservletrequest, httpservletresponse, flag,
- false);
- }
- private HttpSession getIHttpSession(HttpServletRequest httpservletrequest,
- HttpServletResponse httpservletresponse, boolean flag, boolean flag1) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc,
- "SessionContext.getIHttpSession(req,res,create,cacheOnly): create = "
- + flag + " cacheOnly= " + flag1);
- boolean flag2 = false;
- boolean flag3 = false;
- IHttpSession ihttpsession = null;
- String s = null;
- String s1 = ((IExtendedRequest) httpservletrequest)
- .getUpdatedSessionId();
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.getIHttpSession: id from request object is "
- + s1);
- if (s1 != null)
- s = s1;
- if (s == null) {
- s = getFullSessionId(httpservletrequest);
- if (!useSSLId && s != null) {
- flag3 = true;
- if (s.length() < cacheIdPlusIdlength) {
- Tr.warning(tc, "SessionContext.getIHttpSession: id " + s
- + " failed length check against "
- + cacheIdPlusIdlength);
- s = null;
- }
- }
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.getIHttpSession : UseSSLId = "
- + useSSLId);
- if (useSSLId
- && ((IExtendedRequest) httpservletrequest).getSSLId() != null)
- flag2 = true;
- if (s != null && (!flag1 || getFromMemory(getSessionIDOnly(s)) != null))
- ihttpsession = getIHttpSession(s, httpservletrequest, flag2);
- if (ihttpsession == null && flag3) {
- List list = getAllRequestedSessionIdsFromCookies(httpservletrequest);
- if (list != null && list.size() > 1) {
- ihttpsession = checkAllCookies(list, 1, httpservletrequest,
- flag2);
- if (ihttpsession != null)
- s = ((SessionData) ihttpsession).getCacheId()
- + ihttpsession.getId();
- }
- }
- if (ihttpsession != null) {
- String s2 = getSessionIDOnly(s);
- if (!s2.equals(ihttpsession.getId())) {
- Object aobj[] = { getAppName(), ihttpsession.getId(), s2,
- new SessionCrossoverStackTrace() };
- Tr.error(tc, "SessionContext.CrossoverOnRetrieve",
- ((Object) (aobj)));
- ihttpsession = null;
- } else if (crossoverCheck(ihttpsession.getId())) {
- Object aobj1[] = { getAppName(), ihttpsession.getId(),
- (String) currentThreadSessionId.get(),
- new SessionCrossoverStackTrace() };
- Tr.error(tc, "SessionContext.CrossoverOnRetrieve",
- ((Object) (aobj1)));
- ihttpsession = null;
- }
- }
- if (ihttpsession == null && flag)
- if (s != null) {
- if (flag2) {
- ihttpsession = createSession(httpservletrequest, s, true);
- if (TraceComponent.isAnyTracingEnabled()
- && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.getIHttpSession : sslReq path so create session with Id = "
- + s);
- } else {
- String s3 = null;
- if (!idReuse && s.length() >= cacheIdPlusIdlength)
- s3 = s.substring(cacheIdLength, cacheIdPlusIdlength);
- if (idReuse || s1 != null || isSessionIdInUse(s3))
- ihttpsession = createSession(httpservletrequest, s,
- false);
- else
- ihttpsession = createSession(httpservletrequest, null,
- false);
- }
- } else {
- ihttpsession = createSession(httpservletrequest, null, false);
- }
- if (ihttpsession != null) {
- if (((SessionData) ihttpsession).internalIsNew())
- updateCurrentThreadSessionId((SessionData) ihttpsession);
- ((SessionData) ihttpsession).setPathInfo(httpservletrequest
- .getPathInfo());
- Object obj = null;
- boolean flag4 = ihttpsession.usingSSL();
- if (mUsingCookies && ihttpsession.isBrowserTokenUpdated()) {
- String s4 = ihttpsession.testAndGetBrowserToken(flag4);
- setCookie(httpservletrequest, httpservletresponse, s4, flag4);
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "calling req.setSessionid "
- + ihttpsession.getBrowserToken(flag4));
- ((IExtendedRequest) httpservletrequest).setSessionId(ihttpsession
- .getBrowserToken(flag4));
- } else if (idReuse && s != null && s1 == null)
- ((IExtendedRequest) httpservletrequest).setSessionId(s);
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.exit(tc,
- "SessionContext.getIHttpSession(req,res,create,cacheOnly)");
- return ihttpsession;
- }
- private IHttpSession checkAllCookies(List list, int i,
- HttpServletRequest httpservletrequest, boolean flag) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc,
- "SessionContext.checkAllCookies got this many cookies: "
- + list.size());
- IHttpSession ihttpsession = null;
- for (int j = i; j < list.size(); j++) {
- String s1 = (String) list.get(j);
- if (s1 == null || s1.length() < cacheIdPlusIdlength)
- continue;
- ihttpsession = getIHttpSession(s1, httpservletrequest, flag);
- if (ihttpsession == null)
- continue;
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.checkAllCookies found session using cookie index "
- + j + " with id " + s1);
- break;
- }
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
- String s = ihttpsession != null ? "non-null" : "null";
- Tr.exit(tc, "SessionContext.checkAllCookies returning " + s);
- }
- return ihttpsession;
- }
- private String getFullSessionId(HttpServletRequest httpservletrequest) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.getFullSessionId");
- Object obj = null;
- if (useSSLId) {
- String s = getRequestedSessionIdFromSSL(httpservletrequest);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.getFullSessionId: SSL Id = " + s);
- if (s != null)
- return s;
- }
- if (mUsingCookies) {
- String s1 = getRequestedSessionIdFromCookie(httpservletrequest);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.getFullSessionId: Cookie Id = "
- + s1);
- if (s1 != null)
- return s1;
- }
- if (mUsingURL) {
- String s2 = getRequestedSessionIdFromURL(httpservletrequest);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.getFullSessionId: URL Id = " + s2);
- if (s2 != null)
- return s2;
- }
- return null;
- }
- public String getRequestedSessionId(HttpServletRequest httpservletrequest) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.getRequestedSessionId");
- Object obj = null;
- if (useSSLId) {
- String s = getRequestedSessionIdFromSSL(httpservletrequest);
- if (s != null)
- return getSessionIDOnly(s);
- }
- if (mUsingCookies) {
- List list = getAllRequestedSessionIdsFromCookies(httpservletrequest);
- if (list != null) {
- if (list.size() > 1) {
- IHttpSession ihttpsession = checkAllCookies(list, 0,
- httpservletrequest, false);
- if (ihttpsession != null)
- return ihttpsession.getId();
- }
- if (list.size() > 0) {
- String s1 = (String) list.get(0);
- if (s1 != null)
- return getSessionIDOnly(s1);
- }
- }
- }
- if (mUsingURL) {
- String s2 = getRequestedSessionIdFromURL(httpservletrequest);
- if (s2 != null)
- return getSessionIDOnly(s2);
- }
- return null;
- }
- public boolean isRequestedSessionIdFromCookie(
- HttpServletRequest httpservletrequest) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.isRequestedSessionIdFromCookie");
- Object obj = null;
- if (useSSLId) {
- String s = getRequestedSessionIdFromSSL(httpservletrequest);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.isRequestedSessionIdFromCookie: SSL Id = "
- + s);
- if (s != null)
- return false;
- }
- if (mUsingCookies) {
- String s1 = getRequestedSessionIdFromCookie(httpservletrequest);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.isRequestedSessionIdFromCookie: Cookie Id = "
- + s1);
- if (s1 != null)
- return true;
- }
- return false;
- }
- public boolean isRequestedSessionIdFromUrl(
- HttpServletRequest httpservletrequest) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.isRequestedSessionIdFromUrl");
- Object obj = null;
- if (useSSLId) {
- String s = getRequestedSessionIdFromSSL(httpservletrequest);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.isRequestedSessionIdFromURL: SSL Id = "
- + s);
- if (s != null)
- return false;
- }
- if (mUsingCookies) {
- String s1 = getRequestedSessionIdFromCookie(httpservletrequest);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.isRequestedSessionIdFromURL: Cookie Id = "
- + s1);
- if (s1 != null)
- return false;
- }
- if (mUsingURL) {
- String s2 = getRequestedSessionIdFromURL(httpservletrequest);
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc,
- "SessionContext.isRequestedSessionIdFromURL: URL Id = "
- + s2);
- if (s2 != null)
- return true;
- }
- return false;
- }
- public boolean isRequestedSessionIdValid(
- HttpServletRequest httpservletrequest, HttpSession httpsession) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
- Tr.debug(tc, "SessionContext.isRequestedSessionIdValid");
- String s = getFullSessionId(httpservletrequest);
- if (s == null)
- return false;
- if (httpsession == null)
- return false;
- if (httpsession.isNew())
- return false;
- s = getSessionIDOnly(s);
- if (s.equals(httpsession.getId()))
- return true;
- List list = getAllRequestedSessionIdsFromCookies(httpservletrequest);
- if (list != null && list.size() > 1) {
- for (int i = 1; i < list.size(); i++) {
- String s2 = (String) list.get(i);
- if (s2 == null || s2.length() <= cacheIdLength)
- continue;
- String s1 = getSessionIDOnly(s2);
- if (s1.equals(httpsession.getId()))
- return true;
- }
- }
- return false;
- }
- public HttpSession sessionPreInvoke(HttpServletRequest httpservletrequest,
- HttpServletResponse httpservletresponse) {
- if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
- Tr.entry(tc, "SessionContext.sessionPreInvoke");
- if (debugSessionCrossover) {
- String s = ((IExtendedRequest) httpservletrequest)
- .getUpdatedSessionId();
- if (s == null)
- s = getFullSessionId(httpservletrequest);
- if (s != null) {
- String s1 = getSessionIDOnly(s);
- currentThreadSessionId.set(s1);
- } else {