diff --git a/integration/admin-client/src/main/java/org/keycloak/admin/client/token/TokenManager.java b/integration/admin-client/src/main/java/org/keycloak/admin/client/token/TokenManager.java index b434b108ea..5246c99fd4 100644 --- a/integration/admin-client/src/main/java/org/keycloak/admin/client/token/TokenManager.java +++ b/integration/admin-client/src/main/java/org/keycloak/admin/client/token/TokenManager.java @@ -92,7 +92,7 @@ public class TokenManager { return currentToken; } - public AccessTokenResponse refreshToken() { + public synchronized AccessTokenResponse refreshToken() { Form form = new Form().param(GRANT_TYPE, REFRESH_TOKEN) .param(REFRESH_TOKEN, currentToken.getRefreshToken()); @@ -103,10 +103,8 @@ public class TokenManager { try { int requestTime = Time.currentTime(); - synchronized (this) { - currentToken = tokenService.refreshToken(config.getRealm(), form.asMap()); - expirationTime = requestTime + currentToken.getExpiresIn(); - } + currentToken = tokenService.refreshToken(config.getRealm(), form.asMap()); + expirationTime = requestTime + currentToken.getExpiresIn(); return currentToken; } catch (BadRequestException e) { return grantToken(); @@ -126,7 +124,7 @@ public class TokenManager { * * @param token the token to invalidate (cannot be null). */ - public void invalidate(String token) { + public synchronized void invalidate(String token) { if (currentToken == null) { return; // There's nothing to invalidate. }