[java-idp-oidc] branch main updated: JOIDC-130 - Remove dependency on Gson library
Henri Mikkonen
henri.mikkonen at iki.fi
Thu Oct 13 14:43:01 UTC 2022
This is an automated email from the git hooks/post-receive script.
hjmikkon pushed a commit to branch main
in repository java-idp-oidc.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-oidc.git;a=commit;h=f2aeef738995f64bd7c769547babc8a66b6786ef
The following commit(s) were added to refs/heads/main by this push:
new f2aeef73 JOIDC-130 - Remove dependency on Gson library
f2aeef73 is described below
commit f2aeef738995f64bd7c769547babc8a66b6786ef
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Thu Oct 13 17:41:04 2022 +0300
JOIDC-130 - Remove dependency on Gson library
https://shibboleth.atlassian.net/browse/JOIDC-130
CheckRedirectURIs action updated and gson dependency removed from POMs.
---
idp-oidc-extension-impl/pom.xml | 4 ---
.../oidc/op/profile/impl/CheckRedirectURIs.java | 35 +++++++++++++++-------
.../idp/flows/oidc/register/register-beans.xml | 3 +-
.../op/profile/impl/CheckRedirectUrisTest.java | 18 +++++++++++
pom.xml | 6 ----
5 files changed, 45 insertions(+), 21 deletions(-)
diff --git a/idp-oidc-extension-impl/pom.xml b/idp-oidc-extension-impl/pom.xml
index 87aa47f2..644077f2 100644
--- a/idp-oidc-extension-impl/pom.xml
+++ b/idp-oidc-extension-impl/pom.xml
@@ -25,10 +25,6 @@
<groupId>net.shibboleth.idp.plugin.oidc</groupId>
<artifactId>idp-plugin-oidc-op-api</artifactId>
</dependency>
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- </dependency>
<!-- provided dependencies -->
<dependency>
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectURIs.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectURIs.java
index 7fd3d432..139bb6e7 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectURIs.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectURIs.java
@@ -18,9 +18,8 @@
package net.shibboleth.idp.plugin.oidc.op.profile.impl;
import java.io.IOException;
-import java.lang.reflect.Type;
import java.net.URI;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Set;
@@ -42,9 +41,8 @@ import org.opensaml.security.httpclient.HttpClientSecuritySupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.Gson;
-import com.google.gson.JsonSyntaxException;
-import com.google.gson.reflect.TypeToken;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.oauth2.sdk.GrantType;
import com.nimbusds.openid.connect.sdk.rp.ApplicationType;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
@@ -86,6 +84,9 @@ public class CheckRedirectURIs extends AbstractProfileAction {
/** HTTP client security parameters. */
@Nullable private HttpClientSecurityParameters httpClientSecurityParameters;
+ /** JSON object mapper. */
+ @NonnullAfterInit private ObjectMapper objectMapper;
+
/** Constructor. */
public CheckRedirectURIs() {
super();
@@ -115,6 +116,17 @@ public class CheckRedirectURIs extends AbstractProfileAction {
httpClientSecurityParameters = params;
}
+ /**
+ * Set the JSON {@link ObjectMapper}.
+ *
+ * @param mapper object mapper
+ */
+ public void setObjectMapper(@Nonnull final ObjectMapper mapper) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+
+ objectMapper = Constraint.isNotNull(mapper, "Object mapper cannot be null");
+ }
+
/** {@inheritDoc} */
public void doInitialize() throws ComponentInitializationException {
super.doInitialize();
@@ -122,6 +134,10 @@ public class CheckRedirectURIs extends AbstractProfileAction {
if (httpClient == null) {
throw new ComponentInitializationException(getLogPrefix() + " HttpClient cannot be null");
}
+
+ if (objectMapper == null) {
+ throw new ComponentInitializationException(getLogPrefix() + "ObjectMapper cannot be null");
+ }
}
/** {@inheritDoc} */
@@ -251,13 +267,12 @@ public class CheckRedirectURIs extends AbstractProfileAction {
EntityUtils.consumeQuietly(response.getEntity());
}
log.trace("{} Fetched the following response body: {}", getLogPrefix(), output);
- final Type listType = new TypeToken<ArrayList<URI>>(){}.getType();
final List<URI> parsedUris;
try {
- parsedUris = new Gson().fromJson(output, listType);
- } catch (final JsonSyntaxException e) {
- log.error("{} Could not parse the sector_identifier_uri contents from {}", getLogPrefix(), sectorIdUri);
- return false;
+ parsedUris = Arrays.asList(objectMapper.readValue(output, URI[].class));
+ } catch (final JsonProcessingException e) {
+ log.error("{} Could not parse the sector_identifier_uri contents from {}", getLogPrefix(), sectorIdUri, e);
+ return false;
}
if (parsedUris == null) {
log.error("{} sector_identifier_uris contents is empty, no URLs included: {}", getLogPrefix(), output);
diff --git a/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/register/register-beans.xml b/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/register/register-beans.xml
index 988c228e..2a786e01 100644
--- a/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/register/register-beans.xml
+++ b/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/register/register-beans.xml
@@ -58,7 +58,8 @@
class="net.shibboleth.idp.plugin.oidc.op.profile.impl.CheckRedirectURIs"
scope="prototype"
p:httpClient="#{getObject('shibboleth.oidc.NonBrowser.HttpClient') ?: getObject('shibboleth.InternalHttpClient')}"
- p:httpClientSecurityParameters="#{getObject('shibboleth.oidc.NonBrowser.HttpClientSecurityParameters')}" />
+ p:httpClientSecurityParameters="#{getObject('shibboleth.oidc.NonBrowser.HttpClientSecurityParameters')}"
+ p:objectMapper-ref="shibboleth.oidc.JSONObjectMapper" />
<bean id="GenerateClientID"
class="net.shibboleth.idp.plugin.oidc.op.profile.impl.GenerateClientID"
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java
index 53775393..4becdf6c 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/CheckRedirectUrisTest.java
@@ -37,6 +37,7 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientRegistrationRequest;
@@ -57,6 +58,7 @@ public class CheckRedirectUrisTest extends BaseOIDCRegistrationRequestTest {
public void setUp() throws ComponentInitializationException, URISyntaxException, ClientProtocolException,
IOException {
action = new CheckRedirectURIs();
+ action.setObjectMapper(new ObjectMapper());
action.setHttpClient(buildMockHttpClient("mock"));
action.initialize();
redirectUri1 = new URI("https://example.org/cb1");
@@ -124,6 +126,14 @@ public class CheckRedirectUrisTest extends BaseOIDCRegistrationRequestTest {
assertEvent(OidcEventIds.INVALID_REDIRECT_URIS, metadata, redirectUri1);
}
+ @Test
+ public void testInvalidUrlContents() throws Exception {
+ final OIDCClientMetadata metadata = new OIDCClientMetadata();
+ metadata.setSectorIDURI(new URI("https://invalid.scheme.org/cb"));
+ initializeActionWithClient(buildMockHttpClient("[ \"http://not valid url/\" ]"));
+ assertEvent(OidcEventIds.INVALID_REDIRECT_URIS, metadata, redirectUri1);
+ }
+
@Test
public void testValidSectorIdUriContents() throws Exception {
final OIDCClientMetadata metadata = new OIDCClientMetadata();
@@ -142,9 +152,17 @@ public class CheckRedirectUrisTest extends BaseOIDCRegistrationRequestTest {
"localhost"));
}
+ @Test(expectedExceptions = ComponentInitializationException.class)
+ public void testNoObjectMapper() throws Exception {
+ action = new CheckRedirectURIs();
+ action.setHttpClient(buildMockHttpClient("mock"));
+ action.initialize();
+ }
+
protected void initializeActionWithClient(final HttpClient httpClient) throws ComponentInitializationException {
action = new CheckRedirectURIs();
action.setHttpClient(httpClient);
+ action.setObjectMapper(new ObjectMapper());
action.initialize();
}
diff --git a/pom.xml b/pom.xml
index 0d5c0677..3065f363 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,6 @@
<shib.idp.version>4.2.0</shib.idp.version>
<opensaml.version>4.2.0</opensaml.version>
<oidc.common.version>2.1.0</oidc.common.version>
- <gson.version>2.8.6</gson.version>
<commons.io.version>2.6</commons.io.version>
<checkstyle.configLocation>${project.basedir}/resources/checkstyle.xml</checkstyle.configLocation>
</properties>
@@ -100,11 +99,6 @@
<version>${project.version}</version>
<artifactId>idp-plugin-oidc-op-api</artifactId>
</dependency>
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>${gson.version}</version>
- </dependency>
<!-- Test IdP bom dependencies -->
<dependency>
<groupId>net.shibboleth.idp</groupId>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list