From 134c9b11c010d555c9e9a8403eb676f9f4aa3357 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 4 Apr 2016 08:29:58 +0200 Subject: [PATCH] KEYCLOAK-2608 Timestamp resolution of 1s for Event.time is inappropriate for use with tests --- common/src/main/java/org/keycloak/common/util/Time.java | 4 ++++ .../src/main/java/org/keycloak/events/EventBuilder.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/keycloak/common/util/Time.java b/common/src/main/java/org/keycloak/common/util/Time.java index c0f8864571..b05f338852 100644 --- a/common/src/main/java/org/keycloak/common/util/Time.java +++ b/common/src/main/java/org/keycloak/common/util/Time.java @@ -30,6 +30,10 @@ public class Time { return ((int) (System.currentTimeMillis() / 1000)) + offset; } + public static long currentTimeMillis() { + return System.currentTimeMillis() + (offset * 1000); + } + public static Date toDate(int time) { return new Date(((long) time ) * 1000); } diff --git a/server-spi/src/main/java/org/keycloak/events/EventBuilder.java b/server-spi/src/main/java/org/keycloak/events/EventBuilder.java index 0b06475cd1..c55feb5e8d 100755 --- a/server-spi/src/main/java/org/keycloak/events/EventBuilder.java +++ b/server-spi/src/main/java/org/keycloak/events/EventBuilder.java @@ -169,7 +169,7 @@ public class EventBuilder { } private void send() { - event.setTime(Time.toMillis(Time.currentTime())); + event.setTime(Time.currentTimeMillis()); if (store != null) { if (realm.getEnabledEventTypes() != null && !realm.getEnabledEventTypes().isEmpty() ? realm.getEnabledEventTypes().contains(event.getType().name()) : event.getType().isSaveByDefault()) {