001
014
015 package com.liferay.portal.kernel.servlet;
016
017 import com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdHttpSession;
018 import com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdSplitterUtil;
019
020 import java.util.ArrayList;
021 import java.util.List;
022
023 import javax.servlet.http.HttpSessionEvent;
024 import javax.servlet.http.HttpSessionListener;
025
026
034 public class PortletSessionListenerManager implements HttpSessionListener {
035
036 public static void addHttpSessionListener(
037 HttpSessionListener httpSessionListener) {
038
039 _httpSessionListeners.add(httpSessionListener);
040 }
041
042 public static void removeHttpSessionListener(
043 HttpSessionListener httpSessionListener) {
044
045 _httpSessionListeners.remove(httpSessionListener);
046 }
047
048 @Override
049 public void sessionCreated(HttpSessionEvent httpSessionEvent) {
050 httpSessionEvent = getHttpSessionEvent(httpSessionEvent);
051
052 Thread currentThread = Thread.currentThread();
053
054 ClassLoader contextClassLoader = currentThread.getContextClassLoader();
055
056 try {
057 for (HttpSessionListener httpSessionListener :
058 _httpSessionListeners) {
059
060 Class<?> clazz = httpSessionListener.getClass();
061
062 ClassLoader classLoader = clazz.getClassLoader();
063
064 currentThread.setContextClassLoader(classLoader);
065
066 httpSessionListener.sessionCreated(httpSessionEvent);
067 }
068 }
069 finally {
070 currentThread.setContextClassLoader(contextClassLoader);
071 }
072 }
073
074 @Override
075 public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
076 httpSessionEvent = getHttpSessionEvent(httpSessionEvent);
077
078 for (HttpSessionListener httpSessionListener : _httpSessionListeners) {
079 httpSessionListener.sessionDestroyed(httpSessionEvent);
080 }
081 }
082
083 protected HttpSessionEvent getHttpSessionEvent(
084 HttpSessionEvent httpSessionEvent) {
085
086 if (CompoundSessionIdSplitterUtil.hasSessionDelimiter()) {
087 CompoundSessionIdHttpSession compoundSessionIdHttpSession =
088 new CompoundSessionIdHttpSession(httpSessionEvent.getSession());
089
090 httpSessionEvent = new HttpSessionEvent(
091 compoundSessionIdHttpSession);
092 }
093
094 return httpSessionEvent;
095 }
096
097 private static List<HttpSessionListener> _httpSessionListeners =
098 new ArrayList<HttpSessionListener>();
099
100 }