Merge pull request #1046 from mposolda/master
KEYCLOAK-1102 Used just one ResteasyClient in admin client
This commit is contained in:
commit
f732332281
2 changed files with 7 additions and 6 deletions
|
@ -20,9 +20,10 @@ public class Keycloak {
|
||||||
|
|
||||||
private Keycloak(String serverUrl, String realm, String username, String password, String clientId, String clientSecret){
|
private Keycloak(String serverUrl, String realm, String username, String password, String clientId, String clientSecret){
|
||||||
config = new Config(serverUrl, realm, username, password, clientId, clientSecret);
|
config = new Config(serverUrl, realm, username, password, clientId, clientSecret);
|
||||||
tokenManager = new TokenManager(config);
|
|
||||||
|
|
||||||
client = new ResteasyClientBuilder().build();
|
client = new ResteasyClientBuilder().build();
|
||||||
|
|
||||||
|
tokenManager = new TokenManager(config, client);
|
||||||
|
|
||||||
target = client.target(config.getServerUrl());
|
target = client.target(config.getServerUrl());
|
||||||
|
|
||||||
target.register(new BearerAuthFilter(tokenManager.getAccessTokenString()));
|
target.register(new BearerAuthFilter(tokenManager.getAccessTokenString()));
|
||||||
|
|
|
@ -18,10 +18,12 @@ public class TokenManager {
|
||||||
|
|
||||||
private AccessTokenResponse currentToken;
|
private AccessTokenResponse currentToken;
|
||||||
private Date expirationTime;
|
private Date expirationTime;
|
||||||
private Config config;
|
private final Config config;
|
||||||
|
private final ResteasyClient client;
|
||||||
|
|
||||||
public TokenManager(Config config){
|
public TokenManager(Config config, ResteasyClient client){
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAccessTokenString(){
|
public String getAccessTokenString(){
|
||||||
|
@ -38,7 +40,6 @@ public class TokenManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccessTokenResponse grantToken(){
|
public AccessTokenResponse grantToken(){
|
||||||
ResteasyClient client = new ResteasyClientBuilder().build();
|
|
||||||
ResteasyWebTarget target = client.target(config.getServerUrl());
|
ResteasyWebTarget target = client.target(config.getServerUrl());
|
||||||
|
|
||||||
Form form = new Form()
|
Form form = new Form()
|
||||||
|
@ -60,7 +61,6 @@ public class TokenManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccessTokenResponse refreshToken(){
|
public AccessTokenResponse refreshToken(){
|
||||||
ResteasyClient client = new ResteasyClientBuilder().build();
|
|
||||||
ResteasyWebTarget target = client.target(config.getServerUrl());
|
ResteasyWebTarget target = client.target(config.getServerUrl());
|
||||||
|
|
||||||
Form form = new Form()
|
Form form = new Form()
|
||||||
|
|
Loading…
Reference in a new issue