isDOMElementOfType() public static method

Deprecation: This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\XML::isDOMElementOfType() instead.
public static isDOMElementOfType ( DOMNode $element, $name, $nsURI )
$element DOMNode
 /**
  * Extract the response element from the SOAP response.
  *
  * @param string $soapResponse  The SOAP response.
  * @return string  The <saml1p:Response> element, as a string.
  */
 private static function extractResponse($soapResponse)
 {
     assert('is_string($soapResponse)');
     $doc = new DOMDocument();
     if (!$doc->loadXML($soapResponse)) {
         throw new SimpleSAML_Error_Exception('Error parsing SAML 1 artifact response.');
     }
     $soapEnvelope = $doc->firstChild;
     if (!SimpleSAML_Utilities::isDOMElementOfType($soapEnvelope, 'Envelope', 'http://schemas.xmlsoap.org/soap/envelope/')) {
         throw new SimpleSAML_Error_Exception('Expected artifact response to contain a <soap:Envelope> element.');
     }
     $soapBody = SimpleSAML_Utilities::getDOMChildren($soapEnvelope, 'Body', 'http://schemas.xmlsoap.org/soap/envelope/');
     if (count($soapBody) === 0) {
         throw new SimpleSAML_Error_Exception('Couldn\'t find <soap:Body> in <soap:Envelope>.');
     }
     $soapBody = $soapBody[0];
     $responseElement = SimpleSAML_Utilities::getDOMChildren($soapBody, 'Response', 'urn:oasis:names:tc:SAML:1.0:protocol');
     if (count($responseElement) === 0) {
         throw new SimpleSAML_Error_Exception('Couldn\'t find <saml1p:Response> in <soap:Body>.');
     }
     $responseElement = $responseElement[0];
     /*
      * Save the <saml1p:Response> element. Note that we need to import it
      * into a new document, in order to preserve namespace declarations.
      */
     $newDoc = new DOMDocument();
     $newDoc->appendChild($newDoc->importNode($responseElement, TRUE));
     $responseXML = $newDoc->saveXML();
     return $responseXML;
 }
 /**
  * This function locates the EntityDescriptor node in a DOMDocument. This node should
  * be the first (and only) node in the document.
  *
  * This function will throw an exception if it is unable to locate the node.
  *
  * @param $doc The DOMDocument where we should find the EntityDescriptor node.
  * @return The DOMEntity which represents the EntityDescriptor.
  */
 private static function findEntityDescriptor($doc)
 {
     assert('$doc instanceof DOMDocument');
     /* Find the EntityDescriptor DOMElement. This should be the first (and only) child of the
      * DOMDocument.
      */
     $ed = $doc->documentElement;
     if ($ed === NULL) {
         throw new Exception('Failed to load SAML metadata from empty XML document.');
     }
     if (SimpleSAML_Utilities::isDOMElementOfType($ed, 'EntityDescriptor', '@md') === FALSE) {
         throw new Exception('Expected first element in the metadata document to be an EntityDescriptor element.');
     }
     return new SAML2_XML_md_EntityDescriptor($ed);
 }
示例#3
0
文件: add.php 项目: hukumonline/yii
    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";
    $t->show();
    exit;
}
/* Validate the metadata against the metadata schema (if enabled). */
if ($metaConfig->getBoolean('metashare.validateschema')) {
    $errors = SimpleSAML_Utilities::validateXML($doc, 'saml-schema-metadata-2.0.xsd');
 /**
  * Parse XML metadata and return entities
  */
 private function loadXML($data, $source)
 {
     $entities = array();
     $doc = new DOMDocument();
     $res = $doc->loadXML($data);
     if ($res !== TRUE) {
         throw new Exception('Failed to read XML from ' . $source['src']);
     }
     if ($doc->documentElement === NULL) {
         throw new Exception('Opened file is not an XML document: ' . $source['src']);
     }
     if (SimpleSAML_Utilities::isDOMElementOfType($doc->documentElement, 'EntitiesDescriptor', '@md') === TRUE) {
         foreach (SAML2_Utils::xpQuery($doc->documentElement, './saml_metadata:EntityDescriptor|./saml_metadata:EntitiesDescriptor') as $node) {
             if ($node->localName === 'EntityDescriptor') {
                 try {
                     $entities = array_merge($entities, SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($node));
                 } catch (Exception $e) {
                     $entityID = $node->getAttribute('entityID');
                     if (empty($entityID)) {
                         $entityID = "unknown";
                     }
                     SimpleSAML_Logger::warning('[metarefresh]: Error while parsing entity (' . $entityID . '): ' . $e->getMessage());
                 }
             } else {
                 $entities = array_merge($entities, $this->loadXML($node->ownerDocument->saveXML($node), $source));
             }
         }
     } else {
         $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($doc->documentElement);
     }
     return $entities;
 }