[java-idp-oidc] branch main updated: OSJ-354: Suffix the PROTOCOL_MESSAGE category with .SAML

Brent Putman putmanb at georgetown.edu
Wed Aug 2 23:39:02 UTC 2023


This is an automated email from the git hooks/post-receive script.

putmanb 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=320b92dfb03783f9780b9df8621148040eac4636

The following commit(s) were added to refs/heads/main by this push:
     new 320b92df OSJ-354: Suffix the PROTOCOL_MESSAGE category with .SAML
320b92df is described below

commit 320b92dfb03783f9780b9df8621148040eac4636
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Wed Aug 2 18:10:09 2023 -0400

    OSJ-354: Suffix the PROTOCOL_MESSAGE category with .SAML
---
 .../impl/OIDCAuthenticationRequestDecoder.java     |  2 +-
 .../impl/OIDCClientRegistrationRequestDecoder.java |  2 +-
 .../op/decoding/impl/OIDCTokenRequestDecoder.java  |  2 +-
 .../decoding/impl/OIDCUserInfoRequestDecoder.java  |  2 +-
 .../op/encoding/impl/NimbusResponseEncoder.java    | 29 ++++++++++---------
 .../decoding/impl/BaseOAuth2RequestDecoder.java    | 33 +++++++++-------------
 .../impl/OAuth2AuthorizationRequestDecoder.java    |  2 +-
 .../impl/OAuth2IntrospectionRequestDecoder.java    |  2 +-
 .../impl/OAuth2RevocationRequestDecoder.java       |  2 +-
 .../src/test/resources/logback-test.xml            |  1 +
 10 files changed, 37 insertions(+), 40 deletions(-)

diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCAuthenticationRequestDecoder.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCAuthenticationRequestDecoder.java
index afc5a62a..15a75fac 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCAuthenticationRequestDecoder.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCAuthenticationRequestDecoder.java
@@ -44,7 +44,7 @@ public class OIDCAuthenticationRequestDecoder extends BaseOAuth2RequestDecoder<A
     protected AuthenticationRequest parseMessage() throws MessageDecodingException {
         try {
             final HTTPRequest httpReq = JakartaServletUtils.createHTTPRequest(getHttpServletRequest());
-            getProtocolMessageLog().trace("Inbound request {}", RequestUtil.toString(httpReq));
+            getProtocolMessageLogger().trace("Inbound request {}", RequestUtil.toString(httpReq));
             return AuthenticationRequest.parse(httpReq);
         } catch (final com.nimbusds.oauth2.sdk.ParseException | IOException e) {
             log.error("Unable to decode inbound request: {}", e.getMessage());
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCClientRegistrationRequestDecoder.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCClientRegistrationRequestDecoder.java
index 3e8da91b..f0a9fa63 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCClientRegistrationRequestDecoder.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCClientRegistrationRequestDecoder.java
@@ -47,7 +47,7 @@ public class OIDCClientRegistrationRequestDecoder extends BaseOAuth2RequestDecod
     protected OIDCClientRegistrationRequest parseMessage() throws MessageDecodingException {
         try {
             final HTTPRequest httpRequest = JakartaServletUtils.createHTTPRequest(getHttpServletRequest());
-            getProtocolMessageLog().trace("Inbound request {}", RequestUtil.toString(httpRequest));
+            getProtocolMessageLogger().trace("Inbound request {}", RequestUtil.toString(httpRequest));
             final JSONObject requestJson = httpRequest.getQueryAsJSONObject();
             //TODO: Nimbus seems to be interpreting scope in different way as many RPs, currently the scope
             //is removed in this phase, better solution TODO.
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCTokenRequestDecoder.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCTokenRequestDecoder.java
index e6f355a2..73722611 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCTokenRequestDecoder.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCTokenRequestDecoder.java
@@ -44,7 +44,7 @@ public class OIDCTokenRequestDecoder extends BaseOAuth2RequestDecoder<TokenReque
     protected TokenRequest parseMessage() throws MessageDecodingException {
         try {
             final HTTPRequest httpReq = JakartaServletUtils.createHTTPRequest(getHttpServletRequest());
-            getProtocolMessageLog().trace("Inbound request {}", RequestUtil.toString(httpReq));
+            getProtocolMessageLogger().trace("Inbound request {}", RequestUtil.toString(httpReq));
             return TokenRequest.parse(httpReq);
         } catch (final ParseException | IOException e) {
             log.error("Unable to decode inbound request: {}", e.getMessage());
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCUserInfoRequestDecoder.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCUserInfoRequestDecoder.java
index d7bec126..5c10ac95 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCUserInfoRequestDecoder.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/decoding/impl/OIDCUserInfoRequestDecoder.java
@@ -43,7 +43,7 @@ public class OIDCUserInfoRequestDecoder extends BaseOAuth2RequestDecoder<UserInf
     protected UserInfoRequest parseMessage() throws MessageDecodingException {
         try {
             final HTTPRequest httpReq = JakartaServletUtils.createHTTPRequest(getHttpServletRequest());
-            getProtocolMessageLog().trace("Inbound request {}", RequestUtil.toString(httpReq));
+            getProtocolMessageLogger().trace("Inbound request {}", RequestUtil.toString(httpReq));
             return UserInfoRequest.parse(httpReq);
         } catch (final ParseException | IOException e) {
             log.error("Unable to decode inbound request: {}", e.getMessage());
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/encoding/impl/NimbusResponseEncoder.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/encoding/impl/NimbusResponseEncoder.java
index 0d34d5fb..01bed066 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/encoding/impl/NimbusResponseEncoder.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/encoding/impl/NimbusResponseEncoder.java
@@ -53,15 +53,18 @@ public class NimbusResponseEncoder extends AbstractHttpServletResponseMessageEnc
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(NimbusResponseEncoder.class);
 
-    /** Used to log protocol messages. */
-    @Nonnull private final Logger protocolMessageLog = LoggerFactory.getLogger("PROTOCOL_MESSAGE.OAUTH2");
-
     /** Velocity engine used to evaluate the template when using FORM POST response mode. */
     @Nullable private VelocityEngine velocityEngine;
 
     /** ID of the Velocity template used when using FORM POST response mode. */
     @Nonnull @NotEmpty private String velocityTemplateId = DEFAULT_TEMPLATE_ID;
 
+    /** Constructor. */
+    public NimbusResponseEncoder() {
+        super();
+        setProtocolMessageLoggerCategory(BASE_PROTOCOL_MESSAGE_LOGGER_CATEGORY + ".OAUTH2");
+    }
+
     /**
      * Set the Velocity template id.
      * 
@@ -122,15 +125,6 @@ public class NimbusResponseEncoder extends AbstractHttpServletResponseMessageEnc
             throw new MessageEncodingException("Incorrect message type");
         }
 
-        if (protocolMessageLog.isDebugEnabled() ){
-            final String message = ResponseUtil.getProtocolMessage((Response) getMessageContext().getMessage());
-            if (message == null) {
-                log.warn("Protocol log message was null, nothing to log");
-            } else {
-                protocolMessageLog.debug(message);
-            }
-        }
-
         try {
             final HttpServletResponse response = getHttpServletResponse();
             if (impliesFormPost(getMessageContext().getMessage())) {
@@ -148,15 +142,22 @@ public class NimbusResponseEncoder extends AbstractHttpServletResponseMessageEnc
                 // Write it also to log
                 final StringWriter writer = new StringWriter();
                 velocityEngine.mergeTemplate(velocityTemplateId, "UTF-8", context, writer);
-                protocolMessageLog.trace("Outbound response {}", ResponseUtil.toString(response, writer.toString()));
+                getProtocolMessageLogger().trace("Outbound response {}", ResponseUtil.toString(response, writer.toString()));
                 return;
             }
             final HTTPResponse resp = ((Response) getMessageContext().getMessage()).toHTTPResponse();
-            protocolMessageLog.trace("Outbound response {}", ResponseUtil.toString(resp));
+            getProtocolMessageLogger().trace("Outbound response {}", ResponseUtil.toString(resp));
             JakartaServletUtils.applyHTTPResponse(resp, response);
         } catch (final IOException e) {
             throw new MessageEncodingException("Problem encoding response", e);
         }
     }
+    
+    /** {@inheritDoc} */
+    @Override
+    @Nullable
+    protected String serializeMessageForLogging(@Nullable Object message) {
+        return ResponseUtil.getProtocolMessage((Response) message);
+    }
 
 }
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/BaseOAuth2RequestDecoder.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/BaseOAuth2RequestDecoder.java
index b62ba50b..5b6e6a5b 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/BaseOAuth2RequestDecoder.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/BaseOAuth2RequestDecoder.java
@@ -38,12 +38,15 @@ public abstract class BaseOAuth2RequestDecoder<T extends Request> extends Abstra
     @Nonnull
     private final Logger log = LoggerFactory.getLogger(BaseOAuth2RequestDecoder.class);
 
-    /** Used to log protocol messages. */
-    @Nonnull private final Logger protocolMessageLog = LoggerFactory.getLogger("PROTOCOL_MESSAGE.OAUTH2");
-
     /** A flag to remove the IP address from the endpoint URI. */
     private boolean removeIpAddressFromEndpointUri;
 
+    /** Constructor. */
+    public BaseOAuth2RequestDecoder() {
+        super();
+        setProtocolMessageLoggerCategory(BASE_PROTOCOL_MESSAGE_LOGGER_CATEGORY + ".OAUTH2");
+    }
+
     /**
      * Set the flag to remove the IP address from the endpoint URI.
      * 
@@ -63,24 +66,8 @@ public abstract class BaseOAuth2RequestDecoder<T extends Request> extends Abstra
         final T requestMessage = parseMessage();
         messageContext.setMessage(requestMessage);
         setMessageContext(messageContext);
-        if (protocolMessageLog.isDebugEnabled() ){
-            final String message = getMessageToLog(requestMessage);
-            if (message == null) {
-                log.warn("Decoded protocol log message was null, nothing to log");
-                return;
-            }
-            protocolMessageLog.debug(message);
-        }
     }
 
-    /**
-     * Get the protocol message logger.
-     * 
-     * @return The protocol message logger
-     */
-    @Nonnull protected Logger getProtocolMessageLog() {
-        return protocolMessageLog;
-    }
     /**
      * Parses the message into the exact type of the request message.
      * 
@@ -97,6 +84,14 @@ public abstract class BaseOAuth2RequestDecoder<T extends Request> extends Abstra
      */
     @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.
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2AuthorizationRequestDecoder.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2AuthorizationRequestDecoder.java
index eba056fb..e23947db 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2AuthorizationRequestDecoder.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2AuthorizationRequestDecoder.java
@@ -44,7 +44,7 @@ public class OAuth2AuthorizationRequestDecoder extends BaseOAuth2RequestDecoder<
     protected AuthorizationRequest parseMessage() throws MessageDecodingException {
         try {
             final HTTPRequest httpReq = JakartaServletUtils.createHTTPRequest(getHttpServletRequest());
-            getProtocolMessageLog().trace("Inbound request {}", RequestUtil.toString(httpReq));
+            getProtocolMessageLogger().trace("Inbound request {}", RequestUtil.toString(httpReq));
             return AuthorizationRequest.parse(httpReq);
         } catch (final com.nimbusds.oauth2.sdk.ParseException | IOException e) {
             log.error("Unable to decode inbound request: {}", e.getMessage());
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2IntrospectionRequestDecoder.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2IntrospectionRequestDecoder.java
index e348aeb6..dd359193 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2IntrospectionRequestDecoder.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2IntrospectionRequestDecoder.java
@@ -43,7 +43,7 @@ public class OAuth2IntrospectionRequestDecoder extends BaseOAuth2RequestDecoder<
     protected TokenIntrospectionRequest parseMessage() throws MessageDecodingException {
         try {
             final HTTPRequest httpReq = JakartaServletUtils.createHTTPRequest(getHttpServletRequest());
-            getProtocolMessageLog().trace("Inbound request {}", RequestUtil.toString(httpReq));
+            getProtocolMessageLogger().trace("Inbound request {}", RequestUtil.toString(httpReq));
             return TokenIntrospectionRequest.parse(httpReq);
         } catch (final com.nimbusds.oauth2.sdk.ParseException | IOException e) {
             log.error("Unable to decode inbound request: {}", e.getMessage());
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2RevocationRequestDecoder.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2RevocationRequestDecoder.java
index f358323b..d3d4031b 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2RevocationRequestDecoder.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oauth2/decoding/impl/OAuth2RevocationRequestDecoder.java
@@ -43,7 +43,7 @@ public class OAuth2RevocationRequestDecoder extends BaseOAuth2RequestDecoder<Tok
     protected TokenRevocationRequest parseMessage() throws MessageDecodingException {
         try {
             final HTTPRequest httpReq = JakartaServletUtils.createHTTPRequest(getHttpServletRequest());
-            getProtocolMessageLog().trace("Inbound request {}", RequestUtil.toString(httpReq));
+            getProtocolMessageLogger().trace("Inbound request {}", RequestUtil.toString(httpReq));
             return TokenRevocationRequest.parse(httpReq);
         } catch (final com.nimbusds.oauth2.sdk.ParseException | IOException e) {
             log.error("Unable to decode inbound request: {}", e.getMessage());
diff --git a/idp-oidc-extension-impl/src/test/resources/logback-test.xml b/idp-oidc-extension-impl/src/test/resources/logback-test.xml
index 494a6712..0a5c2f5f 100644
--- a/idp-oidc-extension-impl/src/test/resources/logback-test.xml
+++ b/idp-oidc-extension-impl/src/test/resources/logback-test.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <configuration>
+    <logger name="PROTOCOL_MESSAGE" level="TRACE"/>
     <logger name="net.shibboleth.idp.oidc" level="TRACE"/>
     <logger name="net.shibboleth.idp.oauth2" level="TRACE"/>
     <logger name="net.shibboleth" level="DEBUG"/>

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


More information about the commits mailing list