From 87d724a5988c31ee4f05bf0691117f96615d17bf Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 3 Nov 2011 12:41:34 +0000 Subject: [PATCH] SAML2_Utils: Change extractStrings to take the namespaceURI and localname instead of an XPath query. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2971 44740490-163a-0410-bde0-09ae8108e29a --- lib/SAML2/Assertion.php | 4 ++-- lib/SAML2/Utils.php | 15 ++++++++++----- lib/SAML2/XML/md/AffiliationDescriptor.php | 2 +- lib/SAML2/XML/md/AttributeAuthorityDescriptor.php | 4 ++-- lib/SAML2/XML/md/AuthnAuthorityDescriptor.php | 2 +- lib/SAML2/XML/md/IDPSSODescriptor.php | 2 +- lib/SAML2/XML/md/PDPDescriptor.php | 2 +- lib/SAML2/XML/md/SSODescriptorType.php | 2 +- 8 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/SAML2/Assertion.php b/lib/SAML2/Assertion.php index b35e5d6c2..d987fb0b9 100644 --- a/lib/SAML2/Assertion.php +++ b/lib/SAML2/Assertion.php @@ -321,7 +321,7 @@ class SAML2_Assertion implements SAML2_SignedElement { } switch ($node->localName) { case 'AudienceRestriction': - $audiences = SAML2_Utils::extractStrings($node, './saml_assertion:Audience'); + $audiences = SAML2_Utils::extractStrings($node, SAML2_Const::NS_SAML, 'Audience'); if ($this->validAudiences === NULL) { /* The first (and probably last) AudienceRestriction element. */ $this->validAudiences = $audiences; @@ -401,7 +401,7 @@ class SAML2_Assertion implements SAML2_SignedElement { $this->authnContext = trim($accr[0]->textContent); } - $this->AuthenticatingAuthority = SAML2_Utils::extractStrings($ac, './saml_assertion:AuthenticatingAuthority'); + $this->AuthenticatingAuthority = SAML2_Utils::extractStrings($ac, SAML2_Const::NS_SAML, 'AuthenticatingAuthority'); } diff --git a/lib/SAML2/Utils.php b/lib/SAML2/Utils.php index d95243461..0e37acc71 100644 --- a/lib/SAML2/Utils.php +++ b/lib/SAML2/Utils.php @@ -458,15 +458,20 @@ class SAML2_Utils { /** * Extract strings from a set of nodes. * - * @param DOMElement $parent The element we should rund the XPath query on. - * @param string $query The XPath query we should use to retrieve the nodes. + * @param DOMElement $parent The element that contains the localized strings. + * @param string $namespaceURI The namespace URI the string elements should have. + * @param string $localName The localName of the string elements. * @return array The string values of the various nodes. */ - public static function extractStrings(DOMElement $parent, $query) { - assert('is_string($query)'); + public static function extractStrings(DOMElement $parent, $namespaceURI, $localName) { + assert('is_string($namespaceURI)'); + assert('is_string($localName)'); $ret = array(); - foreach (self::xpQuery($parent, $query) as $node) { + for ($node = $parent->firstChild; $node !== NULL; $node = $node->nextSibling) { + if ($node->namespaceURI !== $namespaceURI || $node->localName !== $localName) { + continue; + } $ret[] = trim($node->textContent); } diff --git a/lib/SAML2/XML/md/AffiliationDescriptor.php b/lib/SAML2/XML/md/AffiliationDescriptor.php index ad3332305..927ad1f83 100644 --- a/lib/SAML2/XML/md/AffiliationDescriptor.php +++ b/lib/SAML2/XML/md/AffiliationDescriptor.php @@ -102,7 +102,7 @@ class SAML2_XML_md_AffiliationDescriptor extends SAML2_SignedElementHelper { $this->Extensions = SAML2_XML_md_Extensions::getList($xml); - $this->AffiliateMember = SAML2_Utils::extractStrings($xml, './saml_metadata:AffiliateMember'); + $this->AffiliateMember = SAML2_Utils::extractStrings($xml, SAML2_Const::NS_MD, 'AffiliateMember'); if (empty($this->AffiliateMember)) { throw new Exception('Missing AffiliateMember in AffiliationDescriptor.'); } diff --git a/lib/SAML2/XML/md/AttributeAuthorityDescriptor.php b/lib/SAML2/XML/md/AttributeAuthorityDescriptor.php index bbf950750..8babb283a 100644 --- a/lib/SAML2/XML/md/AttributeAuthorityDescriptor.php +++ b/lib/SAML2/XML/md/AttributeAuthorityDescriptor.php @@ -81,9 +81,9 @@ class SAML2_XML_md_AttributeAuthorityDescriptor extends SAML2_XML_md_RoleDescrip $this->AssertionIDRequestService[] = new SAML2_XML_md_EndpointType($airs); } - $this->NameIDFormat = SAML2_Utils::extractStrings($xml, './saml_metadata:NameIDFormat'); + $this->NameIDFormat = SAML2_Utils::extractStrings($xml, SAML2_Const::NS_MD, 'NameIDFormat'); - $this->AttributeProfile = SAML2_Utils::extractStrings($xml, './saml_metadata:AttributeProfile'); + $this->AttributeProfile = SAML2_Utils::extractStrings($xml, SAML2_Const::NS_MD, 'AttributeProfile'); foreach (SAML2_Utils::xpQuery($xml, './saml_assertion:Attribute') as $a) { $this->Attribute[] = new SAML2_XML_saml_Attribute($a); diff --git a/lib/SAML2/XML/md/AuthnAuthorityDescriptor.php b/lib/SAML2/XML/md/AuthnAuthorityDescriptor.php index 9a059823f..8ab4c88c0 100644 --- a/lib/SAML2/XML/md/AuthnAuthorityDescriptor.php +++ b/lib/SAML2/XML/md/AuthnAuthorityDescriptor.php @@ -61,7 +61,7 @@ class SAML2_XML_md_AuthnAuthorityDescriptor extends SAML2_XML_md_RoleDescriptor $this->AssertionIDRequestService[] = new SAML2_XML_md_EndpointType($airs); } - $this->NameIDFormat = SAML2_Utils::extractStrings($xml, './saml_metadata:NameIDFormat'); + $this->NameIDFormat = SAML2_Utils::extractStrings($xml, SAML2_Const::NS_MD, 'NameIDFormat'); } diff --git a/lib/SAML2/XML/md/IDPSSODescriptor.php b/lib/SAML2/XML/md/IDPSSODescriptor.php index 67116ced8..99190fa2e 100644 --- a/lib/SAML2/XML/md/IDPSSODescriptor.php +++ b/lib/SAML2/XML/md/IDPSSODescriptor.php @@ -92,7 +92,7 @@ class SAML2_XML_md_IDPSSODescriptor extends SAML2_XML_md_SSODescriptorType { $this->AssertionIDRequestService[] = new SAML2_XML_md_EndpointType($airs); } - $this->AttributeProfile = SAML2_Utils::extractStrings($xml, './saml_metadata:AttributeProfile'); + $this->AttributeProfile = SAML2_Utils::extractStrings($xml, SAML2_Const::NS_MD, 'AttributeProfile'); foreach (SAML2_Utils::xpQuery($xml, './saml_assertion:Attribute') as $a) { $this->Attribute[] = new SAML2_XML_saml_Attribute($a); diff --git a/lib/SAML2/XML/md/PDPDescriptor.php b/lib/SAML2/XML/md/PDPDescriptor.php index e2765fdea..677d5f64f 100644 --- a/lib/SAML2/XML/md/PDPDescriptor.php +++ b/lib/SAML2/XML/md/PDPDescriptor.php @@ -61,7 +61,7 @@ class SAML2_XML_md_PDPDescriptor extends SAML2_XML_md_RoleDescriptor { $this->AssertionIDRequestService[] = new SAML2_XML_md_EndpointType($airs); } - $this->NameIDFormat = SAML2_Utils::extractStrings($xml, './saml_metadata:NameIDFormat'); + $this->NameIDFormat = SAML2_Utils::extractStrings($xml, SAML2_Const::NS_MD, 'NameIDFormat'); } diff --git a/lib/SAML2/XML/md/SSODescriptorType.php b/lib/SAML2/XML/md/SSODescriptorType.php index 4ba5f5a57..bdb8e965f 100644 --- a/lib/SAML2/XML/md/SSODescriptorType.php +++ b/lib/SAML2/XML/md/SSODescriptorType.php @@ -75,7 +75,7 @@ abstract class SAML2_XML_md_SSODescriptorType extends SAML2_XML_md_RoleDescripto $this->ManageNameIDService[] = new SAML2_XML_md_EndpointType($ep); } - $this->NameIDFormat = SAML2_Utils::extractStrings($xml, './saml_metadata:NameIDFormat'); + $this->NameIDFormat = SAML2_Utils::extractStrings($xml, SAML2_Const::NS_MD, 'NameIDFormat'); } -- GitLab