[java-opensaml] branch main updated: IDP-2069 - Null Handling Task

Scott Cantor cantor.2 at osu.edu
Thu Apr 13 19:22:39 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=c26a2fceab319b40df44deb1d0678fd643ecf27a

The following commit(s) were added to refs/heads/main by this push:
     new c26a2fcea IDP-2069 - Null Handling Task
c26a2fcea is described below

commit c26a2fceab319b40df44deb1d0678fd643ecf27a
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Apr 13 15:22:36 2023 -0400

    IDP-2069 - Null Handling Task
    
    https://shibboleth.atlassian.net/browse/IDP-2069
    
    Clean up of some message handlers.
    Add init guard to AbstractMessageHandler.
    Fix improper setup of body handler in SOAP decoders.
---
 .../messaging/handler/AbstractMessageHandler.java  |  1 +
 .../binding/decoding/impl/HTTPSOAP11Decoder.java   | 23 +++++++++++++++-------
 .../binding/decoding/impl/HTTPSOAP11Decoder.java   | 23 +++++++++++++++-------
 .../binding/impl/AddECPResponseHeaderHandler.java  |  7 ++++---
 .../binding/impl/AddGeneratedKeyHeaderHandler.java | 11 ++++++++---
 .../impl/SAMLOutboundDestinationHandlerTest.java   |  5 ++++-
 .../impl/EndpointURLSchemeSecurityHandlerTest.java | 15 ++++++++++----
 .../binding/encoding/impl/HTTPPostEncoderTest.java |  1 +
 .../binding/encoding/impl/HTTPPostEncoderTest.java |  7 ++++---
 .../impl/HTTPPostSimpleSignEncoderTest.java        |  3 ++-
 .../impl/HTTPRedirectDeflateEncoderTest.java       |  4 ++++
 .../impl/AddConsentToResponseHandlerTest.java      |  6 +++---
 .../impl/AddECPResponseHeaderHandlerTest.java      | 16 +++++++--------
 .../impl/AddGeneratedKeyHeaderHandlerTest.java     | 15 +++++++++-----
 .../impl/AddRelayStateHeaderHandlerTest.java       | 13 ++++++++----
 .../AddRequestAuthenticatedHeaderHandlerTest.java  |  8 ++++----
 .../impl/ExtractConsentFromRequestHandlerTest.java |  6 +++---
 .../impl/ExtractProxiedRequestersHandlerTest.java  |  9 ++++++---
 .../decoder/http/impl/HTTPSOAP11Decoder.java       | 14 +++++++------
 19 files changed, 122 insertions(+), 65 deletions(-)

