View Javadoc

1   package org.apache.continuum.web.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  import org.slf4j.MDC;
25  
26  /**
27   * @author Jevica Arianne B. Zurbano
28   * @version $Id: AuditLog.java
29   * @since 17 apr 09
30   */
31  public class AuditLog
32  {
33      private Logger logger = LoggerFactory.getLogger( AuditLog.class.getName() );
34  
35      private String action;
36  
37      private String category;
38  
39      private String resource;
40  
41      private String currentUser;
42  
43      public AuditLog( String action )
44      {
45          this.action = action;
46      }
47  
48      public AuditLog( String resource, String action )
49      {
50          this.action = action;
51          this.resource = resource;
52      }
53  
54      public void setCurrentUser( String currentUser )
55      {
56          this.currentUser = currentUser;
57      }
58  
59      public String getCurrentUser()
60      {
61          return currentUser;
62      }
63  
64      public void setResource( String resource )
65      {
66          this.resource = resource;
67      }
68  
69      public String getResource()
70      {
71          return resource;
72      }
73  
74      public void setCategory( String category )
75      {
76          this.category = category;
77      }
78  
79      public String getCategory()
80      {
81          return category;
82      }
83  
84      public void setAction( String action )
85      {
86          this.action = action;
87      }
88  
89      public String getAction()
90      {
91          return action;
92      }
93  
94      public void log()
95      {
96          if ( currentUser != null )
97          {
98              MDC.put( "security.currentUser", currentUser );
99          }
100 
101         if ( resource != null )
102         {
103             if ( category != null )
104             {
105                 logger.info( category + " " + resource + " - " + action );
106             }
107             else
108             {
109                 logger.info( resource + " - " + action );
110             }
111         }
112     }
113 }
114