diff --git a/lib/SimpleSAML/Utils/Attributes.php b/lib/SimpleSAML/Utils/Attributes.php index 266084a7c21e4602b74af6584779aa5e036c1bed..4a138f68299a789615cd991c0e1daacc399f2d4e 100644 --- a/lib/SimpleSAML/Utils/Attributes.php +++ b/lib/SimpleSAML/Utils/Attributes.php @@ -106,4 +106,29 @@ class Attributes return $newAttrs; } + + + /** + * Extract an attribute's namespace, or revert to default. + * + * This function takes in a namespaced attribute name at splits it in a namespace/attribute name tuple. + * When no namespace is found in the attribute name, it will be namespaced with the default namespace. + * This default namespace can be overriden by supplying a second parameter to this function. + * + * @param string $name The namespaced attribute name. + * @param string $namespace The default namespace that should be used when no namespace is found (optional). + * + * @return array The attribute name, split to the namespace and the actual attribute name. + */ + public static function getAttributeNamespace($name, $namespace = 'http://schemas.xmlsoap.org/claims') + { + $slash = strrpos($name, '/'); + if ($slash !== false) { + $namespace = substr($name, 0, $slash); + $name = substr($name, $slash + 1); + } + $name = htmlspecialchars($name); + $namespace = htmlspecialchars($namespace); + return array($namespace, $name); + } } diff --git a/modules/adfs/lib/IdP/ADFS.php b/modules/adfs/lib/IdP/ADFS.php index af11f7bd3016bcbd322e08b0f23b60134514676c..63c196c4313c44729a3c6f238917426843a62fec 100644 --- a/modules/adfs/lib/IdP/ADFS.php +++ b/modules/adfs/lib/IdP/ADFS.php @@ -61,14 +61,8 @@ MSG; if ((!is_array($values)) || (count($values) == 0)) { continue; } - $namespace = "http://schemas.xmlsoap.org/claims"; - $slash = strrpos($name, '/'); - if ($slash !== false) { - $namespace = substr($name, 0, $slash); - $name = substr($name, $slash + 1); - } - $name = htmlspecialchars($name); - $namespace = htmlspecialchars($namespace); + + list($namespace, $name) = SimpleSAML\Utils\Attributes::getAttributeNamespace($name); foreach ($values as $value) { if ((!isset($value)) || ($value === '')) { continue;