Log outbound XML in msg encoders.
authorcantor <cantor@fb386ef7-a10c-0410-8ebf-fd3f8e989ab0>
Tue, 20 Nov 2007 22:37:51 +0000 (22:37 +0000)
committercantor <cantor@fb386ef7-a10c-0410-8ebf-fd3f8e989ab0>
Tue, 20 Nov 2007 22:37:51 +0000 (22:37 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-opensaml2/trunk@349 fb386ef7-a10c-0410-8ebf-fd3f8e989ab0

saml/saml1/binding/impl/SAML1ArtifactEncoder.cpp
saml/saml1/binding/impl/SAML1POSTEncoder.cpp
saml/saml1/binding/impl/SAML1SOAPEncoder.cpp
saml/saml2/binding/impl/SAML2ArtifactEncoder.cpp
saml/saml2/binding/impl/SAML2ECPEncoder.cpp
saml/saml2/binding/impl/SAML2POSTEncoder.cpp
saml/saml2/binding/impl/SAML2RedirectEncoder.cpp
saml/saml2/binding/impl/SAML2SOAPEncoder.cpp

index b592b7b..672aeeb 100644 (file)
@@ -110,6 +110,10 @@ long SAML1ArtifactEncoder::encode(
     // Obtain a fresh artifact.
     if (!artifactGenerator)
         throw BindingException("SAML 1.x Artifact Encoder requires an ArtifactGenerator instance.");
+    
+    if (log.isDebugEnabled())
+        log.debugStream() << "marshalled assertion: " << *xmlObject << logging::eol;
+    
     auto_ptr_char recipientID(recipient ? recipient->getEntityID() : NULL);
     log.debug("obtaining new artifact for relying party (%s)", recipientID.get() ? recipientID.get() : "unknown");
     auto_ptr<SAMLArtifact> artifact(artifactGenerator->generateSAML1Artifact(recipient));
index 3a6feae..df0ee43 100644 (file)
@@ -103,6 +103,10 @@ long SAML1POSTEncoder::encode(
 #endif
     Category& log = Category::getInstance(SAML_LOGCAT".MessageEncoder.SAML1POST");
 
+    TemplateEngine* engine = XMLToolingConfig::getConfig().getTemplateEngine();
+    if (!engine)
+        throw BindingException("Encoding response using POST requires a TemplateEngine instance.");
+    
     log.debug("validating input");
     if (xmlObject->getParent())
         throw BindingException("Cannot encode XML content with parent.");
@@ -141,9 +145,14 @@ long SAML1POSTEncoder::encode(
         log.debug("marshalling the response");
         rootElement = response->marshall();
     }
-    
-    string xmlbuf;
+
+    // Push message into template.
+    TemplateEngine::TemplateParameters pmap;
+    string& xmlbuf = pmap.m_map["SAMLResponse"];
     XMLHelper::serialize(rootElement, xmlbuf);
+    log.debug("marshalled response: %s", xmlbuf.c_str());
+    
+    // Replace with base-64 encoded version.
     unsigned int len=0;
     XMLByte* out=Base64::encode(reinterpret_cast<const XMLByte*>(xmlbuf.data()),xmlbuf.size(),&len);
     if (out) {
@@ -155,20 +164,15 @@ long SAML1POSTEncoder::encode(
         throw BindingException("Base64 encoding of XML failed.");
     }
 
-    // Push message into template and send result to client.
+    // Fill in the rest of the data and send to the client.
     log.debug("message encoded, sending HTML form template to client");
-    TemplateEngine* engine = XMLToolingConfig::getConfig().getTemplateEngine();
-    if (!engine)
-        throw BindingException("Encoding response using POST requires a TemplateEngine instance.");
     ifstream infile(m_template.c_str());
     if (!infile)
         throw BindingException("Failed to open HTML template for POST response ($1).", params(1,m_template.c_str()));
-    TemplateEngine::TemplateParameters params;
-    params.m_map["action"] = destination;
-    params.m_map["SAMLResponse"] = xmlbuf;
-    params.m_map["TARGET"] = relayState;
+    pmap.m_map["action"] = destination;
+    pmap.m_map["TARGET"] = relayState;
     stringstream s;
-    engine->run(infile, s, params);
+    engine->run(infile, s, pmap);
     genericResponse.setContentType("text/html");
     long ret = genericResponse.sendResponse(s);
 
index 025a88c..bb9f984 100644 (file)
@@ -154,9 +154,12 @@ long SAML1SOAPEncoder::encode(
                 rootElement = env->marshall();
             }
 
-            string xmlbuf;
-            XMLHelper::serialize(rootElement, xmlbuf);
-            istringstream s(xmlbuf);
+            stringstream s;
+            s << *rootElement;
+            
+            if (log.isDebugEnabled())
+                log.debug("marshalled envelope: %s", s.str().c_str());
+            
             log.debug("sending serialized envelope");
             bool error = (!response && env->getBody() && env->getBody()->hasChildren() &&
                 dynamic_cast<Fault*>(env->getBody()->getUnknownXMLObjects().front()));
@@ -188,11 +191,14 @@ long SAML1SOAPEncoder::encode(
             env->setBody(body);
             body->getUnknownXMLObjects().push_back(fault);
             rootElement = env->marshall();
-    
-            string xmlbuf;
-            XMLHelper::serialize(rootElement, xmlbuf);
-            istringstream s(xmlbuf);
-            log.debug("sending serialized fault");
+
+            stringstream s;
+            s << *rootElement;
+            
+            if (log.isDebugEnabled())
+                log.debug("marshalled envelope: %s", s.str().c_str());
+            
+            log.debug("sending serialized envelope");
             long ret = genericResponse.sendError(s);
         
             // Cleanup by destroying XML.
index 75401c9..e4a9cd3 100644 (file)
@@ -162,6 +162,9 @@ long SAML2ArtifactEncoder::encode(
             xmlObject->marshall((DOMDocument*)NULL,&sigs,credential);
         }
     }
+
+    if (log.isDebugEnabled())
+        log.debugStream() << "marshalled message: " << *xmlObject << logging::eol;
     
     // Store the message. Last step in storage will be to delete the XML.
     log.debug("storing artifact and content in map");
index 99c4ddd..7a1f1ad 100644 (file)
@@ -221,9 +221,12 @@ long SAML2ECPEncoder::encode(
             rootElement = env->marshall();
         }
 
-        string xmlbuf;
-        XMLHelper::serialize(rootElement, xmlbuf);
-        istringstream s(xmlbuf);
+        stringstream s;
+        s << *rootElement;
+        
+        if (log.isDebugEnabled())
+            log.debug("marshalled envelope: %s", s.str().c_str());
+
         log.debug("sending serialized envelope");
         long ret = genericResponse.sendResponse(s);
     
index 5820150..bc651c2 100644 (file)
@@ -108,6 +108,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 +154,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: %s", msg.c_str());
+    
     // SimpleSign.
     if (credential && m_simple) {
         log.debug("applying simple signature to message data");
@@ -199,15 +200,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");
index d0ed6d0..ac711f1 100644 (file)
@@ -116,6 +116,7 @@ long SAML2RedirectEncoder::encode(
     DOMElement* rootElement = xmlObject->marshall();
     string xmlbuf;
     XMLHelper::serialize(rootElement, xmlbuf);
+    log.debug("marshalled message: %s", xmlbuf.c_str());
     
     unsigned int len;
     char* deflated = deflate(const_cast<char*>(xmlbuf.c_str()), xmlbuf.length(), &len);
index 64acb64..98f5e9b 100644 (file)
@@ -152,9 +152,12 @@ long SAML2SOAPEncoder::encode(
                 rootElement = env->marshall();
             }
 
-            string xmlbuf;
-            XMLHelper::serialize(rootElement, xmlbuf);
-            istringstream s(xmlbuf);
+            stringstream s;
+            s << *rootElement;
+            
+            if (log.isDebugEnabled())
+                log.debug("marshalled envelope: %s", s.str().c_str());
+
             log.debug("sending serialized envelope");
             bool error = (!msg && env->getBody() && env->getBody()->hasChildren() &&
                 dynamic_cast<Fault*>(env->getBody()->getUnknownXMLObjects().front()));
@@ -187,10 +190,13 @@ long SAML2SOAPEncoder::encode(
             body->getUnknownXMLObjects().push_back(fault);
             rootElement = env->marshall();
     
-            string xmlbuf;
-            XMLHelper::serialize(rootElement, xmlbuf);
-            istringstream s(xmlbuf);
-            log.debug("sending serialized fault");
+            stringstream s;
+            s << *rootElement;
+            
+            if (log.isDebugEnabled())
+                log.debug("marshalled envelope: %s", s.str().c_str());
+
+            log.debug("sending serialized envelope");
             long ret = genericResponse.sendError(s);
         
             // Cleanup by destroying XML.