1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.audit.impl; |
18 |
|
|
19 |
|
import java.sql.Connection; |
20 |
|
import java.sql.PreparedStatement; |
21 |
|
import java.sql.SQLException; |
22 |
|
import java.sql.Timestamp; |
23 |
|
|
24 |
|
import javax.sql.DataSource; |
25 |
|
|
26 |
|
import org.apache.commons.logging.Log; |
27 |
|
import org.apache.commons.logging.LogFactory; |
28 |
|
import org.apache.jetspeed.audit.AuditActivity; |
29 |
|
import org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
public class AuditActivityImpl extends PersistenceBrokerDaoSupport implements AuditActivity |
40 |
|
{ |
41 |
0 |
protected final static Log log = LogFactory.getLog(AuditActivityImpl.class); |
42 |
|
|
43 |
|
protected DataSource ds; |
44 |
0 |
protected String anonymousUser = "guest"; |
45 |
0 |
protected boolean enabled = true; |
46 |
|
|
47 |
|
public AuditActivityImpl(DataSource dataSource) |
48 |
0 |
{ |
49 |
0 |
this.ds = dataSource; |
50 |
0 |
} |
51 |
|
|
52 |
|
public void setEnabled(boolean enabled) |
53 |
|
{ |
54 |
0 |
this.enabled = enabled; |
55 |
0 |
} |
56 |
|
|
57 |
|
public boolean getEnabled() |
58 |
|
{ |
59 |
0 |
return this.enabled; |
60 |
|
} |
61 |
|
|
62 |
|
public DataSource getDataSource() |
63 |
|
{ |
64 |
0 |
return ds; |
65 |
|
} |
66 |
|
|
67 |
|
public void logAdminAttributeActivity(String adminName, String ipAddress, String targetUser, String activity, String name, String beforeValue, String afterValue, String description) |
68 |
|
{ |
69 |
0 |
if (enabled) |
70 |
|
{ |
71 |
0 |
logAdminActivity(adminName, ipAddress, targetUser, activity, description, AuditActivity.CAT_ADMIN_ATTRIBUTE_MAINTENANCE, name, beforeValue, afterValue); |
72 |
|
} |
73 |
0 |
} |
74 |
|
|
75 |
|
public void logAdminCredentialActivity(String adminName, String ipAddress, String targetUser, String activity, String description) |
76 |
|
{ |
77 |
0 |
if (enabled) |
78 |
|
{ |
79 |
0 |
logAdminActivity(adminName, ipAddress, targetUser, activity, description, AuditActivity.CAT_ADMIN_CREDENTIAL_MAINTENANCE, "", "", ""); |
80 |
|
} |
81 |
0 |
} |
82 |
|
|
83 |
|
public void logAdminAuthorizationActivity(String adminName, String ipAddress, String targetUser, String activity, String value, String description) |
84 |
|
{ |
85 |
0 |
if (enabled) |
86 |
|
{ |
87 |
0 |
logAdminActivity(adminName, ipAddress, targetUser, activity, description, AuditActivity.CAT_ADMIN_AUTHORIZATION_MAINTENANCE, "", value, ""); |
88 |
|
} |
89 |
0 |
} |
90 |
|
|
91 |
|
public void logAdminUserActivity(String adminName, String ipAddress, String targetUser, String activity, String description) |
92 |
|
{ |
93 |
0 |
if (enabled) |
94 |
|
{ |
95 |
0 |
logAdminActivity(adminName, ipAddress, targetUser, activity, description, AuditActivity.CAT_ADMIN_USER_MAINTENANCE, "", "", ""); |
96 |
|
} |
97 |
0 |
} |
98 |
|
|
99 |
|
protected void logAdminActivity(String adminName, String ipAddress, String targetUser, String activity, String description, String category, String name, String beforeValue, String afterValue) |
100 |
|
{ |
101 |
0 |
Connection con = null; |
102 |
0 |
PreparedStatement stm = null; |
103 |
|
try |
104 |
|
{ |
105 |
0 |
Timestamp timestamp = new Timestamp(System.currentTimeMillis()); |
106 |
0 |
con = ds.getConnection(); |
107 |
0 |
stm = con.prepareStatement("INSERT INTO ADMIN_ACTIVITY (ACTIVITY, CATEGORY, ADMIN, USER_NAME, TIME_STAMP, IPADDRESS, ATTR_NAME, ATTR_VALUE_BEFORE, ATTR_VALUE_AFTER, DESCRIPTION) VALUES(?,?,?,?,?,?,?,?,?,?)"); |
108 |
0 |
stm.setString(1, activity); |
109 |
0 |
stm.setString(2, category); |
110 |
0 |
stm.setString(3, adminName); |
111 |
0 |
stm.setString(4, targetUser); |
112 |
0 |
stm.setTimestamp(5, timestamp); |
113 |
0 |
stm.setString(6, ipAddress); |
114 |
0 |
stm.setString(7, name); |
115 |
0 |
stm.setString(8, beforeValue); |
116 |
0 |
stm.setString(9, afterValue); |
117 |
0 |
stm.setString(10, description); |
118 |
0 |
stm.execute(); |
119 |
|
} |
120 |
0 |
catch (SQLException e) |
121 |
|
{ |
122 |
0 |
log.error(e); |
123 |
|
} |
124 |
|
finally |
125 |
|
{ |
126 |
0 |
try |
127 |
|
{ |
128 |
0 |
if (stm != null) stm.close(); |
129 |
|
} |
130 |
0 |
catch (SQLException se) |
131 |
0 |
{} |
132 |
0 |
releaseConnection(con); |
133 |
0 |
} |
134 |
0 |
} |
135 |
|
|
136 |
|
public void logUserActivity(String userName, String ipAddress, String activity, String description) |
137 |
|
{ |
138 |
0 |
logUserActivities(userName, ipAddress, activity, "", "", "", description, AuditActivity.CAT_USER_AUTHENTICATION); |
139 |
0 |
} |
140 |
|
|
141 |
|
public void logUserAttributeActivity(String userName, String ipAddress, String activity, String name, String beforeValue, String afterValue, String description) |
142 |
|
{ |
143 |
0 |
logUserActivities(userName, ipAddress, activity, name, beforeValue, afterValue, description, AuditActivity.CAT_USER_ATTRIBUTE); |
144 |
0 |
} |
145 |
|
|
146 |
|
protected void logUserActivities(String userName, String ipAddress, String activity, String name, String beforeValue, String afterValue, String description, String category) |
147 |
|
{ |
148 |
0 |
if (enabled) |
149 |
|
{ |
150 |
0 |
Connection con = null; |
151 |
0 |
PreparedStatement stm = null; |
152 |
|
try |
153 |
|
{ |
154 |
0 |
Timestamp timestamp = new Timestamp(System.currentTimeMillis()); |
155 |
0 |
con = ds.getConnection(); |
156 |
0 |
stm = con.prepareStatement("INSERT INTO USER_ACTIVITY (ACTIVITY, CATEGORY, USER_NAME, TIME_STAMP, IPADDRESS, ATTR_NAME, ATTR_VALUE_BEFORE, ATTR_VALUE_AFTER, DESCRIPTION) VALUES(?,?,?,?,?,?,?,?,?)"); |
157 |
0 |
stm.setString(1, activity); |
158 |
0 |
stm.setString(2, category); |
159 |
0 |
stm.setString(3, userName); |
160 |
0 |
stm.setTimestamp(4, timestamp); |
161 |
0 |
stm.setString(5, ipAddress); |
162 |
0 |
stm.setString(6, name); |
163 |
0 |
stm.setString(7, beforeValue); |
164 |
0 |
stm.setString(8, afterValue); |
165 |
0 |
stm.setString(9, description); |
166 |
0 |
stm.executeUpdate(); |
167 |
|
} |
168 |
0 |
catch (SQLException e) |
169 |
|
{ |
170 |
|
|
171 |
0 |
e.printStackTrace(); |
172 |
|
} |
173 |
|
finally |
174 |
|
{ |
175 |
0 |
try |
176 |
|
{ |
177 |
0 |
if (stm != null) stm.close(); |
178 |
|
} |
179 |
0 |
catch (SQLException se) |
180 |
0 |
{} |
181 |
0 |
releaseConnection(con); |
182 |
0 |
} |
183 |
|
} |
184 |
0 |
} |
185 |
|
|
186 |
|
void releaseConnection(Connection con) |
187 |
|
{ |
188 |
|
try |
189 |
|
{ |
190 |
0 |
if (con != null) con.close(); |
191 |
0 |
} catch (SQLException e) |
192 |
|
{ |
193 |
0 |
} |
194 |
0 |
} |
195 |
|
} |