Skip to content
Snippets Groups Projects
Commit e4b95abd authored by Olav Morken's avatar Olav Morken
Browse files

SAML2_Utils: Change extractLocalizedStrings to take the namespaceURI and...

SAML2_Utils: Change extractLocalizedStrings to take the namespaceURI and localname instead of an XPath query.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2972 44740490-163a-0410-bde0-09ae8108e29a
parent 87d724a5
Branches
Tags
No related merge requests found
...@@ -434,15 +434,21 @@ class SAML2_Utils { ...@@ -434,15 +434,21 @@ class SAML2_Utils {
/** /**
* Extract localized strings from a set of nodes. * Extract localized strings from a set of nodes.
* *
* @param DOMElement $parent The element we should rund the XPath query on. * @param DOMElement $parent The element that contains the localized strings.
* @param string $query The XPath query we should use to retrieve the nodes. * @param string $namespaceURI The namespace URI the localized strings should have.
* @param string $localName The localName of the localized strings.
* @return array Localized strings. * @return array Localized strings.
*/ */
public static function extractLocalizedStrings(DOMElement $parent, $query) { public static function extractLocalizedStrings(DOMElement $parent, $namespaceURI, $localName) {
assert('is_string($query)'); assert('is_string($namespaceURI)');
assert('is_string($localName)');
$ret = array(); $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;
}
if ($node->hasAttribute('xml:lang')) { if ($node->hasAttribute('xml:lang')) {
$language = $node->getAttribute('xml:lang'); $language = $node->getAttribute('xml:lang');
} else { } else {
......
...@@ -73,12 +73,12 @@ class SAML2_XML_md_AttributeConsumingService { ...@@ -73,12 +73,12 @@ class SAML2_XML_md_AttributeConsumingService {
$this->isDefault = SAML2_Utils::parseBoolean($xml, 'isDefault', NULL); $this->isDefault = SAML2_Utils::parseBoolean($xml, 'isDefault', NULL);
$this->ServiceName = SAML2_Utils::extractLocalizedStrings($xml, './saml_metadata:ServiceName'); $this->ServiceName = SAML2_Utils::extractLocalizedStrings($xml, SAML2_Const::NS_MD, 'ServiceName');
if (empty($this->ServiceName)) { if (empty($this->ServiceName)) {
throw new Exception('Missing ServiceName in AttributeConsumingService.'); throw new Exception('Missing ServiceName in AttributeConsumingService.');
} }
$this->ServiceDescription = SAML2_Utils::extractLocalizedStrings($xml, './saml_metadata:ServiceDescription'); $this->ServiceDescription = SAML2_Utils::extractLocalizedStrings($xml, SAML2_Const::NS_MD, 'ServiceDescription');
foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:RequestedAttribute') as $ra) { foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:RequestedAttribute') as $ra) {
$this->RequestedAttribute[] = new SAML2_XML_md_RequestedAttribute($ra); $this->RequestedAttribute[] = new SAML2_XML_md_RequestedAttribute($ra);
......
...@@ -56,17 +56,17 @@ class SAML2_XML_md_Organization { ...@@ -56,17 +56,17 @@ class SAML2_XML_md_Organization {
$this->Extensions = SAML2_XML_md_Extensions::getList($xml); $this->Extensions = SAML2_XML_md_Extensions::getList($xml);
$this->OrganizationName = SAML2_Utils::extractLocalizedStrings($xml, './saml_metadata:OrganizationName'); $this->OrganizationName = SAML2_Utils::extractLocalizedStrings($xml, SAML2_Const::NS_MD, 'OrganizationName');
if (empty($this->OrganizationName)) { if (empty($this->OrganizationName)) {
$this->OrganizationName = array('invalid' => ''); $this->OrganizationName = array('invalid' => '');
} }
$this->OrganizationDisplayName = SAML2_Utils::extractLocalizedStrings($xml, './saml_metadata:OrganizationDisplayName'); $this->OrganizationDisplayName = SAML2_Utils::extractLocalizedStrings($xml, SAML2_Const::NS_MD, 'OrganizationDisplayName');
if (empty($this->OrganizationDisplayName)) { if (empty($this->OrganizationDisplayName)) {
$this->OrganizationDisplayName = array('invalid' => ''); $this->OrganizationDisplayName = array('invalid' => '');
} }
$this->OrganizationURL = SAML2_Utils::extractLocalizedStrings($xml, './saml_metadata:OrganizationURL'); $this->OrganizationURL = SAML2_Utils::extractLocalizedStrings($xml, SAML2_Const::NS_MD, 'OrganizationURL');
if (empty($this->OrganizationURL)) { if (empty($this->OrganizationURL)) {
$this->OrganizationURL = array('invalid' => ''); $this->OrganizationURL = array('invalid' => '');
} }
......
...@@ -64,8 +64,7 @@ class SAML2_XML_mdrpi_PublicationInfo { ...@@ -64,8 +64,7 @@ class SAML2_XML_mdrpi_PublicationInfo {
$this->publicationId = $xml->getAttribute('publicationId'); $this->publicationId = $xml->getAttribute('publicationId');
} }
$query = './*[local-name()="UsagePolicy" and namespace-uri()="' . SAML2_XML_mdrpi_Common::NS_MDRPI . '"]'; $this->UsagePolicy = SAML2_Utils::extractLocalizedStrings($xml, SAML2_XML_mdrpi_Common::NS_MDRPI, 'UsagePolicy');
$this->UsagePolicy = SAML2_Utils::extractLocalizedStrings($xml, $query);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment