Update copyright.
[shibboleth/opensaml2.git] / saml / saml1 / binding / impl / SAML1ArtifactEncoder.cpp
index 197ecb4..0a3ca1b 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.
 
 #include "internal.h"
 #include "exceptions.h"
-#include "saml/binding/SAMLArtifact.h"
+#include "binding/ArtifactMap.h"
+#include "binding/HTTPResponse.h"
+#include "binding/SAMLArtifact.h"
+#include "binding/URLEncoder.h"
 #include "saml1/binding/SAML1ArtifactEncoder.h"
 #include "saml1/core/Assertions.h"
 
@@ -48,11 +51,10 @@ namespace opensaml {
 
 SAML1ArtifactEncoder::SAML1ArtifactEncoder(const DOMElement* e) {}
 
-SAML1ArtifactEncoder::~SAML1ArtifactEncoder() {}
-
-void SAML1ArtifactEncoder::encode(
-    map<string,string>& outputFields,
+long SAML1ArtifactEncoder::encode(
+    GenericResponse& genericResponse,
     XMLObject* xmlObject,
+    const char* destination,
     const char* recipientID,
     const char* relayState,
     const CredentialResolver* credResolver,
@@ -63,9 +65,11 @@ void SAML1ArtifactEncoder::encode(
     xmltooling::NDC ndc("encode");
 #endif
     Category& log = Category::getInstance(SAML_LOGCAT".MessageEncoder.SAML1Artifact");
+
     log.debug("validating input");
-    
-    outputFields.clear();
+    HTTPResponse* httpResponse=dynamic_cast<HTTPResponse*>(&genericResponse);
+    if (!httpResponse)
+        throw BindingException("Unable to cast response interface to HTTPResponse type.");
     if (xmlObject->getParent())
         throw BindingException("Cannot encode XML content with parent.");
     Assertion* assertion = dynamic_cast<Assertion*>(xmlObject);
@@ -86,13 +90,15 @@ void SAML1ArtifactEncoder::encode(
     log.debug("obtaining new artifact for relying party (%s)", recipientID ? recipientID : "unknown");
     auto_ptr<SAMLArtifact> artifact(m_artifactGenerator->generateSAML1Artifact(recipientID));
     
-    // Pass back output fields.
-    outputFields["SAMLart"] = artifact->encode();
-    outputFields["TARGET"] = relayState;
-
     // Store the assertion. Last step in storage will be to delete the XML.
     log.debug("storing artifact and content in map");
     mapper->storeContent(xmlObject, artifact.get(), recipientID);
 
-    log.debug("message encoded");
+    // Generate redirect.
+    string loc = destination;
+    loc += (strchr(destination,'?') ? '&' : '?');
+    URLEncoder* escaper = SAMLConfig::getConfig().getURLEncoder();
+    loc = loc + "SAMLart=" + escaper->encode(artifact->encode().c_str()) + "&TARGET=" + escaper->encode(relayState);
+    log.debug("message encoded, sending redirect to client");
+    return httpResponse->sendRedirect(loc.c_str());
 }