From 1095e77006da8ecf43f45b165c023be2b91157f6 Mon Sep 17 00:00:00 2001 From: Thore Date: Tue, 10 Jan 2023 03:25:50 +0100 Subject: [PATCH] Upgrade dependencies to keycloak 20.0.2 --- .github/workflows/gradle.yaml | 6 +-- build.gradle | 6 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../LastLoginEventListenerProvider.java | 40 ++++++++++--------- .../META-INF/jboss-deployment-structure.xml | 12 ------ 5 files changed, 28 insertions(+), 38 deletions(-) delete mode 100644 src/main/resources/META-INF/jboss-deployment-structure.xml diff --git a/.github/workflows/gradle.yaml b/.github/workflows/gradle.yaml index 723c96c..f6c6b3f 100644 --- a/.github/workflows/gradle.yaml +++ b/.github/workflows/gradle.yaml @@ -8,10 +8,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v3 with: - java-version: 11 + java-version: 17 distribution: temurin - uses: gradle/wrapper-validation-action@v1 diff --git a/build.gradle b/build.gradle index 4f50d2e..3408789 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ version = '0.0.1-SNAPSHOT' description = 'last-login-event-listener' ext { - keycloakVersion = "17.0.0" + keycloakVersion = "20.0.2" } @@ -35,10 +35,10 @@ dependencies { java { toolchain { - languageVersion = JavaLanguageVersion.of(11) + languageVersion = JavaLanguageVersion.of(17) } } -tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e589..070cb70 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists 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 6457d6f..80c9f00 100644 --- a/src/main/java/de/scimeda/keycloak/events/logging/LastLoginEventListenerProvider.java +++ b/src/main/java/de/scimeda/keycloak/events/logging/LastLoginEventListenerProvider.java @@ -10,11 +10,11 @@ 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.OffsetDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Map; public class LastLoginEventListenerProvider implements EventListenerProvider { @@ -31,27 +31,29 @@ public class LastLoginEventListenerProvider implements EventListenerProvider { @Override public void onEvent(Event event) { // log.infof("## NEW %s EVENT", event.getType()); - if (EventType.LOGIN.equals(event.getType())) { - RealmModel realm = this.model.getRealm(event.getRealmId()); - UserModel user = this.session.users().getUserById(realm, event.getUserId()); + if (!EventType.LOGIN.equals(event.getType())) { + return; + } + RealmModel realm = this.model.getRealm(event.getRealmId()); + UserModel user = this.session.users().getUserById(realm, event.getUserId()); - if (user != null) { - log.info("Updating last login status for user: " + event.getUserId()); + if (user == null) { + return; + } + 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 - OffsetDateTime loginTime = OffsetDateTime.now(ZoneOffset.UTC); - String loginTimeS = DateTimeFormatter.ISO_DATE_TIME.format(loginTime); - user.setSingleAttribute("last-login", loginTimeS); + 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 + OffsetDateTime loginTime = OffsetDateTime.now(ZoneOffset.UTC); + String loginTimeS = DateTimeFormatter.ISO_DATE_TIME.format(loginTime); + user.setSingleAttribute("last-login", loginTimeS); } @Override diff --git a/src/main/resources/META-INF/jboss-deployment-structure.xml b/src/main/resources/META-INF/jboss-deployment-structure.xml deleted file mode 100644 index b3bf009..0000000 --- a/src/main/resources/META-INF/jboss-deployment-structure.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - -