[java-idp-plugin-oidc-op-oidfed] branch main updated: Remove the duplicated ResponseUtil class from here

Henri Mikkonen henri.mikkonen at iki.fi
Fri Oct 24 07:18:03 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=67af879b884de10ed35e246f46a7b6128388a528

The following commit(s) were added to refs/heads/main by this push:
     new 67af879  Remove the duplicated ResponseUtil class from here
67af879 is described below

commit 67af879b884de10ed35e246f46a7b6128388a528
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Oct 24 10:16:06 2025 +0300

    Remove the duplicated ResponseUtil class from here
    
    - The class remains in the OP's impl-module, which is not a dependency for the fed-plugin
---
 .../plugin/oidc/op/oidfed/tbd/ResponseUtil.java    | 294 ---------------------
 .../impl/AbstractBuildEntityStatementAction.java   |  11 +-
 2 files changed, 6 insertions(+), 299 deletions(-)

diff --git a/idp-oidfed-op-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/tbd/ResponseUtil.java b/idp-oidfed-op-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/tbd/ResponseUtil.java
deleted file mode 100644
index f993d1b..0000000
--- a/idp-oidfed-op-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/tbd/ResponseUtil.java
+++ /dev/null
@@ -1,294 +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.text.ParseException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.annotation.Nonnull;
-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.jwt.JWT;
-import com.nimbusds.jwt.JWTClaimsSet;
-import com.nimbusds.oauth2.sdk.AccessTokenResponse;
-import com.nimbusds.oauth2.sdk.ErrorObject;
-import com.nimbusds.oauth2.sdk.ErrorResponse;
-import com.nimbusds.oauth2.sdk.Response;
-import com.nimbusds.oauth2.sdk.TokenErrorResponse;
-import com.nimbusds.oauth2.sdk.TokenResponse;
-import com.nimbusds.oauth2.sdk.http.HTTPResponse;
-import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
-import com.nimbusds.openid.connect.sdk.claims.LogoutTokenClaimsSet;
-
-import jakarta.servlet.http.HttpServletResponse;
-import net.shibboleth.oidc.profile.messaging.JSONSuccessResponse;
-
-/** Response logging helper class. */
-public final class ResponseUtil {
-    
-    /** Private constructor. */
-    private ResponseUtil() {
-        
-    }
-
-    /**
-     * Helper method to print response to string for logging.
-     * 
-     * @param httpResponse response to be printed
-     * @return response as formatted string.
-     */
-    protected static String toString(@Nullable final HTTPResponse httpResponse) {
-        return toString(httpResponse, null);
-    }
-
-    /**
-     * Helper method to print response to string for logging.
-     * 
-     * @param httpResponse response to be printed
-     * @param objectMapper object mapper used for pretty printing JSON content
-     * @return response as formatted string
-     * 
-     * @since 4.1.0
-     */
-    protected static String toString(@Nullable final HTTPResponse httpResponse,
-            @Nullable final ObjectMapper objectMapper) {
-        if (httpResponse == null) {
-            return null;
-        }
-        final String nl = System.lineSeparator();
-        String ret = nl;
-        final Map<String, List<String>> headers = httpResponse.getHeaderMap();
-        if (headers != null) {
-            ret += "Headers:" + nl;
-            for (final Entry<String, List<String>> entry : headers.entrySet()) {
-                ret += "\t" + entry.getKey() + ":" + entry.getValue().get(0) + nl;
-            }
-        }
-        final String rawContent = httpResponse.getContent();
-        if (rawContent != null) {
-            if (objectMapper != null) {
-                try {
-                    final Object jsonObject = objectMapper.readValue(rawContent, Object.class);
-                    final String content = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
-                    ret += "Content:" + content.replace("\n", "\n\t");
-                    return ret;
-                } catch (JsonProcessingException e) {
-                    // fall-back into not using object mapper
-                }
-            }
-            ret += "Content:" + rawContent;
-        }
-        return ret;
-    }
-
-    /**
-     * Helper method to print response to string for logging.
-     * 
-     * @param httpServletResponse response to be printed
-     * @param content message content
-     * 
-     * @return response as formatted string.
-     */
-    @Nullable protected static String toString(@Nullable final HttpServletResponse httpServletResponse,
-            @Nullable final String content) {
-        if (httpServletResponse == null) {
-            return null;
-        }
-        final String nl = System.lineSeparator();
-        String ret = nl;
-        final Collection<String> headerNames = httpServletResponse.getHeaderNames();
-        if (headerNames != null) {
-            ret += "Headers:" + nl;
-            for (final String headerName : headerNames) {
-                ret += "\t" + headerName + ":" + httpServletResponse.getHeader(headerName) + nl;
-            }
-        }
-        if (content != null) {
-            ret += "Content:" + content;
-        }
-        return ret;
-    }
-
- // Checkstyle: CyclomaticComplexity|ReturnCount OFF
-
-    /**
-     * Helper method for getting protocol message for a Nimbus response object. This method can currently
-     * recognize success and error responses for OIDC authentication, token, userinfo, introspection and
-     * revocation.
-     * 
-     * @param response The response message
-     * @return The response message specific log message
-     */
-    @Nullable public static String getProtocolMessage(@Nullable final Response response) {
-        if (response == null) {
-            return null;
-        }
-        if (response instanceof JSONSuccessResponse) {
-            return getProtocolMessageForJSONSuccessResponse(response);
-        } else if (response instanceof ErrorResponse) {
-            final ErrorResponse genericError = (ErrorResponse) response;
-            return MoreObjects.toStringHelper(genericError).omitNullValues()
-                    .add("errorObject", genericError.getErrorObject())
-                    .toString();
-        }
-        return MoreObjects.toStringHelper(response).toString();
-    }
- // Checkstyle: CyclomaticComplexity|ReturnCount ON
-
-    /**
-     * Helper method for getting protocol message for token response.
-     * 
-     * @param response The response message
-     * @return  The response message specific log message
-     */
-    @Nullable public static String getProtocolMessageForTokenResponse(@Nonnull final TokenResponse response) {
-        if (response.indicatesSuccess()) {
-            final AccessTokenResponse successResponse = response.toSuccessResponse();
-            return MoreObjects.toStringHelper(successResponse).omitNullValues()
-                    .add("customParameters", successResponse.getCustomParameters())
-                    .add("tokens", successResponse.getTokens())
-                    .toString();
-        } else {
-            final TokenErrorResponse errorResponse = response.toErrorResponse();
-            return MoreObjects.toStringHelper(errorResponse).omitNullValues()
-                    .add("errorObject", getProtocolMessageForErrorObject(errorResponse.getErrorObject()))
-                    .toString();
-        }
-    }
-
-    /**
-     * Helper method for getting protocol message for error object.
-     * 
-     * @param errorObject The error object
-     * @return The log message
-     */
-    @Nullable public static String getProtocolMessageForErrorObject(@Nullable final ErrorObject errorObject) {
-        return errorObject == null ? null : MoreObjects.toStringHelper(errorObject).omitNullValues()
-                .add("httpStatusCode", errorObject.getHTTPStatusCode())
-                .add("code", errorObject.getCode())
-                .add("description", errorObject.getDescription())
-                .add("uri", errorObject.getURI())
-                .toString();
-    }
-
-
-    /**
-     * Helper method for getting protocol message for JSON success response.
-     * 
-     * @param response The response message
-     * @return  The response message specific log message
-     */
-    @Nullable public static String getProtocolMessageForJSONSuccessResponse(final @Nonnull Response response) {
-        if (response instanceof JSONSuccessResponse) {
-            final JSONSuccessResponse successResponse = (JSONSuccessResponse) response;
-            return successResponse.toString();
-        }
-        return null;
-    }
-
-    /**
-     * Helper method for getting protocol message for JWT payload.
-     * 
-     * @param jwt The JWT whose payload is included in the message
-     * @param objectMapper object mapper used for pretty printing JSON content
-     * @return The protocol message containing JWT payload
-     * @throws ParseException IF the protocol message cannot be constructed
-     * 
-     * @since 4.1.0
-     */
-    @Nonnull public static String getJwtProtocolMessage(@Nonnull final JWT jwt,
-            @Nonnull final ObjectMapper objectMapper) throws ParseException {
-        return getJwtProtocolMessage(jwt.getJWTClaimsSet(), objectMapper);
-    }
-
-    /**
-     * Helper method for getting protocol message for ID token payload.
-     * 
-     * @param idToken The ID token whose payload is included in the message
-     * @param objectMapper object mapper used for pretty printing JSON content
-     * @return The protocol message containing JWT payload
-     * @throws ParseException IF the protocol message cannot be constructed
-     * 
-     * @since 4.1.0
-     */
-    @Nonnull public static String getIdTokenProtocolMessage(@Nonnull final IDTokenClaimsSet idToken,
-            @Nonnull final ObjectMapper objectMapper) throws ParseException {
-        try {
-            return getJwtProtocolMessage(idToken.toJWTClaimsSet(), objectMapper);
-        } catch (final com.nimbusds.oauth2.sdk.ParseException e) {
-            final Throwable cause = e.getCause();
-            if (cause instanceof ParseException parseException) {
-                throw parseException;
-            }
-            throw new ParseException(e.getMessage(), 0);
-        }
-    }
-
-    /**
-     * Helper method for getting protocol message for logout token payload.
-     * 
-     * @param logoutToken logout token whose payload is included in the message
-     * @param objectMapper object mapper used for pretty printing JSON content
-     * @return The protocol message containing logout token payload
-     * @throws ParseException IF the protocol message cannot be constructed
-     * 
-     * @since 4.1.0
-     */
-    @Nonnull public static String getLogoutTokenProtocolMessage(@Nonnull final LogoutTokenClaimsSet logoutToken,
-            @Nonnull final ObjectMapper objectMapper) throws ParseException {
-        try {
-            return getJwtProtocolMessage(logoutToken.toJWTClaimsSet(), objectMapper);
-        } catch (final com.nimbusds.oauth2.sdk.ParseException e) {
-            final Throwable cause = e.getCause();
-            if (cause instanceof ParseException parseException) {
-                throw parseException;
-            }
-            throw new ParseException(e.getMessage(), 0);
-        }
-    }
-
-    /**
-     * Helper method for getting protocol message for JWT payload.
-     * 
-     * @param claimsSet The claims set to be included in the message
-     * @param objectMapper object mapper used for pretty printing JSON content
-     * @return The protocol message containing JWT payload
-     * @throws ParseException IF the protocol message cannot be constructed
-     * 
-     * @since 4.1.0
-     */
-    @Nonnull public static String getJwtProtocolMessage(@Nullable final JWTClaimsSet claimsSet,
-            @Nonnull final ObjectMapper objectMapper) throws ParseException {
-        if (claimsSet == null) {
-            return "<encrypted>";
-        }
-        try {
-            final Object jsonObject = objectMapper.readValue(claimsSet.toString(), Object.class);
-            final String content = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
-            if (content != null) {
-                return content;
-            }
-        } catch (final JsonProcessingException e) {
-        }
-        throw new ParseException("Could not parse the JSON output from the claims set", 0);
-    }
-
-}
\ No newline at end of file
diff --git a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/profile/impl/AbstractBuildEntityStatementAction.java b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/profile/impl/AbstractBuildEntityStatementAction.java
index 27fe3b9..05cd8a4 100644
--- a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/profile/impl/AbstractBuildEntityStatementAction.java
+++ b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/profile/impl/AbstractBuildEntityStatementAction.java
@@ -33,6 +33,7 @@ import org.opensaml.profile.context.ProfileRequestContext;
 import org.opensaml.profile.context.navigate.OutboundMessageContextLookup;
 import org.slf4j.Logger;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.nimbusds.jwt.JWT;
 import com.nimbusds.jwt.JWTClaimsSet;
@@ -41,7 +42,6 @@ import com.nimbusds.openid.connect.sdk.federation.entities.EntityStatement;
 
 import net.shibboleth.idp.plugin.oidc.op.oidfed.profile.navigate.AuthorityHintsLookupFunction;
 import net.shibboleth.idp.plugin.oidc.op.oidfed.profile.navigate.EntityStatementClaimsSetManipulationStrategyLookupFunction;
-import net.shibboleth.idp.plugin.oidc.op.oidfed.tbd.ResponseUtil;
 import net.shibboleth.idp.profile.AbstractProfileAction;
 import net.shibboleth.idp.profile.IdPEventIds;
 import net.shibboleth.profile.context.navigate.IssuerLookupFunction;
@@ -295,15 +295,16 @@ public abstract class AbstractBuildEntityStatementAction extends AbstractProfile
      */
     protected void logAndConstructEntityStatement(@Nonnull final JWTClaimsSet claimsSet) {
         log.trace("{} Building JWT from the claims set {}", getLogPrefix(), claimsSet);
-        final JWT jwt = new PlainJWT(claimsSet);
         assert objectMapper != null;
         try {
-            protocolMessageLog.trace("Entity statement payload contents:\n{}",
-                    ResponseUtil.getJwtProtocolMessage(jwt, objectMapper));
-        } catch (final ParseException e) {
+            final Object jsonObject = objectMapper.readValue(claimsSet.toString(), Object.class);
+            final String contents = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
+            protocolMessageLog.trace("Entity statement payload contents:\n{}", contents);
+        } catch (final JsonProcessingException e) {
             log.error("{} Could not construct protocol log message", getLogPrefix(), e);
         }
         assert entityStatementCtx != null;
+        final JWT jwt = new PlainJWT(claimsSet);
         entityStatementCtx.setJWT(jwt);
     }
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list