authorization-utils/src/main/java/org/gcube/common/authorization/utils/clientid/ClientIDManager.java

38 lines
1.1 KiB
Java
Raw Normal View History

2021-12-06 17:43:18 +01:00
package org.gcube.common.authorization.utils.clientid;
import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.model.TokenResponse;
/**
* @author Luca Frosini (ISTI - CNR)
*/
2022-03-30 15:03:50 +02:00
public class ClientIDManager implements RenewalProvider {
2021-12-06 17:43:18 +01:00
protected final String clientID;
protected final String clientSecret;
2022-03-30 15:03:50 +02:00
public ClientIDManager(String clientID, String clientSecret) {
2021-12-06 17:43:18 +01:00
this.clientID = clientID;
this.clientSecret = clientSecret;
}
2022-03-29 12:43:25 +02:00
public Secret getSecret(String context) throws Exception {
2023-07-11 10:21:12 +02:00
TokenResponse tokenResponse = KeycloakClientFactory.newInstance().queryUMAToken(context, clientID, clientSecret, context, null);
2022-03-29 12:43:25 +02:00
JWTSecret jwtSecret = new JWTSecret(tokenResponse.getAccessToken());
jwtSecret.setRenewalProvider(this);
jwtSecret.setTokenResponse(tokenResponse);
return jwtSecret;
}
2022-03-30 14:29:40 +02:00
2021-12-06 17:43:18 +01:00
@Override
public Secret renew(String context) throws Exception {
return getSecret(context);
2021-12-06 17:43:18 +01:00
}
2022-03-30 15:03:50 +02:00
2021-12-06 17:43:18 +01:00
}