|
22 | 22 | import java.io.File; |
23 | 23 | import java.io.IOException; |
24 | 24 | import java.security.PrivilegedActionException; |
| 25 | +import java.text.DateFormat; |
| 26 | +import java.text.SimpleDateFormat; |
25 | 27 | import java.util.ArrayList; |
26 | 28 | import java.util.Arrays; |
27 | 29 | import java.util.Collection; |
|
30 | 32 | import java.util.Locale; |
31 | 33 | import java.util.Map; |
32 | 34 | import java.util.Properties; |
| 35 | +import java.util.TimeZone; |
33 | 36 | import java.util.concurrent.ThreadFactory; |
34 | 37 | import java.util.concurrent.TimeUnit; |
35 | 38 | import java.util.concurrent.atomic.AtomicLong; |
|
67 | 70 | public class ElasticSearchAuditDestination extends AuditDestination { |
68 | 71 | private static final Logger LOG = LoggerFactory.getLogger(ElasticSearchAuditDestination.class); |
69 | 72 |
|
| 73 | + private static final ThreadLocal<DateFormat> DATE_FORMAT = ThreadLocal.withInitial(() -> { |
| 74 | + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); |
| 75 | + format.setTimeZone(TimeZone.getTimeZone("UTC")); |
| 76 | + return format; |
| 77 | + }); |
| 78 | + |
70 | 79 | public static final String CONFIG_URLS = "urls"; |
71 | 80 | public static final String CONFIG_PORT = "port"; |
72 | 81 | public static final String CONFIG_USER = "user"; |
@@ -339,7 +348,12 @@ Map<String, Object> toDoc(AuthzAuditEvent auditEvent) { |
339 | 348 | doc.put("resType", auditEvent.getResourceType()); |
340 | 349 | doc.put("reason", auditEvent.getResultReason()); |
341 | 350 | doc.put("action", auditEvent.getAction()); |
342 | | - doc.put("evtTime", auditEvent.getEventTime()); |
| 351 | + Date eventTime = auditEvent.getEventTime(); |
| 352 | + if (eventTime != null) { |
| 353 | + doc.put("evtTime", DATE_FORMAT.get().format(eventTime)); |
| 354 | + } else { |
| 355 | + doc.put("evtTime", null); |
| 356 | + } |
343 | 357 | doc.put("seq_num", auditEvent.getSeqNum()); |
344 | 358 | doc.put("event_count", auditEvent.getEventCount()); |
345 | 359 | doc.put("event_dur_ms", auditEvent.getEventDurationMS()); |
|
0 commit comments