Merge pull request #1 from stroeder/prior-login
This commit is contained in:
commit
9ccd611ad2
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue