Always throw a descriptive exception instead of returning nothing.
authorcantor <cantor@fb386ef7-a10c-0410-8ebf-fd3f8e989ab0>
Mon, 9 Jul 2007 17:10:06 +0000 (17:10 +0000)
committercantor <cantor@fb386ef7-a10c-0410-8ebf-fd3f8e989ab0>
Mon, 9 Jul 2007 17:10:06 +0000 (17:10 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-opensaml2/trunk@282 fb386ef7-a10c-0410-8ebf-fd3f8e989ab0

saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp
saml/saml1/binding/impl/SAML1POSTDecoder.cpp
saml/saml1/binding/impl/SAML1SOAPDecoder.cpp
saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp
saml/saml2/binding/impl/SAML2POSTDecoder.cpp
saml/saml2/binding/impl/SAML2RedirectDecoder.cpp
saml/saml2/binding/impl/SAML2SOAPDecoder.cpp

index 3a5fbbf..ee5278a 100644 (file)
@@ -75,16 +75,14 @@ XMLObject* SAML1ArtifactDecoder::decode(
 
     log.debug("validating input");
     const HTTPRequest* httpRequest=dynamic_cast<const HTTPRequest*>(&genericRequest);
-    if (!httpRequest) {
-        log.error("unable to cast request to HTTPRequest type");
-        return NULL;
-    }
+    if (!httpRequest)
+        throw BindingException("Unable to cast request object to HTTPRequest type.");
     if (strcmp(httpRequest->getMethod(),"GET"))
-        return NULL;
+        throw BindingException("Invalid HTTP method ($1).", params(1, httpRequest->getMethod()));
     vector<const char*> SAMLart;
     const char* TARGET = httpRequest->getParameter("TARGET");
     if (httpRequest->getParameters("SAMLart", SAMLart)==0 || !TARGET)
-        return NULL;
+        throw BindingException("Request missing SAMLart or TARGET parameters.");
     relayState = TARGET;
 
     if (!m_artifactResolver || !policy.getMetadataProvider() || !policy.getRole())
index bf3395e..ef39d62 100644 (file)
@@ -77,16 +77,14 @@ XMLObject* SAML1POSTDecoder::decode(
 
     log.debug("validating input");
     const HTTPRequest* httpRequest=dynamic_cast<const HTTPRequest*>(&genericRequest);
-    if (!httpRequest) {
-        log.error("unable to cast request to HTTPRequest type");
-        return NULL;
-    }
+    if (!httpRequest)
+        throw BindingException("Unable to cast request object to HTTPRequest type.");
     if (strcmp(httpRequest->getMethod(),"POST"))
-        return NULL;
+        throw BindingException("Invalid HTTP method ($1).", params(1, httpRequest->getMethod()));
     const char* samlResponse = httpRequest->getParameter("SAMLResponse");
     const char* TARGET = httpRequest->getParameter("TARGET");
     if (!samlResponse || !TARGET)
-        return NULL;
+        throw BindingException("Request missing SAMLResponse or TARGET parameters.");
     relayState = TARGET;
 
     // Decode the base64 into SAML.
index eff4034..f928f8b 100644 (file)
@@ -78,14 +78,12 @@ XMLObject* SAML1SOAPDecoder::decode(
     string s = genericRequest.getContentType();
     if (s.find("text/xml") == string::npos) {
         log.warn("ignoring incorrect content type (%s)", s.c_str() ? s.c_str() : "none");
-        return NULL;
+        throw BindingException("Invalid content type for SOAP message.");
     }
 
     const char* data = genericRequest.getRequestBody();
-    if (!data) {
-        log.warn("empty request body");
-        return NULL;
-    }
+    if (!data)
+        throw BindingException("SOAP message had an empty request body.");
     istringstream is(data);
     
     // Parse and bind the document into an XMLObject.
index b05e3e2..17a22ec 100644 (file)
@@ -76,13 +76,11 @@ XMLObject* SAML2ArtifactDecoder::decode(
 
     log.debug("validating input");
     const HTTPRequest* httpRequest=dynamic_cast<const HTTPRequest*>(&genericRequest);
-    if (!httpRequest) {
-        log.error("unable to cast request to HTTPRequest type");
-        return NULL;
-    }
+    if (!httpRequest)
+        throw BindingException("Unable to cast request object to HTTPRequest type.");
     const char* SAMLart = httpRequest->getParameter("SAMLart");
     if (!SAMLart)
-        return NULL;
+        throw BindingException("Request missing SAMLart parameter.");
     const char* state = httpRequest->getParameter("RelayState");
     if (state)
         relayState = state;
index 692950b..988aa0f 100644 (file)
@@ -76,17 +76,15 @@ XMLObject* SAML2POSTDecoder::decode(
 
     log.debug("validating input");
     const HTTPRequest* httpRequest=dynamic_cast<const HTTPRequest*>(&genericRequest);
-    if (!httpRequest) {
-        log.error("unable to cast request to HTTPRequest type");
-        return NULL;
-    }
+    if (!httpRequest)
+        throw BindingException("Unable to cast request object to HTTPRequest type.");
     if (strcmp(httpRequest->getMethod(),"POST"))
-        return NULL;
+        throw BindingException("Invalid HTTP method ($1).", params(1, httpRequest->getMethod()));
     const char* msg = httpRequest->getParameter("SAMLResponse");
     if (!msg)
         msg = httpRequest->getParameter("SAMLRequest");
     if (!msg)
-        return NULL;
+        throw BindingException("Request missing SAMLRequest or SAMLResponse parameter.");
     const char* state = httpRequest->getParameter("RelayState");
     if (state)
         relayState = state;
index 08f54d8..5927613 100644 (file)
@@ -78,17 +78,15 @@ XMLObject* SAML2RedirectDecoder::decode(
 
     log.debug("validating input");
     const HTTPRequest* httpRequest=dynamic_cast<const HTTPRequest*>(&genericRequest);
-    if (!httpRequest) {
-        log.error("unable to cast request to HTTPRequest type");
-        return NULL;
-    }
+    if (!httpRequest)
+        throw BindingException("Unable to cast request object to HTTPRequest type.");
     if (strcmp(httpRequest->getMethod(),"GET"))
-        return NULL;
+        throw BindingException("Invalid HTTP method ($1).", params(1, httpRequest->getMethod()));
     const char* msg = httpRequest->getParameter("SAMLResponse");
     if (!msg)
         msg = httpRequest->getParameter("SAMLRequest");
     if (!msg)
-        return NULL;
+        throw BindingException("Request missing SAMLRequest or SAMLResponse parameter.");
     const char* state = httpRequest->getParameter("RelayState");
     if (state)
         relayState = state;
@@ -97,7 +95,7 @@ XMLObject* SAML2RedirectDecoder::decode(
     state = httpRequest->getParameter("SAMLEncoding");
     if (state && strcmp(state,samlconstants::SAML20_BINDING_URL_ENCODING_DEFLATE)) {
         log.warn("SAMLEncoding (%s) was not recognized", state);
-        return NULL;
+        throw BindingException("Unsupported SAMLEncoding value.");
     }
 
     // Decode the compressed message into SAML. First we base64-decode it.
index 3757039..2d9d22f 100644 (file)
@@ -80,14 +80,12 @@ XMLObject* SAML2SOAPDecoder::decode(
     string s = genericRequest.getContentType();
     if (s.find("text/xml") == string::npos) {
         log.warn("ignoring incorrect content type (%s)", s.c_str() ? s.c_str() : "none");
-        return NULL;
+        throw BindingException("Invalid content type for SOAP message.");
     }
 
     const char* data = genericRequest.getRequestBody();
-    if (!data) {
-        log.warn("empty request body");
-        return NULL;
-    }
+    if (!data)
+        throw BindingException("SOAP message had an empty request body.");
     istringstream is(data);
     
     // Parse and bind the document into an XMLObject.