diff --git a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessageHandler.java b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessageHandler.java
index 52049f926..fe90bf03e 100644
--- a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessageHandler.java
+++ b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessageHandler.java
@@ -82,6 +82,7 @@ public abstract class AbstractMessageHandler extends AbstractInitializableCompon
     /** {@inheritDoc} */
     @Override public void invoke(@Nonnull final MessageContext messageContext)
             throws MessageHandlerException {
+        checkComponentActive();
         Constraint.isNotNull(messageContext, "Message context cannot be null");
 
         // The try/catch logic is designed to suppress a checked exception raised by
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml1/binding/decoding/impl/HTTPSOAP11Decoder.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml1/binding/decoding/impl/HTTPSOAP11Decoder.java
index d27c323a3..1e12d9cfb 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml1/binding/decoding/impl/HTTPSOAP11Decoder.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml1/binding/decoding/impl/HTTPSOAP11Decoder.java
@@ -22,6 +22,7 @@ import javax.annotation.Nullable;
 
 import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.messaging.decoder.MessageDecodingException;
+import org.opensaml.messaging.handler.MessageHandler;
 import org.opensaml.saml.common.SAMLObject;
 import org.opensaml.saml.common.binding.BindingDescriptor;
 import org.opensaml.saml.common.binding.decoding.SAMLMessageDecoder;
@@ -31,6 +32,7 @@ import org.opensaml.saml.common.xml.SAMLConstants;
 import org.slf4j.Logger;
 
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
@@ -44,13 +46,6 @@ public class HTTPSOAP11Decoder extends org.opensaml.soap.soap11.decoder.http.imp
 
     /** Optional {@link BindingDescriptor} to inject into {@link SAMLBindingContext} created. */
     @Nullable private BindingDescriptor bindingDescriptor;
-    
-    /**
-     * Constructor.
-     */
-    public HTTPSOAP11Decoder() {
-        setBodyHandler(new SAMLSOAPDecoderBodyHandler());
-    }
 
     /** {@inheritDoc} */
     @Nonnull @NotEmpty public String getBindingURI() {
@@ -75,6 +70,20 @@ public class HTTPSOAP11Decoder extends org.opensaml.soap.soap11.decoder.http.imp
         bindingDescriptor = descriptor;
     }
     
+    /** {@inheritDoc} */
+    @Override
+    protected void doInitialize() throws ComponentInitializationException {
+        
+        // Need to set this before calling base class.
+        if (getBodyHandler() == null) {
+            final MessageHandler handler = new SAMLSOAPDecoderBodyHandler();
+            handler.initialize();
+            setBodyHandler(handler);
+        }
+        
+        super.doInitialize();
+    }
+    
     /** {@inheritDoc} */
     protected void doDecode() throws MessageDecodingException {
         super.doDecode();
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPSOAP11Decoder.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPSOAP11Decoder.java
index 2cb9cb16e..410fabf08 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPSOAP11Decoder.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPSOAP11Decoder.java
@@ -22,6 +22,7 @@ import javax.annotation.Nullable;
 
 import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.messaging.decoder.MessageDecodingException;
+import org.opensaml.messaging.handler.MessageHandler;
 import org.opensaml.saml.common.SAMLObject;
 import org.opensaml.saml.common.binding.BindingDescriptor;
 import org.opensaml.saml.common.binding.decoding.SAMLMessageDecoder;
@@ -31,6 +32,7 @@ import org.opensaml.saml.common.xml.SAMLConstants;
 import org.slf4j.Logger;
 
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
@@ -45,13 +47,6 @@ public class HTTPSOAP11Decoder extends org.opensaml.soap.soap11.decoder.http.imp
     /** Optional {@link BindingDescriptor} to inject into {@link SAMLBindingContext} created. */
     @Nullable private BindingDescriptor bindingDescriptor;
     
-    /**
-     * Constructor.
-     */
-    public HTTPSOAP11Decoder() {
-        setBodyHandler(new SAMLSOAPDecoderBodyHandler());
-    }
-
     /** {@inheritDoc} */
     @Nonnull @NotEmpty public String getBindingURI() {
         return SAMLConstants.SAML2_SOAP11_BINDING_URI;
@@ -74,6 +69,20 @@ public class HTTPSOAP11Decoder extends org.opensaml.soap.soap11.decoder.http.imp
     public void setBindingDescriptor(@Nullable final BindingDescriptor descriptor) {
         bindingDescriptor = descriptor;
     }
+
+    /** {@inheritDoc} */
+    @Override
+    protected void doInitialize() throws ComponentInitializationException {
+        
+        // Need to set this before calling base class.
+        if (getBodyHandler() == null) {
+            final MessageHandler handler = new SAMLSOAPDecoderBodyHandler();
+            handler.initialize();
+            setBodyHandler(handler);
+        }
+        
+        super.doInitialize();
+    }
     
     /** {@inheritDoc} */
     protected void doDecode() throws MessageDecodingException {
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/impl/AddECPResponseHeaderHandler.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/impl/AddECPResponseHeaderHandler.java
index b1e20f5d6..0edbbace7 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/impl/AddECPResponseHeaderHandler.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/impl/AddECPResponseHeaderHandler.java
@@ -20,7 +20,6 @@ package org.opensaml.saml.saml2.binding.impl;
 import java.net.URI;
 
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 
 import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
 import org.opensaml.messaging.context.MessageContext;
@@ -34,7 +33,9 @@ import org.opensaml.soap.messaging.SOAPMessagingSupport;
 import org.opensaml.soap.soap11.ActorBearing;
 import org.opensaml.soap.util.SOAPSupport;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
+import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
  * MessageHandler to add the ECP {@link Response} header to an outgoing SOAP envelope.
@@ -45,7 +46,7 @@ public class AddECPResponseHeaderHandler extends AbstractMessageHandler {
     @Nonnull private final Logger log = LoggerFactory.getLogger(AddECPResponseHeaderHandler.class);
     
     /** The location to record in the header. */
-    @Nullable private URI assertionConsumerURL;
+    @NonnullBeforeExec private URI assertionConsumerURL;
 
     /** {@inheritDoc} */
     @Override
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/impl/AddGeneratedKeyHeaderHandler.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/impl/AddGeneratedKeyHeaderHandler.java
index e3fb087b7..abc648719 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/impl/AddGeneratedKeyHeaderHandler.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/impl/AddGeneratedKeyHeaderHandler.java
@@ -30,6 +30,7 @@ import org.opensaml.soap.messaging.SOAPMessagingSupport;
 import org.opensaml.soap.soap11.ActorBearing;
 import org.opensaml.soap.util.SOAPSupport;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
 import net.shibboleth.shared.codec.Base64Support;
 
 /**
@@ -37,6 +38,9 @@ import net.shibboleth.shared.codec.Base64Support;
  */
 public class AddGeneratedKeyHeaderHandler extends AbstractMessageHandler {
 
+    /** Session key to encode and include. */
+    @NonnullBeforeExec private byte[] sessionKey; 
+    
     /** {@inheritDoc} */
     @Override
     protected boolean doPreInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
@@ -46,7 +50,8 @@ public class AddGeneratedKeyHeaderHandler extends AbstractMessageHandler {
         }
 
         final ECPContext ctx = messageContext.getSubcontext(ECPContext.class);
-        if (ctx == null || ctx.getSessionKey() == null) {
+        sessionKey = ctx != null ? ctx.getSessionKey() : null;
+        if (sessionKey == null) {
             return false;
         }
         
@@ -61,8 +66,8 @@ public class AddGeneratedKeyHeaderHandler extends AbstractMessageHandler {
                         GeneratedKey.DEFAULT_ELEMENT_NAME);
         try {
             final GeneratedKey header = builder.buildObject();
-            header.setValue(Base64Support.encode(messageContext.getSubcontext(ECPContext.class).getSessionKey(),
-                    false));
+            assert sessionKey != null;
+            header.setValue(Base64Support.encode(sessionKey, false));
             SOAPSupport.addSOAP11ActorAttribute(header, ActorBearing.SOAP11_ACTOR_NEXT);      
             SOAPMessagingSupport.addHeaderBlock(messageContext, header);
         } catch (final Exception e) {
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/SAMLOutboundDestinationHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/SAMLOutboundDestinationHandlerTest.java
index 7658b4ca1..75deb7fc6 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/SAMLOutboundDestinationHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/SAMLOutboundDestinationHandlerTest.java
@@ -29,6 +29,8 @@ import org.testng.Assert;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import net.shibboleth.shared.component.ComponentInitializationException;
+
 /**
  * Test the {@link SAMLOutboundDestinationHandler}.
  */
@@ -39,7 +41,7 @@ public class SAMLOutboundDestinationHandlerTest extends XMLObjectBaseTestCase {
     private MessageContext messageContext;
     
     @BeforeMethod
-    public void setUp() {
+    public void setUp() throws ComponentInitializationException {
         SAMLObjectBuilder<AssertionConsumerService> endpointBuilder =
                 (SAMLObjectBuilder<AssertionConsumerService>) builderFactory.<AssertionConsumerService>ensureBuilder(
                         AssertionConsumerService.DEFAULT_ELEMENT_NAME);
@@ -47,6 +49,7 @@ public class SAMLOutboundDestinationHandlerTest extends XMLObjectBaseTestCase {
         samlEndpoint.setLocation("http://example.org");
         
         handler = new SAMLOutboundDestinationHandler();
+        handler.initialize();
         messageContext = new MessageContext();
         messageContext.ensureSubcontext(SAMLPeerEntityContext.class).
             ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/security/impl/EndpointURLSchemeSecurityHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/security/impl/EndpointURLSchemeSecurityHandlerTest.java
index 01ea32651..71a101cdf 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/security/impl/EndpointURLSchemeSecurityHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/security/impl/EndpointURLSchemeSecurityHandlerTest.java
@@ -25,14 +25,25 @@ import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
 import org.opensaml.saml.saml2.core.AuthnRequest;
 import org.opensaml.saml.saml2.core.Response;
 import org.opensaml.saml.saml2.metadata.AssertionConsumerService;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import net.shibboleth.shared.component.ComponentInitializationException;
+
 /**
  * Test the security handler which evaluates message context endpoint URL schemes.
  */
 @SuppressWarnings("javadoc")
 public class EndpointURLSchemeSecurityHandlerTest extends XMLObjectBaseTestCase {
     
+    private EndpointURLSchemeSecurityHandler handler;
+    
+    @BeforeMethod
+    public void setUp() throws ComponentInitializationException {
+        handler = new EndpointURLSchemeSecurityHandler();
+        handler.initialize();
+    }
+    
     @Test
     public void testValidRequestLocation() throws MessageHandlerException {
         AssertionConsumerService endpoint = buildXMLObject(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
@@ -42,7 +53,6 @@ public class EndpointURLSchemeSecurityHandlerTest extends XMLObjectBaseTestCase
         messageContext.setMessage(buildXMLObject(AuthnRequest.DEFAULT_ELEMENT_NAME));
         messageContext.ensureSubcontext(SAMLPeerEntityContext.class).ensureSubcontext(SAMLEndpointContext.class).setEndpoint(endpoint);
         
-        EndpointURLSchemeSecurityHandler handler = new EndpointURLSchemeSecurityHandler();
         handler.invoke(messageContext);
     }
     
@@ -55,7 +65,6 @@ public class EndpointURLSchemeSecurityHandlerTest extends XMLObjectBaseTestCase
         messageContext.setMessage(buildXMLObject(Response.DEFAULT_ELEMENT_NAME));
         messageContext.ensureSubcontext(SAMLPeerEntityContext.class).ensureSubcontext(SAMLEndpointContext.class).setEndpoint(endpoint);
         
-        EndpointURLSchemeSecurityHandler handler = new EndpointURLSchemeSecurityHandler();
         handler.invoke(messageContext);
     }
     
@@ -68,7 +77,6 @@ public class EndpointURLSchemeSecurityHandlerTest extends XMLObjectBaseTestCase
         messageContext.setMessage(buildXMLObject(AuthnRequest.DEFAULT_ELEMENT_NAME));
         messageContext.ensureSubcontext(SAMLPeerEntityContext.class).ensureSubcontext(SAMLEndpointContext.class).setEndpoint(endpoint);
         
-        EndpointURLSchemeSecurityHandler handler = new EndpointURLSchemeSecurityHandler();
         handler.invoke(messageContext);
     }
     
@@ -81,7 +89,6 @@ public class EndpointURLSchemeSecurityHandlerTest extends XMLObjectBaseTestCase
         messageContext.setMessage(buildXMLObject(Response.DEFAULT_ELEMENT_NAME));
         messageContext.ensureSubcontext(SAMLPeerEntityContext.class).ensureSubcontext(SAMLEndpointContext.class).setEndpoint(endpoint);
         
-        EndpointURLSchemeSecurityHandler handler = new EndpointURLSchemeSecurityHandler();
         handler.invoke(messageContext);
     }
 
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPPostEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPPostEncoderTest.java
index 71e044180..bad8d9cf4 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPPostEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPPostEncoderTest.java
@@ -89,6 +89,7 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
             .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
         
         final SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        handler.initialize();
         handler.invoke(messageContext);
         
         final MockHttpServletResponse response = new MockHttpServletResponse();
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java
index fe97c65db..17c6374ad 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java
@@ -109,7 +109,8 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
         messageContext.ensureSubcontext(SAMLPeerEntityContext.class)
             .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
         
-        SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        final SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        handler.initialize();
         handler.invoke(messageContext);
         
         MockHttpServletResponse response = new MockHttpServletResponse();
@@ -182,7 +183,6 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
     }
 
     @Test
-    @SuppressWarnings("unchecked")
     public void testRequestEncoding() throws Exception {
         SAMLObjectBuilder<AuthnRequest> requestBuilder =
                 (SAMLObjectBuilder<AuthnRequest>) builderFactory.<AuthnRequest>ensureBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
@@ -203,7 +203,8 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
         messageContext.ensureSubcontext(SAMLPeerEntityContext.class)
             .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
         
-        SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        final SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        handler.initialize();
         handler.invoke(messageContext);
         
         MockHttpServletResponse response = new MockHttpServletResponse();
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java
index cbf31cb46..82178844c 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java
@@ -121,7 +121,8 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
         messageContext.ensureSubcontext(SAMLPeerEntityContext.class)
             .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
         
-        SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        final SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        handler.initialize();
         handler.invoke(messageContext);
         
         MockHttpServletResponse response = new MockHttpServletResponse();
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPRedirectDeflateEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPRedirectDeflateEncoderTest.java
index 1f046bcd0..925049dba 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPRedirectDeflateEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPRedirectDeflateEncoderTest.java
@@ -95,6 +95,7 @@ public class HTTPRedirectDeflateEncoderTest extends XMLObjectBaseTestCase {
             .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
         
         final SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        handler.initialize();
         handler.invoke(messageContext);
         
         final MockHttpServletResponse response = new MockHttpServletResponse();
@@ -172,6 +173,7 @@ public class HTTPRedirectDeflateEncoderTest extends XMLObjectBaseTestCase {
             .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
         
         final SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        handler.initialize();
         handler.invoke(messageContext);
         
         final MockHttpServletResponse response = new MockHttpServletResponse();
@@ -253,6 +255,7 @@ public class HTTPRedirectDeflateEncoderTest extends XMLObjectBaseTestCase {
             .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
         
         final SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        handler.initialize();
         handler.invoke(messageContext);
         
         final MockHttpServletResponse response = new MockHttpServletResponse();
@@ -344,6 +347,7 @@ public class HTTPRedirectDeflateEncoderTest extends XMLObjectBaseTestCase {
         messageContext.ensureSubcontext(SecurityParametersContext.class).setSignatureSigningParameters(signingParameters);
         
         final SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
+        handler.initialize();
         handler.invoke(messageContext);
         
         final MockHttpServletResponse response = new MockHttpServletResponse();
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddConsentToResponseHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddConsentToResponseHandlerTest.java
index 4ed0efb49..27583c068 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddConsentToResponseHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddConsentToResponseHandlerTest.java
@@ -57,13 +57,13 @@ public class AddConsentToResponseHandlerTest extends OpenSAMLInitBaseTestCase {
     @Test public void testSuccess() throws MessageHandlerException, ComponentInitializationException {
         final MessageContext messageCtx = new MessageContext();
         messageCtx.setMessage(SAML2ActionTestingSupport.buildResponse());
-        messageCtx.getSubcontext(SAMLConsentContext.class, true).setConsent(StatusResponseType.EXPLICIT_CONSENT);
+        messageCtx.ensureSubcontext(SAMLConsentContext.class).setConsent(StatusResponseType.EXPLICIT_CONSENT);
         
         final AddConsentToResponseHandler handler = new AddConsentToResponseHandler();
         handler.initialize();
         
         handler.invoke(messageCtx);
-        Assert.assertEquals(((StatusResponseType) messageCtx.getMessage()).getConsent(), StatusResponseType.EXPLICIT_CONSENT);
+        Assert.assertEquals(((StatusResponseType) messageCtx.ensureMessage()).getConsent(), StatusResponseType.EXPLICIT_CONSENT);
     }
     
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddECPResponseHeaderHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddECPResponseHeaderHandlerTest.java
index 45fb4c8af..49373b54a 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddECPResponseHeaderHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddECPResponseHeaderHandlerTest.java
@@ -76,9 +76,9 @@ public class AddECPResponseHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
         final Endpoint ep = XMLObjectProviderRegistrySupport.getBuilderFactory().<AssertionConsumerService>ensureBuilder(
                 AssertionConsumerService.DEFAULT_ELEMENT_NAME).buildObject(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
         ep.setLocation("foo");
-        messageCtx.getSubcontext(
-                SAMLPeerEntityContext.class, true).getSubcontext(
-                        SAMLEndpointContext.class, true).setEndpoint(ep);
+        messageCtx.ensureSubcontext(
+                SAMLPeerEntityContext.class).ensureSubcontext(
+                        SAMLEndpointContext.class).setEndpoint(ep);
 
         final AddECPResponseHeaderHandler handler = new AddECPResponseHeaderHandler();
         handler.initialize();
@@ -98,14 +98,14 @@ public class AddECPResponseHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
 
         final MessageContext messageCtx = new MessageContext();
         messageCtx.setMessage(SAML2ActionTestingSupport.buildResponse());
-        messageCtx.getSubcontext(SOAP11Context.class, true).setEnvelope(env);
+        messageCtx.ensureSubcontext(SOAP11Context.class).setEnvelope(env);
         
         final Endpoint ep = XMLObjectProviderRegistrySupport.getBuilderFactory().<AssertionConsumerService>ensureBuilder(
                 AssertionConsumerService.DEFAULT_ELEMENT_NAME).buildObject(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
         ep.setLocation("foo");
-        messageCtx.getSubcontext(
-                SAMLPeerEntityContext.class, true).getSubcontext(
-                        SAMLEndpointContext.class, true).setEndpoint(ep);
+        messageCtx.ensureSubcontext(
+                SAMLPeerEntityContext.class).ensureSubcontext(
+                        SAMLEndpointContext.class).setEndpoint(ep);
         
         final AddECPResponseHeaderHandler handler = new AddECPResponseHeaderHandler();
         handler.initialize();
@@ -119,4 +119,4 @@ public class AddECPResponseHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
         Assert.assertEquals(((Response) headers.get(0)).getAssertionConsumerServiceURL(), "foo");
     }
     
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddGeneratedKeyHeaderHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddGeneratedKeyHeaderHandlerTest.java
index 9d045536c..3946853d2 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddGeneratedKeyHeaderHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddGeneratedKeyHeaderHandlerTest.java
@@ -47,6 +47,11 @@ public class AddGeneratedKeyHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
     
     private AddGeneratedKeyHeaderHandler handler;
     
+    /**
+     * Test set up.
+     * 
+     * @throws ComponentInitializationException
+     */
     @BeforeMethod public void setUp() throws ComponentInitializationException {
         messageCtx = new MessageContext();
         handler = new AddGeneratedKeyHeaderHandler();
@@ -66,7 +71,7 @@ public class AddGeneratedKeyHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
                 SOAPMessagingSupport.getHeaderBlock(messageCtx, GeneratedKey.DEFAULT_ELEMENT_NAME, null, true);
         Assert.assertTrue(headers.isEmpty());
         
-        messageCtx.getSubcontext(ECPContext.class, true);
+        messageCtx.ensureSubcontext(ECPContext.class);
         
         handler.invoke(messageCtx);
         
@@ -83,7 +88,7 @@ public class AddGeneratedKeyHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
     @Test(expectedExceptions=MessageHandlerException.class)
     public void testMissingEnvelope() throws MessageHandlerException, NoSuchAlgorithmException {
 
-        messageCtx.getSubcontext(ECPContext.class, true).setSessionKey(
+        messageCtx.ensureSubcontext(ECPContext.class).setSessionKey(
                 SecureRandom.getInstance("SHA1prng").generateSeed(16));
         
         handler.invoke(messageCtx);
@@ -100,11 +105,11 @@ public class AddGeneratedKeyHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
 
         final byte[] key = new byte[32];
         SecureRandom.getInstance("SHA1prng").nextBytes(key);
-        messageCtx.getSubcontext(ECPContext.class, true).setSessionKey(key);
+        messageCtx.ensureSubcontext(ECPContext.class).setSessionKey(key);
 
         final Envelope env = XMLObjectProviderRegistrySupport.getBuilderFactory().<Envelope>ensureBuilder(
                 Envelope.DEFAULT_ELEMENT_NAME).buildObject(Envelope.DEFAULT_ELEMENT_NAME);
-        messageCtx.getSubcontext(SOAP11Context.class, true).setEnvelope(env);
+        messageCtx.ensureSubcontext(SOAP11Context.class).setEnvelope(env);
         
         handler.invoke(messageCtx);
         
@@ -114,4 +119,4 @@ public class AddGeneratedKeyHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
         Assert.assertEquals(((XSBase64Binary) headers.get(0)).getValue(), Base64Support.encode(key, false));
     }
     
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddRelayStateHeaderHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddRelayStateHeaderHandlerTest.java
index 06bb30103..f39ab3f25 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddRelayStateHeaderHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddRelayStateHeaderHandlerTest.java
@@ -42,6 +42,11 @@ public class AddRelayStateHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
     
     private AddRelayStateHeaderHandler handler;
     
+    /**
+     * Test set up.
+     * 
+     * @throws ComponentInitializationException
+     */
     @BeforeMethod public void setUp() throws ComponentInitializationException {
         messageCtx = new MessageContext();
         handler = new AddRelayStateHeaderHandler();
@@ -71,7 +76,7 @@ public class AddRelayStateHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
     @Test(expectedExceptions=MessageHandlerException.class)
     public void testMissingEnvelope() throws MessageHandlerException {
 
-        messageCtx.getSubcontext(SAMLBindingContext.class, true).setRelayState("foo");
+        messageCtx.ensureSubcontext(SAMLBindingContext.class).setRelayState("foo");
         
         handler.invoke(messageCtx);
     }
@@ -85,9 +90,9 @@ public class AddRelayStateHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
 
         final Envelope env = XMLObjectProviderRegistrySupport.getBuilderFactory().<Envelope>ensureBuilder(
                 Envelope.DEFAULT_ELEMENT_NAME).buildObject(Envelope.DEFAULT_ELEMENT_NAME);
-        messageCtx.getSubcontext(SOAP11Context.class, true).setEnvelope(env);
+        messageCtx.ensureSubcontext(SOAP11Context.class).setEnvelope(env);
         
-        messageCtx.getSubcontext(SAMLBindingContext.class, true).setRelayState("foo");
+        messageCtx.ensureSubcontext(SAMLBindingContext.class).setRelayState("foo");
         
         handler.invoke(messageCtx);
         
@@ -98,4 +103,4 @@ public class AddRelayStateHeaderHandlerTest extends OpenSAMLInitBaseTestCase {
         Assert.assertEquals(((RelayState) headers.get(0)).getValue(), "foo");
     }
     
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddRequestAuthenticatedHeaderHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddRequestAuthenticatedHeaderHandlerTest.java
index 8855e2941..0a91a985c 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddRequestAuthenticatedHeaderHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/AddRequestAuthenticatedHeaderHandlerTest.java
@@ -55,7 +55,7 @@ public class AddRequestAuthenticatedHeaderHandlerTest extends OpenSAMLInitBaseTe
                 SOAPMessagingSupport.getHeaderBlock(messageCtx, RequestAuthenticated.DEFAULT_ELEMENT_NAME, null, true);
         Assert.assertTrue(headers.isEmpty());
         
-        messageCtx.getSubcontext(ECPContext.class, true).setRequestAuthenticated(false);
+        messageCtx.ensureSubcontext(ECPContext.class).setRequestAuthenticated(false);
         
         handler.invoke(messageCtx);
         
@@ -72,7 +72,7 @@ public class AddRequestAuthenticatedHeaderHandlerTest extends OpenSAMLInitBaseTe
     @Test(expectedExceptions=MessageHandlerException.class)
     public void testMissingEnvelope() throws MessageHandlerException, ComponentInitializationException {
         final MessageContext messageCtx = new MessageContext();
-        messageCtx.getSubcontext(ECPContext.class, true).setRequestAuthenticated(true);
+        messageCtx.ensureSubcontext(ECPContext.class).setRequestAuthenticated(true);
 
         final AddRequestAuthenticatedHeaderHandler handler = new AddRequestAuthenticatedHeaderHandler();
         handler.initialize();
@@ -88,11 +88,11 @@ public class AddRequestAuthenticatedHeaderHandlerTest extends OpenSAMLInitBaseTe
      */
     @Test public void testSuccess() throws MessageHandlerException, ComponentInitializationException {
         final MessageContext messageCtx = new MessageContext();
-        messageCtx.getSubcontext(ECPContext.class, true).setRequestAuthenticated(true);
+        messageCtx.ensureSubcontext(ECPContext.class).setRequestAuthenticated(true);
 
         final Envelope env = XMLObjectProviderRegistrySupport.getBuilderFactory().<Envelope>ensureBuilder(
                 Envelope.DEFAULT_ELEMENT_NAME).buildObject(Envelope.DEFAULT_ELEMENT_NAME);
-        messageCtx.getSubcontext(SOAP11Context.class, true).setEnvelope(env);
+        messageCtx.ensureSubcontext(SOAP11Context.class).setEnvelope(env);
         
         final AddRequestAuthenticatedHeaderHandler handler = new AddRequestAuthenticatedHeaderHandler();
         handler.initialize();
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/ExtractConsentFromRequestHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/ExtractConsentFromRequestHandlerTest.java
index c1ab0dcd5..2babfe479 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/ExtractConsentFromRequestHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/ExtractConsentFromRequestHandlerTest.java
@@ -57,14 +57,14 @@ public class ExtractConsentFromRequestHandlerTest extends OpenSAMLInitBaseTestCa
     @Test public void testSuccess() throws MessageHandlerException, ComponentInitializationException {
         final MessageContext messageCtx = new MessageContext();
         messageCtx.setMessage(SAML2ActionTestingSupport.buildAttributeQueryRequest(null));
-        ((RequestAbstractType) messageCtx.getMessage()).setConsent(RequestAbstractType.IMPLICIT_CONSENT);
+        ((RequestAbstractType) messageCtx.ensureMessage()).setConsent(RequestAbstractType.IMPLICIT_CONSENT);
         
         final ExtractConsentFromRequestHandler handler = new ExtractConsentFromRequestHandler();
         handler.initialize();
         
         handler.invoke(messageCtx);
-        Assert.assertEquals(messageCtx.getSubcontext(SAMLConsentContext.class).getConsent(),
+        Assert.assertEquals(messageCtx.ensureSubcontext(SAMLConsentContext.class).getConsent(),
                 StatusResponseType.IMPLICIT_CONSENT);
     }
     
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/ExtractProxiedRequestersHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/ExtractProxiedRequestersHandlerTest.java
index d55a09822..3625c3685 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/ExtractProxiedRequestersHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/impl/ExtractProxiedRequestersHandlerTest.java
@@ -42,6 +42,9 @@ public class ExtractProxiedRequestersHandlerTest extends OpenSAMLInitBaseTestCas
     
     SAMLObjectBuilder<RequesterID> requesterIDBuilder;
     
+    /**
+     * Test set up.
+     */
     @BeforeClass public void setUp() {
         scopingBuilder = (SAMLObjectBuilder<Scoping>)
                 XMLObjectProviderRegistrySupport.getBuilderFactory().<Scoping>ensureBuilder(
@@ -85,7 +88,7 @@ public class ExtractProxiedRequestersHandlerTest extends OpenSAMLInitBaseTestCas
         two.setURI("two");
         scoping.getRequesterIDs().addAll(Arrays.asList(one, two));
         
-        ((AuthnRequest) messageCtx.getMessage()).setScoping(scoping);
+        ((AuthnRequest) messageCtx.ensureMessage()).setScoping(scoping);
         
         final ExtractProxiedRequestersHandler handler = new ExtractProxiedRequestersHandler();
         handler.initialize();
@@ -93,11 +96,11 @@ public class ExtractProxiedRequestersHandlerTest extends OpenSAMLInitBaseTestCas
         handler.invoke(messageCtx);
         
         final ProxiedRequesterContext ctx = messageCtx.getSubcontext(ProxiedRequesterContext.class);
-        Assert.assertNotNull(ctx);
+        assert ctx != null;
         Assert.assertEquals(ctx.getRequesters().size(), 2);
         Assert.assertTrue(ctx.getRequesters().contains("one"));
         Assert.assertTrue(ctx.getRequesters().contains("two"));
         Assert.assertFalse(ctx.getRequesters().contains("foo"));
     }
     
-}
+}
\ No newline at end of file
diff --git a/opensaml-soap-impl/src/main/java/org/opensaml/soap/soap11/decoder/http/impl/HTTPSOAP11Decoder.java b/opensaml-soap-impl/src/main/java/org/opensaml/soap/soap11/decoder/http/impl/HTTPSOAP11Decoder.java
index 890ddda44..6d882192b 100644
--- a/opensaml-soap-impl/src/main/java/org/opensaml/soap/soap11/decoder/http/impl/HTTPSOAP11Decoder.java
+++ b/opensaml-soap-impl/src/main/java/org/opensaml/soap/soap11/decoder/http/impl/HTTPSOAP11Decoder.java
@@ -33,12 +33,14 @@ import org.opensaml.messaging.handler.MessageHandlerException;
 import org.opensaml.soap.messaging.context.SOAP11Context;
 import org.opensaml.soap.soap11.Envelope;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.net.MediaType;
 
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.servlet.HttpServletSupport;
 
 import jakarta.servlet.http.HttpServletRequest;
@@ -64,17 +66,17 @@ public class HTTPSOAP11Decoder extends BaseHttpServletRequestXMLMessageDecoder {
             CollectionSupport.singleton(MediaType.create("text", "xml"));
     
     /** Class logger. */
-    private final Logger log = LoggerFactory.getLogger(HTTPSOAP11Decoder.class);
+    @Nonnull private final Logger log = LoggerFactory.getLogger(HTTPSOAP11Decoder.class);
     
     /** Message handler to use in processing the message body. */
-    private MessageHandler bodyHandler;
+    @NonnullAfterInit private MessageHandler bodyHandler;
     
     /**
      * Get the configured body handler MessageHandler.
      * 
      * @return Returns the bodyHandler.
      */
-    public MessageHandler getBodyHandler() {
+    @NonnullAfterInit public MessageHandler getBodyHandler() {
         return bodyHandler;
     }
 
@@ -83,8 +85,8 @@ public class HTTPSOAP11Decoder extends BaseHttpServletRequestXMLMessageDecoder {
      * 
      * @param newBodyHandler The bodyHandler to set.
      */
-    public void setBodyHandler(final MessageHandler newBodyHandler) {
-        bodyHandler = newBodyHandler;
+    public void setBodyHandler(@Nonnull final MessageHandler newBodyHandler) {
+        bodyHandler = Constraint.isNotNull(newBodyHandler, "Body MessageHandler cannot be null");
     }
 
     /** {@inheritDoc} */

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


More information about the commits mailing list