Force refreshing token for admin client if time offset is set (#16242)

Closes #16143
This commit is contained in:
Stian Thorgersen 2023-01-04 13:03:10 +01:00 committed by GitHub
parent af3ba49393
commit 7dc16c69cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View file

@ -238,16 +238,11 @@ public class TestingResourceProvider implements RealmResourceProvider {
public Map<String, String> setTimeOffset(Map<String, String> time) { public Map<String, String> setTimeOffset(Map<String, String> time) {
int offset = Integer.parseInt(time.get("offset")); int offset = Integer.parseInt(time.get("offset"));
if (offset > 60) {
suspendTask(ClearExpiredUserSessions.TASK_NAME);
}
Time.setOffset(offset); Time.setOffset(offset);
// Time offset was restarted // Time offset was restarted
if (offset == 0) { if (offset == 0) {
session.getKeycloakSessionFactory().publish(new ResetTimeOffsetEvent()); session.getKeycloakSessionFactory().publish(new ResetTimeOffsetEvent());
restorePeriodicTasks();
} }
return getTimeOffset(); return getTimeOffset();

View file

@ -674,6 +674,14 @@ public abstract class AbstractKeycloakTest {
// adminClient depends on Time.offset for auto-refreshing tokens // adminClient depends on Time.offset for auto-refreshing tokens
Time.setOffset(offset); Time.setOffset(offset);
Map result = testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(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); return String.valueOf(result);
} }