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

48 lines
1.4 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)
*/
public class ClienIDManager implements RenewalProvider {
protected final String clientID;
protected final String clientSecret;
public ClienIDManager(String clientID, String clientSecret) {
this.clientID = clientID;
this.clientSecret = clientSecret;
}
public Secret getSecret() throws Exception {
TokenResponse tokenResponse = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, null);
2021-12-06 17:43:18 +01:00
JWTSecret jwtSecret = new JWTSecret(tokenResponse.getAccessToken());
2021-12-06 17:43:18 +01:00
jwtSecret.setRenewalProvider(this);
jwtSecret.setTokenResponse(tokenResponse);
2021-12-06 17:43:18 +01:00
return jwtSecret;
}
2022-03-29 12:43:25 +02:00
public Secret getSecret(String context) throws Exception {
TokenResponse tokenResponse = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
JWTSecret jwtSecret = new JWTSecret(tokenResponse.getAccessToken());
jwtSecret.setRenewalProvider(this);
jwtSecret.setTokenResponse(tokenResponse);
return jwtSecret;
}
2021-12-06 17:43:18 +01:00
@Override
public Secret renew() throws Exception {
return getSecret();
}
}