secret updated
This commit is contained in:
parent
3ae9e81780
commit
cf6981a284
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.common.security.renewal;
|
package org.gcube.common.security.renewal;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||||
import org.gcube.common.keycloak.model.TokenResponse;
|
import org.gcube.common.keycloak.model.TokenResponse;
|
||||||
import org.gcube.common.security.secrets.JWTSecret;
|
import org.gcube.common.security.secrets.JWTSecret;
|
||||||
|
@ -12,14 +14,16 @@ public class ClientIDManager implements RenewalProvider {
|
||||||
|
|
||||||
protected final String clientID;
|
protected final String clientID;
|
||||||
protected final String clientSecret;
|
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.clientID = clientID;
|
||||||
this.clientSecret = clientSecret;
|
this.clientSecret = clientSecret;
|
||||||
|
this.endpoint = endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Secret getSecret() throws Exception {
|
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 jwtSecret = new JWTSecret(tokenResponse.getAccessToken());
|
||||||
jwtSecret.setRenewalProvider(this);
|
jwtSecret.setRenewalProvider(this);
|
||||||
|
@ -30,7 +34,7 @@ public class ClientIDManager implements RenewalProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Secret getSecret(String context) throws Exception {
|
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 jwtSecret = new JWTSecret(tokenResponse.getAccessToken());
|
||||||
jwtSecret.setRenewalProvider(this);
|
jwtSecret.setRenewalProvider(this);
|
||||||
|
|
|
@ -76,5 +76,5 @@ public class AccessTokenSecret extends Secret {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
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.AccessToken;
|
||||||
import org.gcube.common.keycloak.model.ModelUtils;
|
import org.gcube.common.keycloak.model.ModelUtils;
|
||||||
import org.gcube.common.keycloak.model.RefreshToken;
|
import org.gcube.common.keycloak.model.RefreshToken;
|
||||||
|
@ -54,7 +53,7 @@ public class JWTSecret extends Secret {
|
||||||
expired = true;
|
expired = true;
|
||||||
if(tokenResponse!=null) {
|
if(tokenResponse!=null) {
|
||||||
try {
|
try {
|
||||||
KeycloakClientFactory.newInstance().refreshToken(this.getOwner().getId(), tokenResponse);
|
//KeycloakClientFactory.newInstance().refreshToken(URL, this.getOwner().getId(), tokenResponse);
|
||||||
expired = false;
|
expired = false;
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.warn("Unable to refresh the token with RefreshToken. Going to try to renew it if possible.", e);
|
logger.warn("Unable to refresh the token with RefreshToken. Going to try to renew it if possible.", e);
|
||||||
|
|
Loading…
Reference in New Issue