/** * * @param SAML2_XML_md_EntityDescriptor|SAML2_XML_md_EntitiesDescriptor $element The element we should process. * @param int|NULL $maxExpireTime The maximum expiration time of the entitites. * @param array $validators The parent-elements that may be signed. * @return array Array of SAMLParser instances. */ private static function processDescriptorsElement($element, $maxExpireTime = NULL, array $validators = array()) { assert('is_null($maxExpireTime) || is_int($maxExpireTime)'); if ($element instanceof SAML2_XML_md_EntityDescriptor) { $ret = new SimpleSAML_Metadata_SAMLParser($element, $maxExpireTime, $validators); return array($ret->getEntityId() => $ret); } assert('$element instanceof SAML2_XML_md_EntitiesDescriptor'); $expTime = self::getExpireTime($element, $maxExpireTime); $validators[] = $element; $ret = array(); foreach ($element->children as $child) { $ret += self::processDescriptorsElement($child, $expTime, $validators); } return $ret; }
/** * 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. * * @param $element The DOMElement which contains the EntityDescriptor element or the EntitiesDescriptor * element. * @return An associative array of SAMLParser instances. The key of the array will be the entity id. */ public static function parseDescriptorsElement($element) { if ($element === NULL) { throw new Exception('Document was empty.'); } assert('$element instanceof DOMElement'); $entitiesValidator = NULL; if (SimpleSAML_Utilities::isDOMElementOfType($element, 'EntityDescriptor', '@md') === TRUE) { $elements = array($element); $expireTime = NULL; } elseif (SimpleSAML_Utilities::isDOMElementOfType($element, 'EntitiesDescriptor', '@md') === TRUE) { /* Check if there is a signature element in the EntitiesDescriptor. */ if (count(SimpleSAML_Utilities::getDOMChildren($element, 'Signature', '@ds')) > 0) { try { $entitiesValidator = new SimpleSAML_XML_Validator($element, 'ID'); } catch (Exception $e) { SimpleSAML_Logger::warning('SAMLParser: Error creating XML Signature validator for XML document: ' . $e->getMessage()); $entitiesValidator = NULL; } } $expireTime = self::getExpireTime($element); $elements = SimpleSAML_Utilities::getDOMChildren($element, 'EntityDescriptor', '@md'); } else { throw new Exception('Unexpected root node: [' . $element->namespaceURI . ']:' . $element->localName); } $ret = array(); foreach ($elements as $e) { $entity = new SimpleSAML_Metadata_SAMLParser($e, $entitiesValidator, $expireTime); $ret[$entity->getEntityId()] = $entity; } return $ret; }