Skip to content
Snippets Groups Projects
Commit 1a9369d8 authored by Jaime Pérez Crespo's avatar Jaime Pérez Crespo Committed by GitHub
Browse files

Merge pull request #680 from tvdijen/adfs-attribute-namespace

Flexible namespace
parents 06784bae 49adfcca
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
......@@ -61,7 +61,8 @@ MSG;
if ((!is_array($values)) || (count($values) == 0)) {
continue;
}
$name = htmlspecialchars($name);
list($namespace, $name) = SimpleSAML\Utils\Attributes::getAttributeNamespace($name, 'http://schemas.xmlsoap.org/claims');
foreach ($values as $value) {
if ((!isset($value)) || ($value === '')) {
continue;
......@@ -69,7 +70,7 @@ MSG;
$value = htmlspecialchars($value);
$result .= <<<MSG
<saml:Attribute AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="$name">
<saml:Attribute AttributeNamespace="$namespace" AttributeName="$name">
<saml:AttributeValue>$value</saml:AttributeValue>
</saml:Attribute>
MSG;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment