The URL is now calculated by the keycloak-client

This commit is contained in:
Luca Frosini 2022-07-18 09:58:26 +02:00
parent 361aad417b
commit 7b0a5b96bf
1 changed files with 1 additions and 17 deletions

View File

@ -1,6 +1,5 @@
package org.gcube.common.security.secrets;
import java.net.URL;
import java.util.Map;
import org.gcube.common.keycloak.KeycloakClient;
@ -10,20 +9,6 @@ import org.gcube.common.security.Owner;
public class CredentialSecret extends Secret {
private static final String PROD_ROOT_SCOPE = "/d4science.research-infrastructures.eu";
public static final String BASE_URL = "https://url.d4science.org";
public static final String SERVICE_PATH = "/auth/realms/d4science/protocol/openid-connect/token";
public static String getServiceURL(String context) {
if(context.startsWith(PROD_ROOT_SCOPE)) {
return BASE_URL;
}
String root = context.split("/")[1];
return BASE_URL.replace("url", "url." + root.replaceAll("\\.", "-"));
}
protected boolean initialised = false;
private String username;
@ -46,8 +31,7 @@ public class CredentialSecret extends Secret {
private void refreshAccessToken() {
try {
KeycloakClient client = KeycloakClientFactory.newInstance();
URL url = new URL(getServiceURL(context)+ SERVICE_PATH);
TokenResponse response = client.queryUMAToken(url, username, password, context, null);
TokenResponse response = client.queryUMAToken(username, password, context, null);
this.accessTokenSecret = new AccessTokenSecret(response.getAccessToken());
} catch (Exception e) {
throw new RuntimeException(e);