001    /**
002     * Copyright (c) 2000-2012 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.filters.compoundsessionid;
016    
017    import com.liferay.portal.kernel.servlet.WrapHttpServletRequestFilter;
018    import com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdServletRequest;
019    import com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdSplitterUtil;
020    import com.liferay.portal.servlet.filters.BasePortalFilter;
021    
022    import javax.servlet.FilterConfig;
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.http.HttpServletResponse;
025    
026    /**
027     * <p>
028     * See http://issues.liferay.com/browse/LPS-18587.
029     * </p>
030     *
031     * @author Michael C. Han
032     */
033    public class CompoundSessionIdFilter
034            extends BasePortalFilter implements WrapHttpServletRequestFilter {
035    
036            public HttpServletRequest getWrappedHttpServletRequest(
037                    HttpServletRequest request, HttpServletResponse response) {
038    
039                    return new CompoundSessionIdServletRequest(request);
040            }
041    
042            @Override
043            public void init(FilterConfig filterConfig) {
044                    super.init(filterConfig);
045    
046                    if (CompoundSessionIdSplitterUtil.hasSessionDelimiter()) {
047                            _filterEnabled = true;
048                    }
049                    else {
050                            _filterEnabled = false;
051                    }
052            }
053    
054            @Override
055            public boolean isFilterEnabled() {
056                    return _filterEnabled;
057            }
058    
059            private static boolean _filterEnabled;
060    
061    }