// 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));
#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.");
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) {
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);
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()));
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.
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");
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);
#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.");
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");
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");
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);
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()));
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.