|
51 | 51 | import java.io.File; |
52 | 52 | import java.io.IOException; |
53 | 53 | import java.security.PrivilegedActionException; |
| 54 | +import java.text.DateFormat; |
| 55 | +import java.text.SimpleDateFormat; |
54 | 56 | import java.util.ArrayList; |
55 | 57 | import java.util.Collection; |
56 | 58 | import java.util.Collections; |
|
59 | 61 | import java.util.Locale; |
60 | 62 | import java.util.Map; |
61 | 63 | import java.util.Properties; |
| 64 | +import java.util.TimeZone; |
62 | 65 | import java.util.concurrent.ThreadFactory; |
63 | 66 | import java.util.concurrent.TimeUnit; |
64 | 67 | import java.util.concurrent.atomic.AtomicLong; |
65 | 68 | import java.util.concurrent.atomic.AtomicReference; |
66 | 69 |
|
67 | 70 | public class ElasticSearchAuditDestination extends AuditDestination { |
68 | 71 | private static final Logger LOG = LoggerFactory.getLogger(ElasticSearchAuditDestination.class); |
| 72 | + private static final ThreadLocal<DateFormat> DATE_FORMAT = ThreadLocal.withInitial(() -> { |
| 73 | + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); |
| 74 | + format.setTimeZone(TimeZone.getTimeZone("UTC")); |
| 75 | + return format; |
| 76 | + }); |
69 | 77 |
|
70 | 78 | public static final String CONFIG_URLS = "urls"; |
71 | 79 | public static final String CONFIG_PORT = "port"; |
@@ -300,7 +308,12 @@ Map<String, Object> toDoc(AuthzAuditEvent auditEvent) { |
300 | 308 | doc.put("resType", auditEvent.getResourceType()); |
301 | 309 | doc.put("reason", auditEvent.getResultReason()); |
302 | 310 | doc.put("action", auditEvent.getAction()); |
303 | | - doc.put("evtTime", auditEvent.getEventTime()); |
| 311 | + Date eventTime = auditEvent.getEventTime(); |
| 312 | + if (eventTime != null) { |
| 313 | + doc.put("evtTime", DATE_FORMAT.get().format(eventTime)); |
| 314 | + } else { |
| 315 | + doc.put("evtTime", null); |
| 316 | + } |
304 | 317 | doc.put("seq_num", auditEvent.getSeqNum()); |
305 | 318 | doc.put("event_count", auditEvent.getEventCount()); |
306 | 319 | doc.put("event_dur_ms", auditEvent.getEventDurationMS()); |
|
0 commit comments