KEYCLOAK-5617 Intermittent ConcurrencyTest failures

This commit is contained in:
Marko Strukelj authored and Stian Thorgersen committed 2017-11-09 07:12:33 +01:00
1 parent 9243430b75
commit bf937452c6
1 file changed
+4 -6
@@ -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.
}