parseDescriptorsElement() public static method

This function parses a DOMElement which represents either an EntityDescriptor element or an EntitiesDescriptor element. It will return an associative array of SAMLParser instances in both cases.
public static parseDescriptorsElement ( DOMElement $element = null ) : SimpleSAML_Metadata_SAMLParser[]
$element DOMElement The DOMElement which contains the EntityDescriptor element or the EntitiesDescriptor element.
return SimpleSAML_Metadata_SAMLParser[] An associative array of SAMLParser instances. The key of the array will be the entity id.
 /**
  * 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']);
     }
     $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($doc->documentElement);
     return $entities;
 }
Beispiel #2
0
 /**
  * Parse XML metadata and return entities
  */
 private function loadXML($data, $source)
 {
     $entities = array();
     try {
         $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']);
         }
         $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($doc->documentElement);
     } catch (Exception $e) {
         SimpleSAML_Logger::warning('metarefresh: Failed to retrieve metadata. ' . $e->getMessage());
     }
     return $entities;
 }
 /**
  * Parse XML metadata and return entities
  */
 private function loadXML($data, $source)
 {
     $entities = array();
     try {
         $doc = \SAML2\DOMDocumentFactory::fromString($data);
     } catch (Exception $e) {
         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']);
     }
     $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($doc->documentElement);
     return $entities;
 }
    /**
     * Test AttributeConsumingService is parsed
     */
    public function testAttributeConsumingServiceParsing()
    {
        $document = \SAML2\DOMDocumentFactory::fromString(<<<XML
<EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi">
  <EntityDescriptor entityID="theEntityID">
    <Extensions>
      <mdrpi:RegistrationInfo registrationAuthority="https://incommon.org"/>
    </Extensions>
    <SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
      <AttributeConsumingService index="0">
        <ServiceName xml:lang="en">Example service</ServiceName>
        <ServiceDescription xml:lang="nl">Dit is een voorbeeld voor de unittest.</ServiceDescription>

        <RequestedAttribute FriendlyName="eduPersonPrincipalName" Name="urn:mace:dir:attribute-def:eduPersonPrincipalName" NameFormat="urn:mace:shibboleth:1.0:attributeNamespace:uri" isRequired="true"/>
        <RequestedAttribute FriendlyName="mail" Name="urn:mace:dir:attribute-def:mail" NameFormat="urn:mace:shibboleth:1.0:attributeNamespace:uri"/>
        <RequestedAttribute FriendlyName="displayName" Name="urn:mace:dir:attribute-def:displayName" NameFormat="urn:mace:shibboleth:1.0:attributeNamespace:uri"/>
      </AttributeConsumingService>
    </SPSSODescriptor>

  </EntityDescriptor>
</EntitiesDescriptor>
XML
);
        $entities = \SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($document->documentElement);
        $this->assertArrayHasKey('theEntityID', $entities);
        $metadata = $entities['theEntityID']->getMetadata20SP();
        $this->assertEquals("Example service", $metadata['name']['en']);
        $this->assertEquals("Dit is een voorbeeld voor de unittest.", $metadata['description']['nl']);
        $expected_a = array("urn:mace:dir:attribute-def:eduPersonPrincipalName", "urn:mace:dir:attribute-def:mail", "urn:mace:dir:attribute-def:displayName");
        $expected_r = array("urn:mace:dir:attribute-def:eduPersonPrincipalName");
        $this->assertEquals($expected_a, $metadata['attributes']);
        $this->assertEquals($expected_r, $metadata['attributes.required']);
    }
 /**
  * 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;
 }