1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.servlet.filters.audit;
16  
17  import com.liferay.portal.kernel.audit.AuditRequestThreadLocal;
18  import com.liferay.portal.kernel.util.WebKeys;
19  import com.liferay.portal.servlet.filters.BasePortalFilter;
20  
21  import javax.servlet.FilterChain;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  import javax.servlet.http.HttpSession;
25  
26  /**
27   * <a href="AuditFilter.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Michael C. Han
30   */
31  public class AuditFilter extends BasePortalFilter {
32  
33      protected void processFilter(
34              HttpServletRequest request, HttpServletResponse response,
35              FilterChain filterChain)
36          throws Exception {
37  
38          AuditRequestThreadLocal auditRequestThreadLocal =
39              AuditRequestThreadLocal.getAuditThreadLocal();
40  
41          auditRequestThreadLocal.setClientHost(request.getRemoteHost());
42          auditRequestThreadLocal.setClientIP(request.getRemoteAddr());
43          auditRequestThreadLocal.setQueryString(request.getQueryString());
44  
45          HttpSession session = request.getSession();
46  
47          Long userId = (Long)session.getAttribute(WebKeys.USER_ID);
48  
49          if (userId != null) {
50              auditRequestThreadLocal.setRealUserId(userId.longValue());
51          }
52  
53          auditRequestThreadLocal.setRequestURL(
54              request.getRequestURL().toString());
55          auditRequestThreadLocal.setServerName(request.getServerName());
56          auditRequestThreadLocal.setServerPort(request.getServerPort());
57          auditRequestThreadLocal.setSessionID(request.getSession().getId());
58  
59          processFilter(AuditFilter.class, request, response, filterChain);
60      }
61  
62  }