Parameterize config namespace for message plugins.
[shibboleth/cpp-opensaml.git] / saml / saml2 / binding / impl / SAML2ArtifactDecoder.cpp
index 42882cb..c5f8c6f 100644 (file)
 
 #include "internal.h"
 #include "exceptions.h"
-#include "binding/HTTPRequest.h"
-#include "saml/binding/SAMLArtifact.h"
+#include "binding/MessageDecoder.h"
 #include "saml2/binding/SAML2Artifact.h"
-#include "saml2/binding/SAML2ArtifactDecoder.h"
 #include "saml2/core/Protocols.h"
 #include "saml2/metadata/Metadata.h"
 #include "saml2/metadata/MetadataProvider.h"
 
 #include <log4cpp/Category.hh>
+#include <xmltooling/io/HTTPRequest.h>
 #include <xmltooling/util/NDC.h>
 #include <xmltooling/util/ReplayCache.h>
 
@@ -44,15 +43,26 @@ using namespace std;
 
 namespace opensaml {
     namespace saml2p {              
-        MessageDecoder* SAML_DLLLOCAL SAML2ArtifactDecoderFactory(const DOMElement* const & e)
+        class SAML_DLLLOCAL SAML2ArtifactDecoder : public MessageDecoder
         {
-            return new SAML2ArtifactDecoder(e);
+        public:
+            SAML2ArtifactDecoder() {}
+            virtual ~SAML2ArtifactDecoder() {}
+            
+            xmltooling::XMLObject* decode(
+                std::string& relayState,
+                const GenericRequest& genericRequest,
+                SecurityPolicy& policy
+                ) const;
+        };                
+
+        MessageDecoder* SAML_DLLLOCAL SAML2ArtifactDecoderFactory(const pair<const DOMElement*,const XMLCh*>& p)
+        {
+            return new SAML2ArtifactDecoder();
         }
     };
 };
 
-SAML2ArtifactDecoder::SAML2ArtifactDecoder(const DOMElement* e) {}
-
 XMLObject* SAML2ArtifactDecoder::decode(
     string& relayState,
     const GenericRequest& genericRequest,
@@ -66,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;
@@ -139,6 +147,7 @@ XMLObject* SAML2ArtifactDecoder::decode(
     }
     policy.setIssuerMetadata(roledesc);
     
+    log.debug("calling ArtifactResolver...");
     auto_ptr<ArtifactResponse> response(
         m_artifactResolver->resolve(*(artifact2.get()), dynamic_cast<const SSODescriptorType&>(*roledesc), policy)
         );