From 98b9be4dacac1d9a8729906473e35fc904676d12 Mon Sep 17 00:00:00 2001 From: cantor Date: Mon, 9 Jul 2007 17:10:06 +0000 Subject: [PATCH] Always throw a descriptive exception instead of returning nothing. git-svn-id: https://svn.middleware.georgetown.edu/cpp-opensaml2/trunk@282 fb386ef7-a10c-0410-8ebf-fd3f8e989ab0 --- saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp | 10 ++++------ saml/saml1/binding/impl/SAML1POSTDecoder.cpp | 10 ++++------ saml/saml1/binding/impl/SAML1SOAPDecoder.cpp | 8 +++----- saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp | 8 +++----- saml/saml2/binding/impl/SAML2POSTDecoder.cpp | 10 ++++------ saml/saml2/binding/impl/SAML2RedirectDecoder.cpp | 12 +++++------- saml/saml2/binding/impl/SAML2SOAPDecoder.cpp | 8 +++----- 7 files changed, 26 insertions(+), 40 deletions(-) diff --git a/saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp b/saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp index 3a5fbbf..ee5278a 100644 --- a/saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp +++ b/saml/saml1/binding/impl/SAML1ArtifactDecoder.cpp @@ -75,16 +75,14 @@ XMLObject* SAML1ArtifactDecoder::decode( log.debug("validating input"); const HTTPRequest* httpRequest=dynamic_cast(&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 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()) diff --git a/saml/saml1/binding/impl/SAML1POSTDecoder.cpp b/saml/saml1/binding/impl/SAML1POSTDecoder.cpp index bf3395e..ef39d62 100644 --- a/saml/saml1/binding/impl/SAML1POSTDecoder.cpp +++ b/saml/saml1/binding/impl/SAML1POSTDecoder.cpp @@ -77,16 +77,14 @@ XMLObject* SAML1POSTDecoder::decode( log.debug("validating input"); const HTTPRequest* httpRequest=dynamic_cast(&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. diff --git a/saml/saml1/binding/impl/SAML1SOAPDecoder.cpp b/saml/saml1/binding/impl/SAML1SOAPDecoder.cpp index eff4034..f928f8b 100644 --- a/saml/saml1/binding/impl/SAML1SOAPDecoder.cpp +++ b/saml/saml1/binding/impl/SAML1SOAPDecoder.cpp @@ -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. diff --git a/saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp b/saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp index b05e3e2..17a22ec 100644 --- a/saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp +++ b/saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp @@ -76,13 +76,11 @@ XMLObject* SAML2ArtifactDecoder::decode( log.debug("validating input"); const HTTPRequest* httpRequest=dynamic_cast(&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; diff --git a/saml/saml2/binding/impl/SAML2POSTDecoder.cpp b/saml/saml2/binding/impl/SAML2POSTDecoder.cpp index 692950b..988aa0f 100644 --- a/saml/saml2/binding/impl/SAML2POSTDecoder.cpp +++ b/saml/saml2/binding/impl/SAML2POSTDecoder.cpp @@ -76,17 +76,15 @@ XMLObject* SAML2POSTDecoder::decode( log.debug("validating input"); const HTTPRequest* httpRequest=dynamic_cast(&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; diff --git a/saml/saml2/binding/impl/SAML2RedirectDecoder.cpp b/saml/saml2/binding/impl/SAML2RedirectDecoder.cpp index 08f54d8..5927613 100644 --- a/saml/saml2/binding/impl/SAML2RedirectDecoder.cpp +++ b/saml/saml2/binding/impl/SAML2RedirectDecoder.cpp @@ -78,17 +78,15 @@ XMLObject* SAML2RedirectDecoder::decode( log.debug("validating input"); const HTTPRequest* httpRequest=dynamic_cast(&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. diff --git a/saml/saml2/binding/impl/SAML2SOAPDecoder.cpp b/saml/saml2/binding/impl/SAML2SOAPDecoder.cpp index 3757039..2d9d22f 100644 --- a/saml/saml2/binding/impl/SAML2SOAPDecoder.cpp +++ b/saml/saml2/binding/impl/SAML2SOAPDecoder.cpp @@ -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. -- 2.1.4