Support path resolution in binding templates.
[shibboleth/opensaml2.git] / saml / saml2 / binding / impl / SAML2POSTEncoder.cpp
index 5820150..8f122e0 100644 (file)
@@ -31,6 +31,7 @@
 #include <xercesc/util/Base64.hpp>
 #include <xmltooling/logging.h>
 #include <xmltooling/util/NDC.h>
+#include <xmltooling/util/PathResolver.h>
 #include <xmltooling/util/TemplateEngine.h>
 
 using namespace opensaml::saml2p;
@@ -89,6 +90,7 @@ SAML2POSTEncoder::SAML2POSTEncoder(const DOMElement* e, const XMLCh* ns, bool si
     }
     if (m_template.empty())
         throw XMLToolingException("SAML2POSTEncoder requires template XML attribute.");
+    XMLToolingConfig::getConfig().getPathResolver()->resolve(m_template, PathResolver::XMLTOOLING_CFG_FILE);
 }
 
 long SAML2POSTEncoder::encode(
@@ -108,6 +110,10 @@ long SAML2POSTEncoder::encode(
 #endif
     Category& log = Category::getInstance(SAML_LOGCAT".MessageEncoder.SAML2POST");
 
+    TemplateEngine* engine = XMLToolingConfig::getConfig().getTemplateEngine();
+    if (!engine)
+        throw BindingException("Encoding message using POST requires a TemplateEngine instance.");
+    
     log.debug("validating input");
     if (xmlObject->getParent())
         throw BindingException("Cannot encode XML content with parent.");
@@ -150,15 +156,12 @@ long SAML2POSTEncoder::encode(
         rootElement = xmlObject->marshall((DOMDocument*)NULL);
     }
     
-    // Start tracking data.
-    TemplateEngine::TemplateParameters pmap;
-    if (relayState && *relayState)
-        pmap.m_map["RelayState"] = relayState;
-
     // Serialize the message.
+    TemplateEngine::TemplateParameters pmap;
     string& msg = pmap.m_map[(request ? "SAMLRequest" : "SAMLResponse")];
     XMLHelper::serialize(rootElement, msg);
-
+    log.debug("marshalled message:\n%s", msg.c_str());
+    
     // SimpleSign.
     if (credential && m_simple) {
         log.debug("applying simple signature to message data");
@@ -199,15 +202,14 @@ long SAML2POSTEncoder::encode(
     msg.append(reinterpret_cast<char*>(out),len);
     XMLString::release(&out);
     
-    // Push message into template and send result to client.
+    // Push the rest of it into template and send result to client.
     log.debug("message encoded, sending HTML form template to client");
-    TemplateEngine* engine = XMLToolingConfig::getConfig().getTemplateEngine();
-    if (!engine)
-        throw BindingException("Encoding message using POST requires a TemplateEngine instance.");
     ifstream infile(m_template.c_str());
     if (!infile)
         throw BindingException("Failed to open HTML template for POST message ($1).", params(1,m_template.c_str()));
     pmap.m_map["action"] = destination;
+    if (relayState && *relayState)
+        pmap.m_map["RelayState"] = relayState;
     stringstream s;
     engine->run(infile, s, pmap);
     genericResponse.setContentType("text/html");