Skip to content
Snippets Groups Projects
Commit cc5730e5 authored by Olav Morken's avatar Olav Morken
Browse files

Log received XML messages to log file when debug is set to TRUE.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2541 44740490-163a-0410-bde0-09ae8108e29a
parent 08f99932
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,9 @@ class SAML2_HTTPPost extends SAML2_Binding { ...@@ -26,6 +26,9 @@ class SAML2_HTTPPost extends SAML2_Binding {
$msgStr = $message->toSignedXML(); $msgStr = $message->toSignedXML();
$msgStr = $msgStr->ownerDocument->saveXML($msgStr); $msgStr = $msgStr->ownerDocument->saveXML($msgStr);
SimpleSAML_Utilities::debugMessage($msgStr, 'out');
$msgStr = base64_encode($msgStr); $msgStr = base64_encode($msgStr);
$msgStr = htmlspecialchars($msgStr); $msgStr = htmlspecialchars($msgStr);
...@@ -86,6 +89,8 @@ END; ...@@ -86,6 +89,8 @@ END;
$msg = base64_decode($msg); $msg = base64_decode($msg);
SimpleSAML_Utilities::debugMessage($msg, 'in');
$document = new DOMDocument(); $document = new DOMDocument();
$document->loadXML($msg); $document->loadXML($msg);
$xml = $document->firstChild; $xml = $document->firstChild;
......
...@@ -30,6 +30,9 @@ class SAML2_HTTPRedirect extends SAML2_Binding { ...@@ -30,6 +30,9 @@ class SAML2_HTTPRedirect extends SAML2_Binding {
$msgStr = $message->toUnsignedXML(); $msgStr = $message->toUnsignedXML();
$msgStr = $msgStr->ownerDocument->saveXML($msgStr); $msgStr = $msgStr->ownerDocument->saveXML($msgStr);
SimpleSAML_Utilities::debugMessage($msgStr, 'out');
$msgStr = gzdeflate($msgStr); $msgStr = gzdeflate($msgStr);
$msgStr = base64_encode($msgStr); $msgStr = base64_encode($msgStr);
...@@ -112,6 +115,8 @@ class SAML2_HTTPRedirect extends SAML2_Binding { ...@@ -112,6 +115,8 @@ class SAML2_HTTPRedirect extends SAML2_Binding {
throw new Exception('Unknown SAMLEncoding: ' . var_export($encoding, TRUE)); throw new Exception('Unknown SAMLEncoding: ' . var_export($encoding, TRUE));
} }
SimpleSAML_Utilities::debugMessage($msg, 'in');
$document = new DOMDocument(); $document = new DOMDocument();
$document->loadXML($msg); $document->loadXML($msg);
$xml = $document->firstChild; $xml = $document->firstChild;
......
...@@ -91,6 +91,8 @@ class SAML2_SOAPClient { ...@@ -91,6 +91,8 @@ class SAML2_SOAPClient {
$request = $msg->toSignedXML(); $request = $msg->toSignedXML();
$request = self::START_SOAP_ENVELOPE . $request->ownerDocument->saveXML($request) . self::END_SOAP_ENVELOPE; $request = self::START_SOAP_ENVELOPE . $request->ownerDocument->saveXML($request) . self::END_SOAP_ENVELOPE;
SimpleSAML_Utilities::debugMessage($request, 'out');
$action = 'http://www.oasis-open.org/committees/security'; $action = 'http://www.oasis-open.org/committees/security';
$version = '1.1'; $version = '1.1';
$destination = $msg->getDestination(); $destination = $msg->getDestination();
...@@ -102,6 +104,8 @@ class SAML2_SOAPClient { ...@@ -102,6 +104,8 @@ class SAML2_SOAPClient {
throw new Exception('Empty SOAP response, check peer certificate.'); throw new Exception('Empty SOAP response, check peer certificate.');
} }
SimpleSAML_Utilities::debugMessage($soapresponsexml, 'in');
// Convert to SAML2_Message (DOMElement) // Convert to SAML2_Message (DOMElement)
$dom = new DOMDocument(); $dom = new DOMDocument();
if (!$dom->loadXML($soapresponsexml)) { if (!$dom->loadXML($soapresponsexml)) {
......
...@@ -122,6 +122,8 @@ class SimpleSAML_Bindings_Shib13_Artifact { ...@@ -122,6 +122,8 @@ class SimpleSAML_Bindings_Shib13_Artifact {
$artifacts = self::getArtifacts(); $artifacts = self::getArtifacts();
$request = self::buildRequest($artifacts); $request = self::buildRequest($artifacts);
SimpleSAML_Utilities::debugMessage($msgStr, 'out');
$url = $idpMetadata->getDefaultEndpoint('ArtifactResolutionService', array('urn:oasis:names:tc:SAML:1.0:bindings:SOAP-binding')); $url = $idpMetadata->getDefaultEndpoint('ArtifactResolutionService', array('urn:oasis:names:tc:SAML:1.0:bindings:SOAP-binding'));
$url = $url['Location']; $url = $url['Location'];
...@@ -166,6 +168,8 @@ class SimpleSAML_Bindings_Shib13_Artifact { ...@@ -166,6 +168,8 @@ class SimpleSAML_Bindings_Shib13_Artifact {
throw new SimpleSAML_Error_Exception('Failed to retrieve assertion from IdP.'); throw new SimpleSAML_Error_Exception('Failed to retrieve assertion from IdP.');
} }
SimpleSAML_Utilities::debugMessage($response, 'in');
/* Find the response in the SOAP message. */ /* Find the response in the SOAP message. */
$response = self::extractResponse($response); $response = self::extractResponse($response);
......
...@@ -79,6 +79,8 @@ class SimpleSAML_Bindings_Shib13_HTTPPost { ...@@ -79,6 +79,8 @@ class SimpleSAML_Bindings_Shib13_HTTPPost {
$response = $responsedom->saveXML(); $response = $responsedom->saveXML();
SimpleSAML_Utilities::debugMessage($response, 'out');
if ($this->configuration->getBoolean('debug', FALSE)) { if ($this->configuration->getBoolean('debug', FALSE)) {
$p = new SimpleSAML_XHTML_Template($this->configuration, 'post-debug.php'); $p = new SimpleSAML_XHTML_Template($this->configuration, 'post-debug.php');
$p->data['header'] = 'SAML (Shibboleth 1.3) Response Debug-mode'; $p->data['header'] = 'SAML (Shibboleth 1.3) Response Debug-mode';
...@@ -114,6 +116,8 @@ class SimpleSAML_Bindings_Shib13_HTTPPost { ...@@ -114,6 +116,8 @@ class SimpleSAML_Bindings_Shib13_HTTPPost {
$rawResponse = $post['SAMLResponse']; $rawResponse = $post['SAMLResponse'];
$samlResponseXML = base64_decode($rawResponse); $samlResponseXML = base64_decode($rawResponse);
SimpleSAML_Utilities::debugMessage($samlResponseXML, 'in');
SimpleSAML_Utilities::validateXMLDocument($samlResponseXML, 'saml11'); SimpleSAML_Utilities::validateXMLDocument($samlResponseXML, 'saml11');
$samlResponse = new SimpleSAML_XML_Shib13_AuthnResponse(); $samlResponse = new SimpleSAML_XML_Shib13_AuthnResponse();
......
...@@ -1906,6 +1906,35 @@ class SimpleSAML_Utilities { ...@@ -1906,6 +1906,35 @@ class SimpleSAML_Utilities {
SimpleSAML_Utilities::redirect($url); SimpleSAML_Utilities::redirect($url);
} }
/**
* Helper function to log messages that we send or receive.
*
* @param string $message The message, as an XML string.
* @param string $type Whether this message is sent or received.
*/
public static function debugMessage($message, $type) {
assert('is_string($message)');
assert('$type === "out" || $type === "in"');
$globalConfig = SimpleSAML_Configuration::getInstance();
if (!$globalConfig->getBoolean('debug', FALSE)) {
/* Message debug disabled. */
return;
}
if ($type === 'in') {
SimpleSAML_Logger::debug('Received message:');
} else {
SimpleSAML_Logger::debug('Sending message:');
}
$str = self::formatXMLString($message);
foreach (explode("\n", $str) as $line) {
SimpleSAML_Logger::debug($line);
}
}
} }
?> ?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment