40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
|
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.ModelUtils;
|
||
|
import org.gcube.common.keycloak.model.RefreshToken;
|
||
|
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 tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, null);
|
||
|
|
||
|
JWTSecret jwtSecret = new JWTSecret(tr.getAccessToken());
|
||
|
jwtSecret.setRenewalProvider(this);
|
||
|
|
||
|
RefreshToken refreshToken = ModelUtils.getRefreshTokenFrom(tr);
|
||
|
jwtSecret.setRefreshToken(refreshToken);
|
||
|
|
||
|
return jwtSecret;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Secret renew() throws Exception {
|
||
|
return getSecret();
|
||
|
}
|
||
|
}
|