The URL is now calculated by the keycloak-client
This commit is contained in:
parent
361aad417b
commit
7b0a5b96bf
|
@ -1,6 +1,5 @@
|
||||||
package org.gcube.common.security.secrets;
|
package org.gcube.common.security.secrets;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.keycloak.KeycloakClient;
|
import org.gcube.common.keycloak.KeycloakClient;
|
||||||
|
@ -10,20 +9,6 @@ import org.gcube.common.security.Owner;
|
||||||
|
|
||||||
public class CredentialSecret extends Secret {
|
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;
|
protected boolean initialised = false;
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
|
@ -46,8 +31,7 @@ public class CredentialSecret extends Secret {
|
||||||
private void refreshAccessToken() {
|
private void refreshAccessToken() {
|
||||||
try {
|
try {
|
||||||
KeycloakClient client = KeycloakClientFactory.newInstance();
|
KeycloakClient client = KeycloakClientFactory.newInstance();
|
||||||
URL url = new URL(getServiceURL(context)+ SERVICE_PATH);
|
TokenResponse response = client.queryUMAToken(username, password, context, null);
|
||||||
TokenResponse response = client.queryUMAToken(url, username, password, context, null);
|
|
||||||
this.accessTokenSecret = new AccessTokenSecret(response.getAccessToken());
|
this.accessTokenSecret = new AccessTokenSecret(response.getAccessToken());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
Loading…
Reference in New Issue