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(httpSessionEvent.getSession());
035    
036                            httpSessionEvent = new HttpSessionEvent(
037                                    compoundSessionIdHttpSession);
038                    }
039    
040                    new PortalSessionCreator(httpSessionEvent);
041    
042                    HttpSession session = httpSessionEvent.getSession();
043    
044                    session.setAttribute(
045                            PortalSessionActivationListener.class.getName(),
046                            PortalSessionActivationListener.getInstance());
047            }
048    
049            public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
050                    if (CompoundSessionIdSplitterUtil.hasSessionDelimiter()) {
051                            CompoundSessionIdHttpSession compoundSessionIdHttpSession =
052                                    new CompoundSessionIdHttpSession(httpSessionEvent.getSession());
053    
054                            httpSessionEvent = new HttpSessionEvent(
055                                    compoundSessionIdHttpSession);
056                    }
057    
058                    new PortalSessionDestroyer(httpSessionEvent);
059    
060                    ThreadLocalCacheManager.clearAll(Lifecycle.SESSION);
061            }
062    
063    }