| SessionIdFilter.java |
1 /**
2 * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portal.servlet.filters.sessionid;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.util.SystemProperties;
27
28 import java.io.IOException;
29
30 import javax.servlet.Filter;
31 import javax.servlet.FilterChain;
32 import javax.servlet.FilterConfig;
33 import javax.servlet.ServletException;
34 import javax.servlet.ServletRequest;
35 import javax.servlet.ServletResponse;
36 import javax.servlet.http.HttpServletRequest;
37 import javax.servlet.http.HttpServletResponse;
38
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41
42 /**
43 * <a href="SessionIdFilter.java.html"><b><i>View Source</i></b></a>
44 *
45 * <p>
46 * http://forum.java.sun.com/thread.jspa?threadID=197150.
47 * </p>
48 *
49 * @author Brian Wing Shun Chan
50 *
51 */
52 public class SessionIdFilter implements Filter {
53
54 public static final boolean USE_FILTER = GetterUtil.getBoolean(
55 SystemProperties.get(SessionIdFilter.class.getName()), true);
56
57 public void init(FilterConfig config) throws ServletException {
58 }
59
60 public void doFilter(
61 ServletRequest req, ServletResponse res, FilterChain chain)
62 throws IOException, ServletException {
63
64 if (_log.isDebugEnabled()) {
65 if (USE_FILTER) {
66 _log.debug(
67 "Session id sharing between http and https is enabled");
68 }
69 else {
70 _log.debug(
71 "Session id sharing between http and https is disabled");
72 }
73 }
74
75 if (USE_FILTER) {
76 HttpServletRequest httpReq = (HttpServletRequest)req;
77 HttpServletResponse httpRes = (HttpServletResponse)res;
78
79 SessionIdServletRequest sessionIdReq =
80 new SessionIdServletRequest(httpReq, httpRes);
81
82 chain.doFilter(sessionIdReq, httpRes);
83 }
84 else {
85 chain.doFilter(req, res);
86 }
87 }
88
89 public void destroy() {
90 }
91
92 private static Log _log = LogFactory.getLog(SessionIdFilter.class);
93
94 }