From 7dc16c69cb2b2bad4aa33660d1de8a1611433551 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Wed, 4 Jan 2023 13:03:10 +0100 Subject: [PATCH] Force refreshing token for admin client if time offset is set (#16242) Closes #16143 --- .../keycloak/testsuite/rest/TestingResourceProvider.java | 5 ----- .../java/org/keycloak/testsuite/AbstractKeycloakTest.java | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/rest/TestingResourceProvider.java b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/rest/TestingResourceProvider.java index cf05f54e76..762893a23f 100644 --- a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/rest/TestingResourceProvider.java +++ b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/rest/TestingResourceProvider.java @@ -238,16 +238,11 @@ public class TestingResourceProvider implements RealmResourceProvider { public Map setTimeOffset(Map time) { int offset = Integer.parseInt(time.get("offset")); - if (offset > 60) { - suspendTask(ClearExpiredUserSessions.TASK_NAME); - } - Time.setOffset(offset); // Time offset was restarted if (offset == 0) { session.getKeycloakSessionFactory().publish(new ResetTimeOffsetEvent()); - restorePeriodicTasks(); } return getTimeOffset(); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java index b8eff6e2b5..c5fe4e06b2 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java @@ -674,6 +674,14 @@ public abstract class AbstractKeycloakTest { // adminClient depends on Time.offset for auto-refreshing tokens Time.setOffset(offset); Map result = testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(offset))); + + // force refreshing token after time offset has changed + try { + adminClient.tokenManager().refreshToken(); + } catch (RuntimeException e) { + adminClient.tokenManager().grantToken(); + } + return String.valueOf(result); }