コード例 #1
0
ファイル: Errors.php プロジェクト: palantirnet/simplesamlphp
 /**
  * Start error logging.
  *
  * A call to this function will begin a new error logging context. Every call must have
  * a corresponding call to end().
  */
 public static function begin()
 {
     // Check whether the error access functions are present
     if (!function_exists('libxml_use_internal_errors')) {
         return;
     }
     if (count(self::$errorStack) === 0) {
         // No error logging is currently in progress. Initialize it.
         self::$xmlErrorState = libxml_use_internal_errors(TRUE);
         libxml_clear_errors();
     } else {
         /* We have already started error logging. Append the current errors to the
          * list of errors in this level.
          */
         self::addErrors();
     }
     // Add a new level to the error stack
     self::$errorStack[] = array();
 }
コード例 #2
0
ファイル: Utilities.php プロジェクト: shirlei/simplesaml
 /**
  * This function attempts to validate an XML string against the specified schema.
  *
  * It will parse the string into a DOM document and validate this document against the schema.
  *
  * @param $xml     The XML string or document which should be validated.
  * @param $schema  The schema which should be used.
  * @return Returns a string with the errors if validation fails. An empty string is
  *         returned if validation passes.
  * @deprecated
  */
 public static function validateXML($xml, $schema)
 {
     assert('is_string($xml) || $xml instanceof DOMDocument');
     assert('is_string($schema)');
     SimpleSAML_XML_Errors::begin();
     if ($xml instanceof DOMDocument) {
         $dom = $xml;
         $res = TRUE;
     } else {
         $dom = new DOMDocument();
         $res = $dom->loadXML($xml);
     }
     if ($res) {
         $config = SimpleSAML_Configuration::getInstance();
         $schemaPath = $config->resolvePath('schemas') . '/';
         $schemaFile = $schemaPath . $schema;
         $res = $dom->schemaValidate($schemaFile);
         if ($res) {
             SimpleSAML_XML_Errors::end();
             return '';
         }
         $errorText = "Schema validation failed on XML string:\n";
     } else {
         $errorText = "Failed to parse XML string for schema validation:\n";
     }
     $errors = SimpleSAML_XML_Errors::end();
     $errorText .= SimpleSAML_XML_Errors::formatErrors($errors);
     return $errorText;
 }
コード例 #3
0
ファイル: XML.php プロジェクト: tractorcow/simplesamlphp
 /**
  * This function attempts to validate an XML string against the specified schema. It will parse the string into a
  * DOM document and validate this document against the schema.
  *
  * Note that this function returns values that are evaluated as a logical true, both when validation works and when
  * it doesn't. Please use strict comparisons to check the values returned.
  *
  * @param string|\DOMDocument $xml The XML string or document which should be validated.
  * @param string              $schema The filename of the schema that should be used to validate the document.
  *
  * @return boolean|string Returns a string with errors found if validation fails. True if validation passes ok.
  * @throws \InvalidArgumentException If $schema is not a string, or $xml is neither a string nor a \DOMDocument.
  *
  * @author Olav Morken, UNINETT AS <*****@*****.**>
  */
 public static function isValid($xml, $schema)
 {
     if (!(is_string($schema) && (is_string($xml) || $xml instanceof \DOMDocument))) {
         throw new \InvalidArgumentException('Invalid input parameters.');
     }
     \SimpleSAML_XML_Errors::begin();
     if ($xml instanceof \DOMDocument) {
         $dom = $xml;
         $res = true;
     } else {
         $dom = new \DOMDocument();
         $res = $dom->loadXML($xml);
     }
     if ($res) {
         $config = \SimpleSAML_Configuration::getInstance();
         $schemaPath = $config->resolvePath('schemas') . '/';
         $schemaFile = $schemaPath . $schema;
         $res = $dom->schemaValidate($schemaFile);
         if ($res) {
             \SimpleSAML_XML_Errors::end();
             return true;
         }
         $errorText = "Schema validation failed on XML string:\n";
     } else {
         $errorText = "Failed to parse XML string for schema validation:\n";
     }
     $errors = \SimpleSAML_XML_Errors::end();
     $errorText .= \SimpleSAML_XML_Errors::formatErrors($errors);
     return $errorText;
 }
コード例 #4
0
ファイル: add.php プロジェクト: hukumonline/yii
SimpleSAML_XML_Errors::begin();
$doc = new DOMDocument();
$doc->validateOnParse = FALSE;
$doc->strictErrorChecking = TRUE;
try {
    $ok = $doc->loadXML($metadata);
    if ($ok !== TRUE) {
        $doc = NULL;
    }
} catch (DOMException $e) {
    $doc = NULL;
}
$errors = SimpleSAML_XML_Errors::end();
if ($doc === NULL || count($errors) > 0) {
    $t->data['status'] = 'invalidxml';
    $t->data['errortext'] = SimpleSAML_XML_Errors::formatErrors($errors);
    $t->show();
    exit;
}
$metadata = $doc->firstChild;
/* Check that the metadata is an EntityDescriptor */
if (!SimpleSAML_Utilities::isDOMElementOfType($metadata, 'EntityDescriptor', '@md')) {
    $t->data['status'] = 'notentitydescriptor';
    $t->show();
    exit;
}
/* Check that the entity id of the metadata matches the URL. */
$entityId = $metadata->getAttribute('entityID');
if ($entityId !== $url) {
    $t->data['status'] = 'entityid';
    $t->data['errortext'] = 'Entity id: ' . $entityId . "\n" . 'URL:       ' . $url . "\n";