[java-opensaml] branch main updated: IDP-2177 - Check for message type early during decode process

Scott Cantor cantor.2 at osu.edu
Wed Dec 6 19:49:14 UTC 2023


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

scantor pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=cac90c65d4f815738455a761535b9e82becb0a52

The following commit(s) were added to refs/heads/main by this push:
     new cac90c65d IDP-2177 - Check for message type early during decode process
cac90c65d is described below

commit cac90c65d4f815738455a761535b9e82becb0a52
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Dec 6 14:49:11 2023 -0500

    IDP-2177 - Check for message type early during decode process
    
    https://shibboleth.atlassian.net/browse/IDP-2177
    
    Extend DecodeMessage action with message type enforcement.
---
 .../profile/action/impl/DecodeMessage.java         | 25 ++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/DecodeMessage.java b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/DecodeMessage.java
index 71a7b5f50..31ded7639 100644
--- a/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/DecodeMessage.java
+++ b/opensaml-profile-impl/src/main/java/org/opensaml/profile/action/impl/DecodeMessage.java
@@ -15,6 +15,7 @@
 package org.opensaml.profile.action.impl;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.messaging.decoder.MessageDecoder;
@@ -33,6 +34,7 @@ import net.shibboleth.shared.primitive.LoggerFactory;
  * 
  * @event {@link EventIds#PROCEED_EVENT_ID}
  * @event {@link EventIds#UNABLE_TO_DECODE}
+ * @event {@link EventIds#INVALID_MESSAGE}
  * 
  * @post If decode succeeds, ProfileRequestContext.getInboundMessageContext() != null
  * @post The injected {@link MessageDecoder} is destroyed.
@@ -44,6 +46,9 @@ public class DecodeMessage extends AbstractProfileAction {
 
     /** The {@link MessageDecoder} instance used to decode the incoming message. */
     @Nonnull private final MessageDecoder decoder;
+    
+    /** Optional message type to enforce. */
+    @Nullable private Class<?> messageType;
 
     /**
      * Constructor.
@@ -53,6 +58,19 @@ public class DecodeMessage extends AbstractProfileAction {
     public DecodeMessage(@Nonnull final MessageDecoder messageDecoder) {
         decoder = Constraint.isNotNull(messageDecoder, "MessageDecoder cannot be null");
     }
+    
+    /**
+     * Set a message type to enforce after decoding.
+     * 
+     * @param type message type
+     * 
+     * @since 5.1.0
+     */
+    public void setMessageType(@Nullable final Class<?> type) {
+        checkSetterPreconditions();
+        
+        messageType = type;
+    }
 
     /** {@inheritDoc} */
     @Override
@@ -65,8 +83,11 @@ public class DecodeMessage extends AbstractProfileAction {
             final Object msg = msgContext != null ? msgContext.getMessage() : null;
 
             if (msg != null) {
-                log.debug("{} Incoming request decoded into a message of type {}", getLogPrefix(), 
-                        msg.getClass().getName());
+                if (messageType != null && !messageType.isInstance(msg)) {
+                    log.warn("{} Message was of incorrect type, expected {}, saw {}", getLogPrefix(), messageType,
+                            msg.getClass().getName());
+                    ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
+                }
             } else {
                 log.warn("{} Decoder did not produce an incoming message?", getLogPrefix());
             }

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


More information about the commits mailing list