[java-idp-plugin-oidc-op-oidfed] 01/02: Depend on OP-impl for now to avoid duplicate classes
Henri Mikkonen
henri.mikkonen at iki.fi
Wed Oct 29 15:56:02 UTC 2025
This is an automated email from the git hooks/post-receive script.
hjmikkon pushed a commit to branch main
in repository java-idp-plugin-oidc-op-oidfed.
View the commit online:
https://git.shibboleth.net/view/?p=java-idp-plugin-oidc-op-oidfed.git;a=commit;h=478e796c7190a2349087d30469d0c59021ed11c1
commit 478e796c7190a2349087d30469d0c59021ed11c1
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Wed Oct 29 14:29:26 2025 +0200
Depend on OP-impl for now to avoid duplicate classes
- BaseOAuth2RequestDecoder that is extended by decoders for explicit registration and resolve entity API requests
- Depends on RequestUtil for constructing protocol messages
---
.../idp/plugin/oidc/op/oidfed/tbd/RequestUtil.java | 198 ---------------------
idp-oidfed-op-impl/pom.xml | 11 +-
.../decoding/impl/BaseOAuth2RequestDecoder.java | 117 ------------
.../ExplicitClientRegistrationRequestDecoder.java | 5 +-
.../decoding/impl/ResolveEntityRequestDecoder.java | 5 +-
pom.xml | 5 +
6 files changed, 14 insertions(+), 327 deletions(-)
diff --git a/idp-oidfed-op-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/tbd/RequestUtil.java b/idp-oidfed-op-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/tbd/RequestUtil.java
deleted file mode 100644
index 6730570..0000000
--- a/idp-oidfed-op-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/tbd/RequestUtil.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.shibboleth.idp.plugin.oidc.op.oidfed.tbd;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.annotation.Nullable;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.base.MoreObjects;
-import com.nimbusds.oauth2.sdk.AuthorizationCodeGrant;
-import com.nimbusds.oauth2.sdk.AuthorizationGrant;
-import com.nimbusds.oauth2.sdk.ClientCredentialsGrant;
-import com.nimbusds.oauth2.sdk.RefreshTokenGrant;
-import com.nimbusds.oauth2.sdk.auth.ClientAuthentication;
-import com.nimbusds.oauth2.sdk.http.HTTPRequest;
-import com.nimbusds.oauth2.sdk.token.AccessToken;
-import com.nimbusds.oauth2.sdk.token.RefreshToken;
-
-/** Request logging helper class. */
-public final class RequestUtil {
-
- /** Private constructor. */
- private RequestUtil() {
-
- }
-
- /**
- * Helper method to print request to string for logging.
- *
- * @param httpReq request to be printed
- * @return request as formatted string.
- */
- @Nullable public static String toString(@Nullable final HTTPRequest httpReq) {
- if (httpReq == null) {
- return null;
- }
- final String nl = System.lineSeparator();
- String ret = httpReq.getMethod().toString() + nl;
- final Map<String, List<String>> headers = httpReq.getHeaderMap();
- if (headers != null) {
- ret += "Headers:" + nl;
- for (final Entry<String, List<String>> entry : headers.entrySet()) {
- ret += "\t" + entry.getKey() + ":" + entry.getValue() + nl;
- }
- }
- final Map<String, List<String>> parameters = httpReq.getQueryParameters();
- if (parameters != null) {
- ret += "Parameters:" + nl;
- for (final Entry<String, List<String>> entry : parameters.entrySet()) {
- final List<String> values = entry.getValue();
- for (int i = 0; values != null && i < values.size(); i++) {
- ret += "\t" + entry.getKey() + ":" + values.get(i) + nl;
- }
- }
- }
- return ret;
- }
-
- /**
- * Helper method to print request to string for logging.
- *
- * @param httpReq request to be printed
- * @param objectMapper object mapper used for pretty printing JSON content
- * @return request as formatted string.
- *
- * @since 4.1.0
- */
- @Nullable public static String toString(@Nullable final HTTPRequest httpReq,
- @Nullable final ObjectMapper objectMapper) {
- if (httpReq == null) {
- return null;
- }
- final String nl = System.lineSeparator();
- String ret = httpReq.getMethod().toString() + nl;
- final Map<String, List<String>> headers = httpReq.getHeaderMap();
- if (headers != null) {
- ret += "Headers:" + nl;
- for (final Entry<String, List<String>> entry : headers.entrySet()) {
- ret += "\t" + entry.getKey() + ":" + entry.getValue() + nl;
- }
- }
- final Map<String, List<String>> parameters = httpReq.getQueryParameters();
- if (parameters != null) {
- if (objectMapper != null && !parameters.isEmpty()) {
- final String rawValue = parameters.keySet().iterator().next();
- try {
- final Object jsonObject = objectMapper.readValue(rawValue, Object.class);
- final String content = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
- return ret + "Content:" + content.replace("\n", "\n\t");
- } catch (JsonProcessingException e) {
- // fall-back into not using object mapper
- }
-
- }
- ret += "Parameters:" + nl;
- for (final Entry<String, List<String>> entry : parameters.entrySet()) {
- ret += "\t" + entry.getKey() + ":" + entry.getValue().get(0) + nl;
- }
- }
- return ret;
- }
-
- /**
- * Helper method for getting protocol log message for client authentication object.
- *
- * @param authentication The client authentication object
- * @return The log message
- */
- @Nullable public static String getClientAuthenticationLog(@Nullable final ClientAuthentication authentication) {
- return authentication == null ? null : MoreObjects.toStringHelper("ClientAuthentication").omitNullValues()
- .add("clientId", authentication.getClientID())
- .add("method", authentication.getMethod())
- .toString();
- }
-
- /**
- * Helper method for getting protocol log message for access token object.
- *
- * @param accessToken The access token object
- * @return The log message
- */
- @Nullable public static String getAccessTokenLog(@Nullable final AccessToken accessToken) {
- return accessToken == null ? null : MoreObjects.toStringHelper("AccessToken").omitNullValues()
- .add("lifetime", accessToken.getLifetime())
- .add("issuedTokenType", accessToken.getIssuedTokenType())
- .add("parameterNames", accessToken.getParameterNames())
- .add("scope", accessToken.getScope())
- .add("value", accessToken.getValue())
- .add("type", accessToken.getType())
- .toString();
- }
-
- /**
- * Helper method for getting protocol log message for authorization grant object.
- *
- * @param grant The authorization grant object
- * @return The log message
- */
- @Nullable public static String getAuthorizationGrantLog(@Nullable final AuthorizationGrant grant) {
- if (grant == null) {
- return null;
- }
- if (grant instanceof AuthorizationCodeGrant) {
- final AuthorizationCodeGrant codeGrant = (AuthorizationCodeGrant) grant;
- return MoreObjects.toStringHelper(codeGrant).omitNullValues()
- .add("authorizationCode", codeGrant.getAuthorizationCode())
- .add("codeVerifier", codeGrant.getCodeVerifier())
- .add("redirectionURI", codeGrant.getRedirectionURI())
- .add("type", codeGrant.getType())
- .toString();
- } else if (grant instanceof RefreshTokenGrant) {
- final RefreshTokenGrant refreshGrant = (RefreshTokenGrant) grant;
- return MoreObjects.toStringHelper(refreshGrant).omitNullValues()
- .add("refreshToken", getRefreshTokenLog(refreshGrant.getRefreshToken()))
- .add("type", refreshGrant.getType())
- .toString();
- } else if (grant instanceof ClientCredentialsGrant) {
- final ClientCredentialsGrant credentialsGrant = (ClientCredentialsGrant) grant;
- return MoreObjects.toStringHelper(credentialsGrant).omitNullValues()
- .add("type", credentialsGrant.getType())
- .toString();
-
- }
- return MoreObjects.toStringHelper(grant).omitNullValues()
- .add("type", grant.getType())
- .toString();
- }
-
- /**
- * Helper method for getting protocol log message for refresh token object.
- *
- * @param refreshToken The refresh token object
- * @return The log message
- */
- @Nullable public static String getRefreshTokenLog(@Nullable final RefreshToken refreshToken) {
- return refreshToken == null ? null : MoreObjects.toStringHelper("RefreshToken").omitNullValues()
- .add("parameterNames", refreshToken.getParameterNames())
- .add("value", refreshToken.getValue())
- .toString();
- }
-
-}
diff --git a/idp-oidfed-op-impl/pom.xml b/idp-oidfed-op-impl/pom.xml
index 6557347..0e8b2ed 100644
--- a/idp-oidfed-op-impl/pom.xml
+++ b/idp-oidfed-op-impl/pom.xml
@@ -75,6 +75,11 @@
<artifactId>idp-plugin-oidc-op-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>${oidc-op.groupId}</groupId>
+ <artifactId>idp-plugin-oidc-op-impl</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>${idp.groupId}</groupId>
<artifactId>idp-admin-api</artifactId>
@@ -406,12 +411,6 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>${oidc-op.groupId}</groupId>
- <artifactId>idp-plugin-oidc-op-impl</artifactId>
- <version>${oidc-op.version}</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>${shib-shared.groupId}</groupId>
<artifactId>shib-attribute-filter-spring</artifactId>
diff --git a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/BaseOAuth2RequestDecoder.java b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/BaseOAuth2RequestDecoder.java
deleted file mode 100644
index 2c9bbbc..0000000
--- a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/BaseOAuth2RequestDecoder.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.shibboleth.idp.plugin.oidc.op.oidfed.decoding.impl;
-
-import java.net.URI;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import org.opensaml.messaging.context.MessageContext;
-import org.opensaml.messaging.decoder.MessageDecodingException;
-import org.opensaml.messaging.decoder.servlet.AbstractHttpServletRequestMessageDecoder;
-import org.slf4j.Logger;
-
-import com.nimbusds.oauth2.sdk.Request;
-
-import jakarta.servlet.http.HttpServletRequest;
-import net.shibboleth.shared.primitive.LoggerFactory;
-
-/**
- * TODO: duplicate with OP's impl
- * Base decoder for Nimbus OAuth2 request messages.
- *
- * @param <T> The exact type of the request message, extends {@link Request}.
- */
-public abstract class BaseOAuth2RequestDecoder<T extends Request> extends AbstractHttpServletRequestMessageDecoder {
-
- /** Class logger. */
- @Nonnull private final static Logger log = LoggerFactory.getLogger(BaseOAuth2RequestDecoder.class);
-
- /** A flag to remove the IP address from the endpoint URI. */
- private boolean removeIpAddressFromEndpointUri;
-
- /** Constructor. */
- public BaseOAuth2RequestDecoder() {
- super();
- setProtocolMessageLoggerSubCategory("OAUTH2");
- }
-
- /**
- * Set the flag to remove the IP address from the endpoint URI.
- *
- * @param flag What to set.
- */
- public synchronized void setRemoveIpAddressFromEndpointUri(final boolean flag) {
- ifInitializedThrowUnmodifiabledComponentException();
- ifDestroyedThrowDestroyedComponentException();
-
- removeIpAddressFromEndpointUri = flag;
- }
-
- /** {@inheritDoc} */
- @Override
- protected void doDecode() throws MessageDecodingException {
- final MessageContext messageContext = new MessageContext();
- final HttpServletRequest httpServletRequest = getHttpServletRequest();
- assert httpServletRequest != null;
- final T requestMessage;
- requestMessage = parseMessage();
- messageContext.setMessage(requestMessage);
- setMessageContext(messageContext);
- }
-
- /**
- * Parses the message into the exact type of the request message.
- *
- * @return The request message
- * @throws MessageDecodingException if there is a problem decoding the message context
- */
- @Nullable protected abstract T parseMessage() throws MessageDecodingException;
-
- /**
- * Get the string representation of what will be logged as the protocol message.
- *
- * @param message the request message
- * @return the string representing the protocol message for logging purposes
- */
- @Nullable protected abstract String getMessageToLog(final T message);
-
- /** {@inheritDoc} */
- @Override
- @Nullable
- @SuppressWarnings("unchecked")
- protected String serializeMessageForLogging(@Nullable Object message) {
- return getMessageToLog((T) message);
- }
-
- /**
- * Returns the endpoint URI either from servlet request or from the given message, depending on the flag for
- * removing IP address from the endpoint URI.
- *
- * @param message the message from which to take the endpoint URI (with IP address), if the flag is false
- * @return the endpoint URI
- */
- @Nullable protected String getEndpointURI(final Request message) {
- if (removeIpAddressFromEndpointUri) {
- final HttpServletRequest httpServletRequest = getHttpServletRequest();
- return httpServletRequest != null ? httpServletRequest.getRequestURI() : null;
- } else {
- final URI endpointUri = message.getEndpointURI();
- return endpointUri != null ? endpointUri.toString() : null;
- }
- }
-
-}
diff --git a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/ExplicitClientRegistrationRequestDecoder.java b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/ExplicitClientRegistrationRequestDecoder.java
index 2723e04..0005384 100644
--- a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/ExplicitClientRegistrationRequestDecoder.java
+++ b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/ExplicitClientRegistrationRequestDecoder.java
@@ -33,9 +33,10 @@ import com.nimbusds.oauth2.sdk.http.JakartaServletUtils;
import com.nimbusds.openid.connect.sdk.federation.entities.EntityStatement;
import jakarta.servlet.http.HttpServletRequest;
+import net.shibboleth.idp.plugin.oidc.op.decoding.impl.RequestUtil;
+import net.shibboleth.idp.plugin.oidc.op.oauth2.decoding.impl.BaseOAuth2RequestDecoder;
import net.shibboleth.idp.plugin.oidc.op.oidfed.messaging.impl.ExplicitClientRegistrationRequest;
import net.shibboleth.idp.plugin.oidc.op.oidfed.metadata.EntityStatementHelper;
-import net.shibboleth.idp.plugin.oidc.op.oidfed.tbd.RequestUtil;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
@@ -43,8 +44,6 @@ import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Message decoder decoding OpenID Federation Explicit Registration request {@link ExplicitClientRegistrationRequest}.
- *
- * @since 4.3.0
*/
public class ExplicitClientRegistrationRequestDecoder
extends BaseOAuth2RequestDecoder<ExplicitClientRegistrationRequest> {
diff --git a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/ResolveEntityRequestDecoder.java b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/ResolveEntityRequestDecoder.java
index ec64f0b..ba15015 100644
--- a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/ResolveEntityRequestDecoder.java
+++ b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/decoding/impl/ResolveEntityRequestDecoder.java
@@ -32,14 +32,13 @@ import com.nimbusds.oauth2.sdk.http.HTTPRequest;
import com.nimbusds.oauth2.sdk.http.JakartaServletUtils;
import jakarta.servlet.http.HttpServletRequest;
+import net.shibboleth.idp.plugin.oidc.op.decoding.impl.RequestUtil;
+import net.shibboleth.idp.plugin.oidc.op.oauth2.decoding.impl.BaseOAuth2RequestDecoder;
import net.shibboleth.idp.plugin.oidc.op.oidfed.messaging.impl.ResolveEntityRequest;
-import net.shibboleth.idp.plugin.oidc.op.oidfed.tbd.RequestUtil;
import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Message decoder decoding OpenID Federation Resolve Entity request {@link ResolveEntityRequest}.
- *
- * @since 4.3.0
*/
public class ResolveEntityRequestDecoder extends BaseOAuth2RequestDecoder<ResolveEntityRequest> {
diff --git a/pom.xml b/pom.xml
index b6ecfb4..b84cf69 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,6 +105,11 @@
<artifactId>idp-plugin-oidc-op-api</artifactId>
<version>${oidc-op.version}</version>
</dependency>
+ <dependency>
+ <groupId>${oidc-op.groupId}</groupId>
+ <artifactId>idp-plugin-oidc-op-impl</artifactId>
+ <version>${oidc-op.version}</version>
+ </dependency>
<dependency>
<groupId>${shib-shared.groupId}</groupId>
<artifactId>shib-shared-bom</artifactId>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list