secret updated

This commit is contained in:
Lucio Lelii 2022-06-10 17:33:29 +02:00
parent 3ae9e81780
commit cf6981a284
3 changed files with 9 additions and 6 deletions

View File

@ -1,5 +1,7 @@
package org.gcube.common.security.renewal;
import java.net.URL;
import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.model.TokenResponse;
import org.gcube.common.security.secrets.JWTSecret;
@ -12,14 +14,16 @@ public class ClientIDManager implements RenewalProvider {
protected final String clientID;
protected final String clientSecret;
protected final URL endpoint;
public ClientIDManager(String clientID, String clientSecret) {
public ClientIDManager(String clientID, String clientSecret, URL endpoint) {
this.clientID = clientID;
this.clientSecret = clientSecret;
this.endpoint = endpoint;
}
public Secret getSecret() throws Exception {
TokenResponse tokenResponse = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, null);
TokenResponse tokenResponse = KeycloakClientFactory.newInstance().queryUMAToken(endpoint, clientID, clientSecret, null);
JWTSecret jwtSecret = new JWTSecret(tokenResponse.getAccessToken());
jwtSecret.setRenewalProvider(this);
@ -30,7 +34,7 @@ public class ClientIDManager implements RenewalProvider {
}
public Secret getSecret(String context) throws Exception {
TokenResponse tokenResponse = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
TokenResponse tokenResponse = KeycloakClientFactory.newInstance().queryUMAToken(endpoint, clientID, clientSecret, context, null);
JWTSecret jwtSecret = new JWTSecret(tokenResponse.getAccessToken());
jwtSecret.setRenewalProvider(this);

View File

@ -76,5 +76,5 @@ public class AccessTokenSecret extends Secret {
}
}
}

View File

@ -6,7 +6,6 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.model.AccessToken;
import org.gcube.common.keycloak.model.ModelUtils;
import org.gcube.common.keycloak.model.RefreshToken;
@ -54,7 +53,7 @@ public class JWTSecret extends Secret {
expired = true;
if(tokenResponse!=null) {
try {
KeycloakClientFactory.newInstance().refreshToken(this.getOwner().getId(), tokenResponse);
//KeycloakClientFactory.newInstance().refreshToken(URL, this.getOwner().getId(), tokenResponse);
expired = false;
}catch (Exception e) {
logger.warn("Unable to refresh the token with RefreshToken. Going to try to renew it if possible.", e);