001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }