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..5b6bf5a 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,8 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.RealmProvider; import org.keycloak.models.UserModel; +import java.util.List; +import java.util.Map; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -35,6 +37,14 @@ 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")) { + List userLastLogin = userAttrs.get("last-login"); + if (userLastLogin != null && !userLastLogin.isEmpty()) { + user.setSingleAttribute("prior-login", userLastLogin.get(0); + } + } + // Use current server time for login event LocalDateTime loginTime = LocalDateTime.now(); String loginTimeS = DateTimeFormatter.ISO_DATE_TIME.format(loginTime); @@ -52,4 +62,4 @@ public class LastLoginEventListenerProvider implements EventListenerProvider { // Nothing to close } -} \ No newline at end of file +}