[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 14:18:59 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=672de3819042e3b965ca5889a1e7a04f9420e645

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

commit 672de3819042e3b965ca5889a1e7a04f9420e645
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Oct 2 10:18:52 2024 -0400

    OSJ-418 - Allow classes to skip servlet request check at init time
    
    https://shibboleth.atlassian.net/browse/OSJ-418
    
    Enhanced message decoder base class with new flag.
---
 .../AbstractHttpServletRequestMessageDecoder.java  | 42 ++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 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 96481e7c5..bea7863c5 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
@@ -29,9 +29,45 @@ import net.shibboleth.shared.primitive.NonnullSupplier;
 public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractMessageDecoder
         implements HttpServletRequestMessageDecoder {
 
+    /** Flag for whether to check for servlet request during init. */
+    private boolean checkDuringInit;
+    
     /** Current HTTP request, if available. */
     @NonnullAfterInit private NonnullSupplier<HttpServletRequest> httpServletRequestSupplier;
 
+    /** Constructor. */
+    public AbstractHttpServletRequestMessageDecoder() {
+        checkDuringInit = true;
+    }
+    
+    /**
+     * Get whether {{@link #initialize()} should throw an exception if {@link #getHttpServletRequest()}
+     * returns null.
+     * 
+     * @return whether a null request should fail initialization
+     * 
+     * @since 5.2.0
+     */
+    public boolean isCheckDuringInit() {
+        return checkDuringInit;
+    }
+    
+    /**
+     * Set whether {{@link #initialize()} should throw an exception if {@link #getHttpServletRequest()}
+     * returns null.
+     * 
+     * <p>Defaults to true.</p>
+     * 
+     * @param flag
+     * 
+     * @since 5.2.0
+     */
+    public void setCheckDuringInit(final boolean flag) {
+        checkSetterPreconditions();
+        
+        checkDuringInit = flag;
+    }
+    
     /** {@inheritDoc} */
     @NonnullAfterInit public HttpServletRequest getHttpServletRequest() {
         if (httpServletRequestSupplier != null) {
@@ -42,7 +78,9 @@ public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractM
     }
 
     /**
-     * Get the supplier for  HTTP request if available.
+     * 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
      */
@@ -62,7 +100,7 @@ public abstract class AbstractHttpServletRequestMessageDecoder extends AbstractM
     protected void doInitialize() throws ComponentInitializationException {
         super.doInitialize();
 
-        if (getHttpServletRequest() == null) {
+        if (isCheckDuringInit() && getHttpServletRequest() == null) {
             throw new ComponentInitializationException("HTTP Servlet request cannot be null");
         }
     }

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


More information about the commits mailing list