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 02056a7e2c..3d4f7079ab 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 @@ -18,7 +18,6 @@ package org.keycloak.admin.client.token; import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.keycloak.admin.client.Config; import org.keycloak.admin.client.resource.BasicAuthFilter; @@ -27,8 +26,6 @@ import org.keycloak.representations.AccessTokenResponse; import javax.ws.rs.BadRequestException; import javax.ws.rs.core.Form; -import java.util.Calendar; -import java.util.Date; /** * @author rodrigo.sasaki@icarros.com.br @@ -41,11 +38,15 @@ public class TokenManager { private long expirationTime; private long minTokenValidity = DEFAULT_MIN_VALIDITY; private final Config config; - private final ResteasyClient client; + private final TokenService tokenService; public TokenManager(Config config, ResteasyClient client){ this.config = config; - this.client = client; + ResteasyWebTarget target = client.target(config.getServerUrl()); + if(!config.isPublicClient()){ + target.register(new BasicAuthFilter(config.getClientId(), config.getClientSecret())); + } + tokenService = target.proxy(TokenService.class); } public String getAccessTokenString(){ @@ -62,8 +63,6 @@ public class TokenManager { } public AccessTokenResponse grantToken(){ - ResteasyWebTarget target = client.target(config.getServerUrl()); - Form form = new Form() .param("grant_type", "password") .param("username", config.getUsername()) @@ -71,12 +70,8 @@ public class TokenManager { if(config.isPublicClient()){ form.param("client_id", config.getClientId()); - } else { - target.register(new BasicAuthFilter(config.getClientId(), config.getClientSecret())); } - TokenService tokenService = target.proxy(TokenService.class); - int requestTime = Time.currentTime(); currentToken = tokenService.grantToken(config.getRealm(), form.asMap()); expirationTime = requestTime + currentToken.getExpiresIn(); @@ -85,20 +80,14 @@ public class TokenManager { } public AccessTokenResponse refreshToken(){ - ResteasyWebTarget target = client.target(config.getServerUrl()); - Form form = new Form() .param("grant_type", "refresh_token") .param("refresh_token", currentToken.getRefreshToken()); if(config.isPublicClient()){ form.param("client_id", config.getClientId()); - } else { - target.register(new BasicAuthFilter(config.getClientId(), config.getClientSecret())); } - TokenService tokenService = target.proxy(TokenService.class); - try { int requestTime = Time.currentTime(); currentToken = tokenService.refreshToken(config.getRealm(), form.asMap());