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.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            @Override
037            public void init(FilterConfig filterConfig) {
038                    super.init(filterConfig);
039    
040                    if (CompoundSessionIdSplitterUtil.hasSessionDelimiter()) {
041                            _filterEnabled = true;
042                    }
043                    else {
044                            _filterEnabled = false;
045                    }
046            }
047    
048            @Override
049            public boolean isFilterEnabled() {
050                    return _filterEnabled;
051            }
052    
053            public HttpServletRequest getWrappedHttpServletRequest(
054                    HttpServletRequest request, HttpServletResponse response) {
055    
056                    return new CompoundSessionIdServletRequest(request);
057            }
058    
059            private static boolean _filterEnabled;
060    
061    }