diff --git a/pom.xml b/pom.xml
index fff615b..e8e052f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
org.gcube.distribution
gcube-bom
- 3.0.0-SNAPSHOT
+ 2.4.0-SNAPSHOT
pom
import
@@ -60,11 +60,6 @@
gxJRS
-
-
-
-
-
org.slf4j
slf4j-log4j12
diff --git a/src/main/java/org/gcube/common/keycloak/DefaultKeycloakClient.java b/src/main/java/org/gcube/common/keycloak/DefaultKeycloakClient.java
index da67800..13c4b95 100644
--- a/src/main/java/org/gcube/common/keycloak/DefaultKeycloakClient.java
+++ b/src/main/java/org/gcube/common/keycloak/DefaultKeycloakClient.java
@@ -13,6 +13,8 @@ import static org.gcube.common.keycloak.model.OIDCConstants.UMA_TOKEN_GRANT_TYPE
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
@@ -280,11 +282,13 @@ public class DefaultKeycloakClient implements KeycloakClient {
.flatMap(p -> p.getValue().stream().map(v -> p.getKey() + "=" + v))
.reduce((p1, p2) -> p1 + "&" + p2).orElse("");
- logger.trace("query string is {}", queryString);
+ logger.trace("Query string is {}", queryString);
request = GXHTTPStringRequest.newRequest(tokenURL.toString())
.header("Content-Type", "application/x-www-form-urlencoded").withBody(queryString);
+ safeSetAsExternalCallForOldAPI(request);
+
logger.trace("Adding provided headers: {}", headers);
for (String headerName : headers.keySet()) {
request.header(headerName, headers.get(headerName));
@@ -408,6 +412,7 @@ public class DefaultKeycloakClient implements KeycloakClient {
request = GXHTTPStringRequest.newRequest(tokenURL.toString()).header("Content-Type",
"application/x-www-form-urlencoded").withBody(queryString);
+ safeSetAsExternalCallForOldAPI(request);
} catch (Exception e) {
throw new KeycloakClientException("Cannot construct the request object correctly", e);
}
@@ -471,6 +476,8 @@ public class DefaultKeycloakClient implements KeycloakClient {
request = GXHTTPStringRequest.newRequest(introspectionURL.toString()).header("Content-Type",
"application/x-www-form-urlencoded").withBody(queryString);
+ safeSetAsExternalCallForOldAPI(request);
+
request = request.header("Authorization", constructBasicAuthenticationHeader(clientId, clientSecret));
} catch (Exception e) {
throw new KeycloakClientException("Cannot construct the request object correctly", e);
@@ -511,4 +518,17 @@ public class DefaultKeycloakClient implements KeycloakClient {
return introspectAccessToken(introspectionURL, clientId, clientSecret, accessTokenJWTString).getActive();
}
+ protected void safeSetAsExternalCallForOldAPI(GXHTTPStringRequest request) {
+ try {
+ logger.trace("Looking for the 'isExternalCall' method in the 'GXHTTPStringRequest' class");
+ Method isExetnalCallMethod = request.getClass().getMethod("isExternalCall", boolean.class);
+ logger.trace("Method found, is the old gxJRS API. Invoking it with 'true' argument");
+ isExetnalCallMethod.invoke(request, true);
+ } catch (NoSuchMethodException e) {
+ logger.trace("Method not found, is the new gxJRS API");
+ } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ logger.warn("Cannot invoke 'isExternalCall' method via reflection on 'GXHTTPStringRequest' class", e);
+ }
+ }
+
}