1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.forgerock.audit.handlers.jdbc;
17
18 import java.sql.PreparedStatement;
19 import java.util.Collections;
20 import java.util.LinkedList;
21 import java.util.List;
22
23 import org.forgerock.audit.events.handlers.EventHandlerConfiguration;
24 import org.forgerock.util.Reject;
25
26 import com.fasterxml.jackson.annotation.JsonProperty;
27 import com.fasterxml.jackson.annotation.JsonPropertyDescription;
28
29
30
31
32 public class JdbcAuditEventHandlerConfiguration extends EventHandlerConfiguration {
33
34 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool")
35 private ConnectionPool connectionPool = new ConnectionPool();
36
37 @JsonProperty(required = true)
38 @JsonPropertyDescription("audit.handlers.jdbc.tableMappings")
39 private List<TableMapping> tableMappings = new LinkedList<>();
40
41 @JsonProperty(required = true)
42 @JsonPropertyDescription("audit.handlers.jdbc.databaseType")
43 private String databaseType;
44
45 @JsonPropertyDescription("audit.handlers.jdbc.buffering")
46 private EventBufferingConfiguration buffering = new EventBufferingConfiguration();
47
48
49
50
51
52 public List<TableMapping> getTableMappings() {
53 if (tableMappings == null) {
54 return Collections.emptyList();
55 }
56 return Collections.unmodifiableList(tableMappings);
57 }
58
59
60
61
62
63 public void setTableMappings(List<TableMapping> tableMappings) {
64 this.tableMappings = tableMappings;
65 }
66
67
68
69
70
71 public ConnectionPool getConnectionPool() {
72 return connectionPool;
73 }
74
75
76
77
78
79 public void setConnectionPool(ConnectionPool connectionPool) {
80 this.connectionPool = connectionPool;
81 }
82
83
84
85
86
87 public String getDatabaseType() {
88 return databaseType;
89 }
90
91
92
93
94
95 public void setDatabaseType(String databaseType) {
96 this.databaseType = databaseType;
97 }
98
99 @Override
100 public boolean isUsableForQueries() {
101 return true;
102 }
103
104
105
106
107 public static class ConnectionPool {
108 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.dataSourceClassName")
109 private String dataSourceClassName;
110
111 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.jdbcUrl")
112 private String jdbcUrl;
113
114 @JsonProperty(required = true)
115 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.username")
116 private String username;
117
118 @JsonProperty(required = true)
119 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.password")
120 private String password;
121
122 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.autoCommit")
123 private boolean autoCommit = true;
124
125 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.connectionTimeout")
126 private int connectionTimeout = 30000;
127
128 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.idleTimeout")
129 private int idleTimeout = 600000;
130
131 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.maxLifetime")
132 private int maxLifetime = 1800000;
133
134 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.minIdle")
135 private int minIdle = 10;
136
137 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.maxPoolSize")
138 private int maxPoolSize = 10;
139
140 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.poolName")
141 private String poolName;
142
143 @JsonPropertyDescription("audit.handlers.jdbc.connectionPool.driverClassName")
144 private String driverClassName;
145
146
147
148
149
150 public String getDriverClassName() {
151 return driverClassName;
152 }
153
154
155
156
157
158 public void setDriverClassName(String driverClassName) {
159 this.driverClassName = driverClassName;
160 }
161
162
163
164
165
166 public String getDataSourceClassName() {
167 return dataSourceClassName;
168 }
169
170
171
172
173
174 public void setDataSourceClassName(final String driverClass) {
175 this.dataSourceClassName = driverClass;
176 }
177
178
179
180
181
182 public String getJdbcUrl() {
183 return jdbcUrl;
184 }
185
186
187
188
189
190 public void setJdbcUrl(final String jdbcUrl) {
191 this.jdbcUrl = jdbcUrl;
192 }
193
194
195
196
197
198 public String getUsername() {
199 return username;
200 }
201
202
203
204
205
206 public void setUsername(final String username) {
207 this.username = username;
208 }
209
210
211
212
213
214 public String getPassword() {
215 return password;
216 }
217
218
219
220
221
222 public void setPassword(final String password) {
223 this.password = password;
224 }
225
226
227
228
229
230 public String getPoolName() {
231 return poolName;
232 }
233
234
235
236
237
238 public void setPoolName(String poolName) {
239 this.poolName = poolName;
240 }
241
242
243
244
245
246 public int getMaxPoolSize() {
247 return maxPoolSize;
248 }
249
250
251
252
253
254 public void setMaxPoolSize(int maxPoolSize) {
255 this.maxPoolSize = maxPoolSize;
256 }
257
258
259
260
261
262 public int getMinIdle() {
263 return minIdle;
264 }
265
266
267
268
269
270 public void setMinIdle(int minIdle) {
271 this.minIdle = minIdle;
272 }
273
274
275
276
277
278 public int getMaxLifetime() {
279 return maxLifetime;
280 }
281
282
283
284
285
286 public void setMaxLifetime(int maxLifetime) {
287 this.maxLifetime = maxLifetime;
288 }
289
290
291
292
293
294 public int getIdleTimeout() {
295 return idleTimeout;
296 }
297
298
299
300
301
302 public void setIdleTimeout(int idleTimeout) {
303 this.idleTimeout = idleTimeout;
304 }
305
306
307
308
309
310 public int getConnectionTimeout() {
311 return connectionTimeout;
312 }
313
314
315
316
317
318 public void setConnectionTimeout(int connectionTimeout) {
319 this.connectionTimeout = connectionTimeout;
320 }
321
322
323
324
325
326 public boolean getAutoCommit() {
327 return autoCommit;
328 }
329
330
331
332
333
334 public void setAutoCommit(boolean autoCommit) {
335 this.autoCommit = autoCommit;
336 }
337 }
338
339
340
341
342
343
344 public EventBufferingConfiguration getBuffering() {
345 return buffering;
346 }
347
348
349
350
351
352
353
354 public void setBufferingConfiguration(EventBufferingConfiguration bufferingConfiguration) {
355 this.buffering = bufferingConfiguration;
356 }
357
358
359
360
361 public static class EventBufferingConfiguration {
362
363 @JsonPropertyDescription("audit.handlers.jdbc.buffering.enabled")
364 private boolean enabled = false;
365
366 @JsonPropertyDescription("audit.handlers.jdbc.buffering.autoFlush")
367 private boolean autoFlush = true;
368
369 @JsonPropertyDescription("audit.handlers.jdbc.buffering.maxSize")
370 private int maxSize = 5000;
371
372 @JsonPropertyDescription("audit.handlers.jdbc.buffering.interval")
373 private String writeInterval = "disabled";
374
375 @JsonPropertyDescription("audit.handlers.jdbc.buffering.writerThreads")
376 private int writerThreads = 1;
377
378 @JsonPropertyDescription("audit.handlers.jdbc.buffering.maxBatchedEvents")
379 private int maxBatchedEvents = 100;
380
381
382
383
384
385
386
387 public boolean isEnabled() {
388 return enabled;
389 }
390
391
392
393
394
395
396
397 public void setEnabled(boolean enabled) {
398 this.enabled = enabled;
399 }
400
401
402
403
404
405
406 public boolean isAutoFlush() {
407 return autoFlush;
408 }
409
410
411
412
413
414
415
416 public void setAutoFlush(boolean auto) {
417 this.autoFlush = auto;
418 }
419
420
421
422
423
424
425 public int getMaxSize() {
426 return maxSize;
427 }
428
429
430
431
432
433
434
435 public void setMaxSize(int maxSize) {
436 Reject.ifFalse(maxSize >= 1);
437 this.maxSize = maxSize;
438 }
439
440
441
442
443
444 public String getWriteInterval() {
445 return writeInterval;
446 }
447
448
449
450
451
452 public void setWriteInterval(String writeInterval) {
453 this.writeInterval = writeInterval;
454 }
455
456
457
458
459
460 public int getWriterThreads() {
461 return writerThreads;
462 }
463
464
465
466
467
468 public void setWriterThreads(int writerThreads) {
469 Reject.ifFalse(writerThreads >= 1);
470 this.writerThreads = writerThreads;
471 }
472
473
474
475
476
477 public int getMaxBatchedEvents() {
478 return maxBatchedEvents;
479 }
480
481
482
483
484
485 public void setMaxBatchedEvents(int maxBatchedEvents) {
486 this.maxBatchedEvents = maxBatchedEvents;
487 }
488 }
489 }