1 package org.apache.continuum.web.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.slf4j.MDC;
25
26
27
28
29
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