Force refreshing token for admin client if time offset is set (#16242)
Closes #16143
This commit is contained in:
parent
af3ba49393
commit
7dc16c69cb
2 changed files with 8 additions and 5 deletions
|
@ -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();
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue