Let XML resource loader handle "validity".
[shibboleth/cpp-opensaml.git] / saml / saml2 / binding / impl / SAML2ArtifactDecoder.cpp
index c309162..7fe371d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Internet2
+ *  Copyright 2001-2007 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,9 +23,8 @@
 #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"
@@ -44,6 +43,19 @@ using namespace std;
 
 namespace opensaml {
     namespace saml2p {              
+        class SAML_DLLLOCAL SAML2ArtifactDecoder : public MessageDecoder
+        {
+        public:
+            SAML2ArtifactDecoder(const DOMElement* e) {}
+            virtual ~SAML2ArtifactDecoder() {}
+            
+            xmltooling::XMLObject* decode(
+                std::string& relayState,
+                const GenericRequest& genericRequest,
+                SecurityPolicy& policy
+                ) const;
+        };                
+
         MessageDecoder* SAML_DLLLOCAL SAML2ArtifactDecoderFactory(const DOMElement* const & e)
         {
             return new SAML2ArtifactDecoder(e);
@@ -51,8 +63,6 @@ namespace opensaml {
     };
 };
 
-SAML2ArtifactDecoder::SAML2ArtifactDecoder(const DOMElement* e) {}
-
 XMLObject* SAML2ArtifactDecoder::decode(
     string& relayState,
     const GenericRequest& genericRequest,
@@ -124,33 +134,34 @@ XMLObject* SAML2ArtifactDecoder::decode(
         auto_ptr_char issuer(provider->getEntityID());
         log.debug("lookup succeeded, artifact issued by (%s)", issuer.get());
     }
+
+    // Mock up an Issuer object for the policy.
+    auto_ptr<Issuer> issuer(IssuerBuilder::buildIssuer());
+    issuer->setName(provider->getEntityID());
+    policy.setIssuer(issuer.get());
+    issuer.release();   // owned by policy now
     
     log.debug("attempting to find artifact issuing role...");
     const RoleDescriptor* roledesc=provider->getRoleDescriptor(*(policy.getRole()), samlconstants::SAML20P_NS);
     if (!roledesc || !dynamic_cast<const SSODescriptorType*>(roledesc)) {
         log.error("unable to find compatible SAML role (%s) in metadata", policy.getRole()->toString().c_str());
-        BindingException ex("Unable to find compatible metadata role for artifact issuer.");
-        annotateException(&ex,provider); // throws it
+        throw BindingException("Unable to find compatible metadata role for artifact issuer.");
     }
+    policy.setIssuerMetadata(roledesc);
     
-    try {
-        auto_ptr<ArtifactResponse> response(
-            m_artifactResolver->resolve(*(artifact2.get()), dynamic_cast<const SSODescriptorType&>(*roledesc), policy)
-            );
-        
-        policy.evaluate(*(response.get()), &genericRequest);
+    log.debug("calling ArtifactResolver...");
+    auto_ptr<ArtifactResponse> response(
+        m_artifactResolver->resolve(*(artifact2.get()), dynamic_cast<const SSODescriptorType&>(*roledesc), policy)
+        );
+    
+    // The policy should be enforced against the ArtifactResponse by the resolve step. 
 
-        // Extract payload and check that message.
-        XMLObject* payload = response->getPayload();
-        policy.evaluate(*payload, &genericRequest);
+    // Extract payload and check that message.
+    XMLObject* payload = response->getPayload();
+    policy.evaluate(*payload, &genericRequest);
 
-        // Return the payload only.
-        response.release();
-        payload->detach(); 
-        return payload;
-    }
-    catch (XMLToolingException& ex) {
-        annotateException(&ex,roledesc,false);
-        throw;
-    }
+    // Return the payload only.
+    response.release();
+    payload->detach(); 
+    return payload;
 }