Merge pull request #1 from stroeder/prior-login

This commit is contained in:
Thore 2021-02-23 02:03:45 +01:00 committed by GitHub
commit 9ccd611ad2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<String, List<String>> userAttrs = user.getAttributes();
if (userAttrs.containsKey("last-login")) {
List<String> 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
}
}
}