37        $allowed_types = array(
'saml20', 
'saml11', 
'saml-meta');
 
   38        if (!(is_string(
$message) && in_array(
$type, $allowed_types, 
true))) {
 
   39            throw new \InvalidArgumentException(
'Invalid input parameters.');
 
   43        if (strpos(
$message, 
'<!DOCTYPE') !== 
false) {
 
   44            throw new \SimpleSAML_Error_Exception(
'XML contained a doctype declaration.');
 
   51        if (!(in_array(
'validatexml', 
$debug, 
true) 
 
   52              || (array_key_exists(
'validatexml', 
$debug) && 
$debug[
'validatexml'] === 
true) 
 
   63                $result = self::isValid(
$message, 
'oasis-sstc-saml-schema-protocol-1.1.xsd');
 
   97            throw new \InvalidArgumentException(
'Invalid input parameters.');
 
  103        if (!(in_array(
'saml', 
$debug, 
true) 
 
  104              || (array_key_exists(
'saml', 
$debug) && 
$debug[
'saml'] === 
true) 
 
  112        if (
$message instanceof \DOMElement) {
 
  134        foreach (explode(
"\n", $str) as $line) {
 
  156    public static function formatDOMElement(\DOMNode $root, $indentBase = 
'')
 
  158        if (!is_string($indentBase)) {
 
  159            throw new \InvalidArgumentException(
'Invalid input parameters');
 
  164        $textNodes = array(); 
 
  165        $childNodes = array(); 
 
  166        for (
$i = 0; 
$i < $root->childNodes->length; 
$i++) {
 
  168            $child = $root->childNodes->item(
$i);
 
  170            if ($child instanceof \DOMText) {
 
  171                $textNodes[] = $child;
 
  172                $fullText .= $child->wholeText;
 
  173            } elseif ($child instanceof \DOMComment || $child instanceof \DOMElement) {
 
  174                $childNodes[] = $child;
 
  181        $fullText = trim($fullText);
 
  182        if (strlen($fullText) > 0) {
 
  189        $hasChildNode = (count($childNodes) > 0);
 
  191        if ($hasText && $hasChildNode) {
 
  197        foreach ($textNodes as $node) {
 
  198            $root->removeChild($node);
 
  203            $root->appendChild(
new \DOMText($fullText));
 
  207        if (!$hasChildNode) {
 
  215        $childIndentation = $indentBase.
'  ';
 
  216        foreach ($childNodes as $node) {
 
  218            $root->insertBefore(
new \DOMText(
"\n".$childIndentation), $node);
 
  221            if ($node instanceof \DOMElement) {
 
  222                self::formatDOMElement($node, $childIndentation);
 
  227        $root->appendChild(
new \DOMText(
"\n".$indentBase));
 
  248        if (!is_string(
$xml) || !is_string($indentBase)) {
 
  249            throw new \InvalidArgumentException(
'Invalid input parameters');
 
  254        } 
catch (\Exception $e) {
 
  255            throw new \DOMException(
'Error parsing XML string.');
 
  258        $root = $doc->firstChild;
 
  259        self::formatDOMElement($root, $indentBase);
 
  261        return $doc->saveXML($root);
 
  280    public static function getDOMChildren(\DOMNode $element, $localName, $namespaceURI)
 
  282        if (!is_string($localName) || !is_string($namespaceURI)) {
 
  283            throw new \InvalidArgumentException(
'Invalid input parameters.');
 
  288        for (
$i = 0; 
$i < $element->childNodes->length; 
$i++) {
 
  290            $child = $element->childNodes->item(
$i);
 
  293            if ($child instanceof \DOMText || $child instanceof \DOMComment) {
 
  297            if (self::isDOMNodeOfType($child, $localName, $namespaceURI) === 
true) {
 
  316    public static function getDOMText(\DOMElement $element)
 
  320        for (
$i = 0; 
$i < $element->childNodes->length; 
$i++) {
 
  322            $child = $element->childNodes->item(
$i);
 
  323            if (!($child instanceof \DOMText)) {
 
  324                throw new \SimpleSAML_Error_Exception($element->localName.
' contained a non-text child node.');
 
  327            $txt .= $child->wholeText;
 
  359        if (!is_string(
$name) || !is_string($nsURI) || strlen($nsURI) === 0) {
 
  365        if ($nsURI[0] === 
'@') {
 
  368                '@ds'      => 
'http://www.w3.org/2000/09/xmldsig#',
 
  369                '@md'      => 
'urn:oasis:names:tc:SAML:2.0:metadata',
 
  370                '@saml1'   => 
'urn:oasis:names:tc:SAML:1.0:assertion',
 
  371                '@saml1md' => 
'urn:oasis:names:tc:SAML:profiles:v1metadata',
 
  372                '@saml1p'  => 
'urn:oasis:names:tc:SAML:1.0:protocol',
 
  373                '@saml2'   => 
'urn:oasis:names:tc:SAML:2.0:assertion',
 
  374                '@saml2p'  => 
'urn:oasis:names:tc:SAML:2.0:protocol',
 
  375                '@shibmd'  => 
'urn:mace:shibboleth:metadata:1.0',
 
  379            if (!array_key_exists($nsURI, $shortcuts)) {
 
  380                throw new \InvalidArgumentException(
'Unknown namespace shortcut: '.$nsURI);
 
  384            $nsURI = $shortcuts[$nsURI];
 
  386        if ($element->localName !== 
$name) {
 
  389        if ($element->namespaceURI !== $nsURI) {
 
  413        if (!(is_string(
$schema) && (is_string(
$xml) || 
$xml instanceof \DOMDocument))) {
 
  414            throw new \InvalidArgumentException(
'Invalid input parameters.');
 
  419        if (
$xml instanceof \DOMDocument) {
 
  426            } 
catch (\Exception $e) {
 
  434            $schemaPath = 
$config->resolvePath(
'schemas');
 
  436            $schemaFile = $schemaPath.$schema;
 
  438            $res = $dom->schemaValidate($schemaFile);
 
  444            $errorText = 
"Schema validation failed on XML string:\n";
 
  446            $errorText = 
"Failed to parse XML string for schema validation:\n";
 
An exception for terminatinating execution or to throw for unit testing.
static isDOMNodeOfType(\DOMNode $element, $name, $nsURI)
This function checks if the DOMElement has the correct localName and namespaceURI.
static checkSAMLMessage($message, $type)
This function performs some sanity checks on XML documents, and optionally validates them against the...
static debugSAMLMessage($message, $type)
Helper function to log SAML messages that we send or receive.
static formatXMLString($xml, $indentBase='')
Format an XML string.
static formatErrors($errors)
Format a list of errors as a string.
static begin()
Start error logging.
static end()
End error logging.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
catch(Exception $e) $message
foreach($_POST as $key=> $value) $res