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 973e8055adc1997bba32d9b595709bdc951af2ae..625f2a123ccbb1520a3216222a307dc32584e1ec 100644
--- a/modules/adfs/lib/IdP/ADFS.php
+++ b/modules/adfs/lib/IdP/ADFS.php
@@ -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;