[java-opensaml] branch main updated: OSJ-418 - Allow classes to skip servlet request check at init time

Scott Cantor cantor.2 at osu.edu
Wed Oct 2 17:56:56 UTC 2024


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=f3bb73bc6eafe8a08046fd892b26525d4069c73d

The following commit(s) were added to refs/heads/main by this push:
     new f3bb73bc6 OSJ-418 - Allow classes to skip servlet request check at init time
f3bb73bc6 is described below

commit f3bb73bc6eafe8a08046fd892b26525d4069c73d
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Oct 2 13:56:52 2024 -0400

    OSJ-418 - Allow classes to skip servlet request check at init time
    
    https://shibboleth.atlassian.net/browse/OSJ-418
    
    Added base class for servlet-aware message handlers with new flag.
---
 .../AbstractHttpServletRequestMessageDecoder.java  |  8 +++-
 .../AbstractHttpServletRequestMessageHandler.java} | 54 +++++++++++----------
 .../BaseSAMLSimpleSignatureSecurityHandler.java    | 55 +---------------------
 .../impl/ReceivedEndpointSecurityHandler.java      | 53 +--------------------
 4 files changed, 39 insertions(+), 131 deletions(-)

diff --git a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/decoder/servlet/AbstractHttpServletRequestMessageDecoder.java b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/decoder/servlet/AbstractHttpServletRequestMessageDecoder.java
index bea7863c5..7ebc67ab7 100644
--- a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/decoder/servlet/AbstractHttpServletRequestMessageDecoder.java
+++ b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/decoder/servlet/AbstractHttpServletRequestMessageDecoder.java
@@ -68,7 +68,11 @@ public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractM
         checkDuringInit = flag;
     }
     
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     * 
+     * <p>The return annotation is valid only in the default state, when {@link #isCheckDuringInit()} is true.</p>
+     */
     @NonnullAfterInit public HttpServletRequest getHttpServletRequest() {
         if (httpServletRequestSupplier != null) {
             return httpServletRequestSupplier.get();
@@ -81,7 +85,7 @@ public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractM
      * Get the supplier for HTTP request if available.
      * 
      * <p>The return annotation is valid only in the default state, when {@link #isCheckDuringInit()} is true.</p>
-     *
+     * 
      * @return current HTTP request
      */
     @NonnullAfterInit public NonnullSupplier<HttpServletRequest> getHttpServletRequestSupplier() {
diff --git a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/decoder/servlet/AbstractHttpServletRequestMessageDecoder.java b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractHttpServletRequestMessageHandler.java
similarity index 73%
copy from opensaml-messaging-api/src/main/java/org/opensaml/messaging/decoder/servlet/AbstractHttpServletRequestMessageDecoder.java
copy to opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractHttpServletRequestMessageHandler.java
index bea7863c5..ec126f4d2 100644
--- a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/decoder/servlet/AbstractHttpServletRequestMessageDecoder.java
+++ b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractHttpServletRequestMessageHandler.java
@@ -12,31 +12,30 @@
  * limitations under the License.
  */
 
-package org.opensaml.messaging.decoder.servlet;
+package org.opensaml.messaging.handler;
 
 import javax.annotation.Nullable;
 
-import org.opensaml.messaging.decoder.AbstractMessageDecoder;
-
 import jakarta.servlet.http.HttpServletRequest;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.primitive.NonnullSupplier;
 
 /**
- * Abstract implementation of {@link HttpServletRequestMessageDecoder}.
+ * Base class for message handlers that require access to an {@link HttpServletRequest}.
+ * 
+ * @since 5.2.0
  */
-public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractMessageDecoder
-        implements HttpServletRequestMessageDecoder {
+public abstract class AbstractHttpServletRequestMessageHandler extends AbstractMessageHandler {
 
     /** Flag for whether to check for servlet request during init. */
     private boolean checkDuringInit;
     
-    /** Current HTTP request, if available. */
+    /** The HttpServletRequest being processed. */
     @NonnullAfterInit private NonnullSupplier<HttpServletRequest> httpServletRequestSupplier;
 
     /** Constructor. */
-    public AbstractHttpServletRequestMessageDecoder() {
+    public AbstractHttpServletRequestMessageHandler() {
         checkDuringInit = true;
     }
     
@@ -45,8 +44,6 @@ public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractM
      * returns null.
      * 
      * @return whether a null request should fail initialization
-     * 
-     * @since 5.2.0
      */
     public boolean isCheckDuringInit() {
         return checkDuringInit;
@@ -59,8 +56,6 @@ public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractM
      * <p>Defaults to true.</p>
      * 
      * @param flag
-     * 
-     * @since 5.2.0
      */
     public void setCheckDuringInit(final boolean flag) {
         checkSetterPreconditions();
@@ -68,28 +63,36 @@ public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractM
         checkDuringInit = flag;
     }
     
-    /** {@inheritDoc} */
+    /**
+     * Get the HTTP servlet request being processed.
+     * 
+     * <p>The return annotation is valid only in the default state, when {@link #isCheckDuringInit()} is true.</p>
+     * 
+     * @return Returns the request.
+     */
     @NonnullAfterInit public HttpServletRequest getHttpServletRequest() {
-        if (httpServletRequestSupplier != null) {
-            return httpServletRequestSupplier.get();
+        if (httpServletRequestSupplier == null) {
+            return null;
         }
-        
-        return null;
+        return httpServletRequestSupplier.get();
     }
 
     /**
-     * Get the supplier for HTTP request if available.
-     * 
-     * <p>The return annotation is valid only in the default state, when {@link #isCheckDuringInit()} is true.</p>
+     * Get the supplier for  HTTP request if available.
      *
+     * <p>The return annotation is valid only in the default state, when {@link #isCheckDuringInit()} is true.</p>
+     * 
      * @return current HTTP request
      */
     @NonnullAfterInit public NonnullSupplier<HttpServletRequest> getHttpServletRequestSupplier() {
         return httpServletRequestSupplier;
     }
 
-    /** {@inheritDoc} */
-    @Override
+    /**
+     * Set the current HTTP request Supplier.
+     *
+     * @param requestSupplier Supplier for the current HTTP request
+     */
     public void setHttpServletRequestSupplier(@Nullable final NonnullSupplier<HttpServletRequest> requestSupplier) {
         checkSetterPreconditions();
 
@@ -97,12 +100,13 @@ public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractM
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void doInitialize() throws ComponentInitializationException {
         super.doInitialize();
-
+        
         if (isCheckDuringInit() && getHttpServletRequest() == null) {
-            throw new ComponentInitializationException("HTTP Servlet request cannot be null");
+            throw new ComponentInitializationException("HttpServletRequest cannot be null");
         }
     }
-
+    
 }
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/BaseSAMLSimpleSignatureSecurityHandler.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/BaseSAMLSimpleSignatureSecurityHandler.java
index 9d50668c6..f8eabbdb7 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/BaseSAMLSimpleSignatureSecurityHandler.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/BaseSAMLSimpleSignatureSecurityHandler.java
@@ -22,7 +22,7 @@ import javax.xml.namespace.QName;
 
 import org.opensaml.core.criterion.EntityIdCriterion;
 import org.opensaml.messaging.context.MessageContext;
-import org.opensaml.messaging.handler.AbstractMessageHandler;
+import org.opensaml.messaging.handler.AbstractHttpServletRequestMessageHandler;
 import org.opensaml.messaging.handler.MessageHandlerException;
 import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
 import org.opensaml.saml.common.messaging.context.SAMLProtocolContext;
@@ -40,30 +40,23 @@ import org.slf4j.Logger;
 
 import com.google.common.base.Strings;
 
-import jakarta.servlet.http.HttpServletRequest;
-import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.annotation.constraint.NotLive;
 import net.shibboleth.shared.annotation.constraint.Unmodifiable;
 import net.shibboleth.shared.codec.Base64Support;
 import net.shibboleth.shared.codec.DecodingException;
 import net.shibboleth.shared.collection.CollectionSupport;
-import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.primitive.LoggerFactory;
-import net.shibboleth.shared.primitive.NonnullSupplier;
 import net.shibboleth.shared.resolver.CriteriaSet;
 
 /**
  * Base class for security-oriented message handlers which verify simple "blob" signatures computed 
  * over some components of a request.
  */
-public abstract class BaseSAMLSimpleSignatureSecurityHandler extends AbstractMessageHandler {
+public abstract class BaseSAMLSimpleSignatureSecurityHandler extends AbstractHttpServletRequestMessageHandler {
 
     /** Logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(BaseSAMLSimpleSignatureSecurityHandler.class);
-
-    /** The HttpServletRequest being processed. */
-    @NonnullAfterInit private NonnullSupplier<HttpServletRequest> httpServletRequestSupplier;
     
     /** The context representing the SAML peer entity. */
     @Nullable private SAMLPeerEntityContext peerContext;
@@ -89,48 +82,6 @@ public abstract class BaseSAMLSimpleSignatureSecurityHandler extends AbstractMes
         return trustEngine;
     }
 
-    /**
-     * Get the current HTTP request if available.
-     * 
-     * @return current HTTP request
-     */
-    @NonnullAfterInit public HttpServletRequest getHttpServletRequest() {
-        if (httpServletRequestSupplier == null) {
-            return null;
-        }
-        return httpServletRequestSupplier.get();
-    }
-
-    /**
-     * Get the supplier for  HTTP request if available.
-     *
-     * @return current HTTP request
-     */
-    @Nullable public NonnullSupplier<HttpServletRequest> getHttpServletRequestSupplier() {
-        return httpServletRequestSupplier;
-    }
-
-    /**
-     * Set the current HTTP request Supplier.
-     *
-     * @param requestSupplier Supplier for the current HTTP request
-     */
-    public void setHttpServletRequestSupplier(@Nullable final NonnullSupplier<HttpServletRequest> requestSupplier) {
-        checkSetterPreconditions();
-
-        httpServletRequestSupplier = requestSupplier;
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    protected void doInitialize() throws ComponentInitializationException {
-        super.doInitialize();
-        
-        if (getHttpServletRequest() == null) {
-            throw new ComponentInitializationException("HttpServletRequest cannot be null");
-        }
-    }
-
     /** {@inheritDoc} */
     @Override
     protected boolean doPreInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
@@ -162,7 +113,6 @@ public abstract class BaseSAMLSimpleSignatureSecurityHandler extends AbstractMes
         return true;
     }
 
-// Checkstyle: ReturnCount OFF
     /** {@inheritDoc} */
     @Override
     protected void doInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
@@ -195,7 +145,6 @@ public abstract class BaseSAMLSimpleSignatureSecurityHandler extends AbstractMes
 
         doEvaluate(signature, signedContent, sigAlg, messageContext);
     }
-// Checkstyle: ReturnCount OFF
 
     /**
      * Evaluate the simple signature based on information in the request and/or message context.
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/ReceivedEndpointSecurityHandler.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/ReceivedEndpointSecurityHandler.java
index cac0a2573..4ecf7d63e 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/ReceivedEndpointSecurityHandler.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/security/impl/ReceivedEndpointSecurityHandler.java
@@ -19,37 +19,30 @@ import javax.annotation.Nullable;
 
 import org.opensaml.messaging.MessageException;
 import org.opensaml.messaging.context.MessageContext;
-import org.opensaml.messaging.handler.AbstractMessageHandler;
+import org.opensaml.messaging.handler.AbstractHttpServletRequestMessageHandler;
 import org.opensaml.messaging.handler.MessageHandlerException;
 import org.opensaml.saml.common.binding.SAMLBindingSupport;
 import org.slf4j.Logger;
 
-import jakarta.servlet.http.HttpServletRequest;
-import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
-import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.net.URIComparator;
 import net.shibboleth.shared.net.URIException;
 import net.shibboleth.shared.net.impl.BasicURLComparator;
 import net.shibboleth.shared.primitive.LoggerFactory;
-import net.shibboleth.shared.primitive.NonnullSupplier;
 import net.shibboleth.shared.primitive.StringSupport;
 
 /**
  * Message handler which checks the validity of the SAML protocol message receiver 
  * endpoint against requirements indicated in the message.
  */
-public class ReceivedEndpointSecurityHandler extends AbstractMessageHandler {
+public class ReceivedEndpointSecurityHandler extends AbstractHttpServletRequestMessageHandler {
     
     /** Logger. */
     @Nonnull private Logger log = LoggerFactory.getLogger(ReceivedEndpointSecurityHandler.class);
     
     /** The URI comparator to use in performing the validation. */
     @Nonnull private URIComparator uriComparator;
-    
-    /** The HttpServletRequest being processed. */
-    @NonnullAfterInit private NonnullSupplier<HttpServletRequest> httpServletRequestSupplier;
 
     /** Constructor. */
     public ReceivedEndpointSecurityHandler() {
@@ -74,48 +67,6 @@ public class ReceivedEndpointSecurityHandler extends AbstractMessageHandler {
         checkSetterPreconditions();
         uriComparator = Constraint.isNotNull(comparator, "URIComparator cannot be null");
     }
-    
-    /**
-     * Get the HTTP servlet request being processed.
-     * 
-     * @return Returns the request.
-     */
-    @NonnullAfterInit public HttpServletRequest getHttpServletRequest() {
-        if (httpServletRequestSupplier == null) {
-            return null;
-        }
-        return httpServletRequestSupplier.get();
-    }
-
-    /**
-     * Get the supplier for  HTTP request if available.
-     *
-     * @return current HTTP request
-     */
-    @NonnullAfterInit public NonnullSupplier<HttpServletRequest> getHttpServletRequestSupplier() {
-        return httpServletRequestSupplier;
-    }
-
-    /**
-     * Set the current HTTP request Supplier.
-     *
-     * @param requestSupplier Supplier for the current HTTP request
-     */
-    public void setHttpServletRequestSupplier(@Nullable final NonnullSupplier<HttpServletRequest> requestSupplier) {
-        checkSetterPreconditions();
-
-        httpServletRequestSupplier = requestSupplier;
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    protected void doInitialize() throws ComponentInitializationException {
-        super.doInitialize();
-        
-        if (getHttpServletRequest() == null) {
-            throw new ComponentInitializationException("HttpServletRequest cannot be null");
-        }
-    }
 
     /** {@inheritDoc} */
     @Override

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


More information about the commits mailing list