From 0c0dc192bb8d0accb6c7b6b9b459d378e8069cce Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Fri, 12 Feb 2010 07:25:04 +0000 Subject: [PATCH] SAMLParser: Extract NameFormat from attributes. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2173 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Metadata/SAMLParser.php | 37 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php index 54f1d9062..8654aac3c 100644 --- a/lib/SimpleSAML/Metadata/SAMLParser.php +++ b/lib/SimpleSAML/Metadata/SAMLParser.php @@ -518,6 +518,9 @@ class SimpleSAML_Metadata_SAMLParser { if (array_key_exists('attributes', $spd)) { $ret['attributes'] = $spd['attributes']; } + if (array_key_exists('attributes.NameFormat', $spd)) { + $ret['attributes.NameFormat'] = $spd['attributes.NameFormat']; + } /* Add name & description. */ if (array_key_exists('name', $spd)) { @@ -667,6 +670,9 @@ class SimpleSAML_Metadata_SAMLParser { if (array_key_exists('attributes', $spd)) { $ret['attributes'] = $spd['attributes']; } + if (array_key_exists('attributes.NameFormat', $spd)) { + $ret['attributes.NameFormat'] = $spd['attributes.NameFormat']; + } /* Add name & description. */ if (array_key_exists('name', $spd)) { @@ -1083,12 +1089,39 @@ class SimpleSAML_Metadata_SAMLParser { $sp['description'][$language] = SimpleSAML_Utilities::getDOMText($child); } + + $format = NULL; $elements = SimpleSAML_Utilities::getDOMChildren($element, 'RequestedAttribute', '@md'); + $sp['attributes'] = array(); foreach($elements AS $child) { $attrname = $child->getAttribute('Name'); - if (!array_key_exists('attributes', $sp)) $sp['attributes'] = array(); $sp['attributes'][] = $attrname; - } + + if ($child->hasAttribute('NameFormat')) { + $attrformat = $child->getAttribute('NameFormat'); + } else { + $attrformat = SAML2_Const::NAMEFORMAT_UNSPECIFIED; + } + + if ($format === NULL) { + $format = $attrformat; + } elseif ($format !== $attrformat) { + $format = SAML2_Const::NAMEFORMAT_UNSPECIFIED; + } + + } + + if (empty($sp['attributes'])) { + /* + * Really an invalid configuration - all AttributeConsumingServices + * should have one or more attributes. + */ + unset($sp['attributes']); + } + + if ($format !== SAML2_Const::NAMEFORMAT_UNSPECIFIED && $format !== NULL) { + $sp['attributes.NameFormat'] = $format; + } } -- GitLab