KEYCLOAK-5617 Intermittent ConcurrencyTest failures

This commit is contained in:
Marko Strukelj 2017-11-08 11:07:07 +01:00 committed by Stian Thorgersen
parent 9243430b75
commit bf937452c6

View file

@ -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.
}