001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.servlet;
016    
017    import com.liferay.portal.kernel.cache.Lifecycle;
018    import com.liferay.portal.kernel.cache.ThreadLocalCacheManager;
019    import com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdHttpSession;
020    import com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdSplitterUtil;
021    
022    import javax.servlet.http.HttpSession;
023    import javax.servlet.http.HttpSessionEvent;
024    import javax.servlet.http.HttpSessionListener;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class PortalSessionListener implements HttpSessionListener {
030    
031            public void sessionCreated(HttpSessionEvent httpSessionEvent) {
032                    if (CompoundSessionIdSplitterUtil.hasSessionDelimiter()) {
033                            CompoundSessionIdHttpSession compoundSessionIdHttpSession =
034                                    new CompoundSessionIdHttpSession(
035                                            httpSessionEvent.getSession());
036    
037                            httpSessionEvent = new HttpSessionEvent(
038                                    compoundSessionIdHttpSession);
039                    }
040    
041                    new PortalSessionCreator(httpSessionEvent);
042    
043                    HttpSession session = httpSessionEvent.getSession();
044    
045                    session.setAttribute(
046                            PortalSessionActivationListener.class.getName(),
047                            PortalSessionActivationListener.getInstance());
048            }
049    
050            public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
051                    if (CompoundSessionIdSplitterUtil.hasSessionDelimiter()) {
052                            CompoundSessionIdHttpSession compoundSessionIdHttpSession =
053                                    new CompoundSessionIdHttpSession(
054                                            httpSessionEvent.getSession());
055    
056                            httpSessionEvent = new HttpSessionEvent(
057                                    compoundSessionIdHttpSession);
058                    }
059    
060                    new PortalSessionDestroyer(httpSessionEvent);
061    
062                    ThreadLocalCacheManager.clearAll(Lifecycle.SESSION);
063            }
064    
065    }