[java-opensaml] 11/24: OSJ-190: SAML 2 Redirect binding decoder should handle SAMLEncoding parameter

Brent Putman putmanb at georgetown.edu
Wed Sep 27 16:46:05 EDT 2017


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

putmanb pushed a commit to branch maint-3.3
in repository java-opensaml.

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

commit 9e15d83b17db882ad5a7083be60a60ff3ad317eb
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Fri Feb 3 23:29:33 2017 +0000

    OSJ-190: SAML 2 Redirect binding decoder should handle SAMLEncoding parameter
---
 .../opensaml/saml/common/xml/SAMLConstants.java    |  4 +++
 .../decoding/impl/HTTPRedirectDeflateDecoder.java  |  6 ++++
 .../impl/HTTPRedirectDeflateDecoderTest.java       | 37 +++++++++++++++++++---
 3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLConstants.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLConstants.java
index a9d6af4..0ed3bec 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLConstants.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLConstants.java
@@ -320,6 +320,10 @@ public final class SAMLConstants {
     
     /** SAML 2.0 Metadata Profile for Algorithm Support QName prefix. */
     public static final String SAML20ALG_PREFIX = "alg";
+    
+    /** URI for SAML 2 binding URL encoding DEFLATE method. */
+    public static final String SAML2_BINDING_URL_ENCODING_DEFLATE_URI = 
+            "urn:oasis:names:tc:SAML:2.0:bindings:URL-Encoding:DEFLATE";
 
     /** Constructor. */
     private SAMLConstants() {
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoder.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoder.java
index 684e3e0..e96806d 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoder.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoder.java
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
 
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.messaging.decoder.MessageDecodingException;
@@ -88,6 +89,11 @@ public class HTTPRedirectDeflateDecoder extends BaseHttpServletRequestXMLMessage
         if (!"GET".equalsIgnoreCase(request.getMethod())) {
             throw new MessageDecodingException("This message decoder only supports the HTTP GET method");
         }
+        
+        String samlEncoding = StringSupport.trimOrNull(request.getParameter("SAMLEncoding"));
+        if (samlEncoding != null && !SAMLConstants.SAML2_BINDING_URL_ENCODING_DEFLATE_URI.equals(samlEncoding)) {
+            throw new MessageDecodingException("Request indicated an unsupported SAMLEncoding: " + samlEncoding);
+        }
 
         String relayState = request.getParameter("RelayState");
         log.debug("Decoded RelayState: {}", relayState);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoderTest.java
index 65a3928..c4db8d3 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/decoding/impl/HTTPRedirectDeflateDecoderTest.java
@@ -24,9 +24,6 @@ import java.net.URL;
 import java.util.zip.Deflater;
 import java.util.zip.DeflaterOutputStream;
 
-import net.shibboleth.utilities.java.support.codec.Base64Support;
-import net.shibboleth.utilities.java.support.xml.SerializeSupport;
-
 import org.opensaml.core.xml.XMLObjectBaseTestCase;
 import org.opensaml.core.xml.io.MarshallingException;
 import org.opensaml.messaging.context.MessageContext;
@@ -34,7 +31,6 @@ import org.opensaml.messaging.decoder.MessageDecodingException;
 import org.opensaml.messaging.encoder.MessageEncodingException;
 import org.opensaml.saml.common.SAMLObject;
 import org.opensaml.saml.common.binding.SAMLBindingSupport;
-import org.opensaml.saml.saml2.binding.decoding.impl.HTTPRedirectDeflateDecoder;
 import org.opensaml.saml.saml2.core.AuthnRequest;
 import org.opensaml.saml.saml2.core.RequestAbstractType;
 import org.opensaml.saml.saml2.core.Response;
@@ -43,6 +39,9 @@ import org.testng.Assert;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.xml.SerializeSupport;
+
 /**
  *
  */
@@ -98,6 +97,36 @@ public class HTTPRedirectDeflateDecoderTest extends XMLObjectBaseTestCase {
         Assert.assertEquals(SAMLBindingSupport.getRelayState(messageContext), expectedRelayValue);
     }
 
+    @Test
+    public void testExplicitDefaultSAMLEncoding() 
+            throws MessageDecodingException, MessageEncodingException, MarshallingException {
+        AuthnRequest samlRequest =
+                (AuthnRequest) unmarshallElement("/org/opensaml/saml/saml2/binding/AuthnRequest.xml");
+        samlRequest.setDestination(null);
+
+        httpRequest.setParameter("SAMLRequest", encodeMessage(samlRequest));
+        httpRequest.setParameter("SAMLEncoding", "urn:oasis:names:tc:SAML:2.0:bindings:URL-Encoding:DEFLATE");
+
+        decoder.decode();
+        MessageContext<SAMLObject> messageContext = decoder.getMessageContext();
+
+        Assert.assertTrue(messageContext.getMessage() instanceof RequestAbstractType);
+        Assert.assertEquals(SAMLBindingSupport.getRelayState(messageContext), expectedRelayValue);
+    }
+
+    @Test(expectedExceptions=MessageDecodingException.class)
+    public void testUnsupportedSAMLEncoding() 
+            throws MessageDecodingException, MessageEncodingException, MarshallingException {
+        AuthnRequest samlRequest =
+                (AuthnRequest) unmarshallElement("/org/opensaml/saml/saml2/binding/AuthnRequest.xml");
+        samlRequest.setDestination(null);
+
+        httpRequest.setParameter("SAMLRequest", encodeMessage(samlRequest));
+        httpRequest.setParameter("SAMLEncoding", "urn:test:encoding:bogus");
+
+        decoder.decode();
+    }
+
     private void populateRequestURL(MockHttpServletRequest request, String requestURL) {
         URL url = null;
         try {

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


More information about the commits mailing list