The library now uses with `2.4.0-SNAPSHOT` version of the BOM and safe set `isExternalCall` to `true` with reflection to be compatible with both old and new `gxJRS` APIs
This commit is contained in:
parent
00d07f99c6
commit
a71f1725a7
7
pom.xml
7
pom.xml
|
@ -20,7 +20,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.distribution</groupId>
|
<groupId>org.gcube.distribution</groupId>
|
||||||
<artifactId>gcube-bom</artifactId>
|
<artifactId>gcube-bom</artifactId>
|
||||||
<version>3.0.0-SNAPSHOT</version>
|
<version>2.4.0-SNAPSHOT</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -60,11 +60,6 @@
|
||||||
<artifactId>gxJRS</artifactId>
|
<artifactId>gxJRS</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency> -->
|
|
||||||
<!-- <groupId>org.gcube.core</groupId> -->
|
|
||||||
<!-- <artifactId>common-fw-clients</artifactId> -->
|
|
||||||
<!-- </dependency> -->
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
|
|
@ -13,6 +13,8 @@ import static org.gcube.common.keycloak.model.OIDCConstants.UMA_TOKEN_GRANT_TYPE
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
@ -280,11 +282,13 @@ public class DefaultKeycloakClient implements KeycloakClient {
|
||||||
.flatMap(p -> p.getValue().stream().map(v -> p.getKey() + "=" + v))
|
.flatMap(p -> p.getValue().stream().map(v -> p.getKey() + "=" + v))
|
||||||
.reduce((p1, p2) -> p1 + "&" + p2).orElse("");
|
.reduce((p1, p2) -> p1 + "&" + p2).orElse("");
|
||||||
|
|
||||||
logger.trace("query string is {}", queryString);
|
logger.trace("Query string is {}", queryString);
|
||||||
|
|
||||||
request = GXHTTPStringRequest.newRequest(tokenURL.toString())
|
request = GXHTTPStringRequest.newRequest(tokenURL.toString())
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded").withBody(queryString);
|
.header("Content-Type", "application/x-www-form-urlencoded").withBody(queryString);
|
||||||
|
|
||||||
|
safeSetAsExternalCallForOldAPI(request);
|
||||||
|
|
||||||
logger.trace("Adding provided headers: {}", headers);
|
logger.trace("Adding provided headers: {}", headers);
|
||||||
for (String headerName : headers.keySet()) {
|
for (String headerName : headers.keySet()) {
|
||||||
request.header(headerName, headers.get(headerName));
|
request.header(headerName, headers.get(headerName));
|
||||||
|
@ -408,6 +412,7 @@ public class DefaultKeycloakClient implements KeycloakClient {
|
||||||
request = GXHTTPStringRequest.newRequest(tokenURL.toString()).header("Content-Type",
|
request = GXHTTPStringRequest.newRequest(tokenURL.toString()).header("Content-Type",
|
||||||
"application/x-www-form-urlencoded").withBody(queryString);
|
"application/x-www-form-urlencoded").withBody(queryString);
|
||||||
|
|
||||||
|
safeSetAsExternalCallForOldAPI(request);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new KeycloakClientException("Cannot construct the request object correctly", 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",
|
request = GXHTTPStringRequest.newRequest(introspectionURL.toString()).header("Content-Type",
|
||||||
"application/x-www-form-urlencoded").withBody(queryString);
|
"application/x-www-form-urlencoded").withBody(queryString);
|
||||||
|
|
||||||
|
safeSetAsExternalCallForOldAPI(request);
|
||||||
|
|
||||||
request = request.header("Authorization", constructBasicAuthenticationHeader(clientId, clientSecret));
|
request = request.header("Authorization", constructBasicAuthenticationHeader(clientId, clientSecret));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new KeycloakClientException("Cannot construct the request object correctly", 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();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue