diff --git a/src/main/java/de/scimeda/keycloak/events/logging/LastLoginEventListenerProvider.java b/src/main/java/de/scimeda/keycloak/events/logging/LastLoginEventListenerProvider.java index 933f3c5..2854230 100644 --- a/src/main/java/de/scimeda/keycloak/events/logging/LastLoginEventListenerProvider.java +++ b/src/main/java/de/scimeda/keycloak/events/logging/LastLoginEventListenerProvider.java @@ -10,6 +10,7 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.RealmProvider; import org.keycloak.models.UserModel; +import java.util.Map; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -35,6 +36,12 @@ public class LastLoginEventListenerProvider implements EventListenerProvider { if (user != null) { log.info("Updating last login status for user: " + event.getUserId()); + Map userAttrs = user.getAttributes(); + if (userAttrs.containsKey("last-login")) { + String userLastLogin = userAttrs.get("last-login").toString(); + user.setSingleAttribute("prior-login", userLastLogin.substring(1, userLastLogin.length()-1)); + } + // Use current server time for login event LocalDateTime loginTime = LocalDateTime.now(); String loginTimeS = DateTimeFormatter.ISO_DATE_TIME.format(loginTime);