From 54e4791a4af85e4f84fd2b421c1901f2764ba125 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaime=20Pe=CC=81rez?= <jaime.perez@uninett.no>
Date: Tue, 23 Aug 2016 11:39:36 +0200
Subject: [PATCH] bugfix: Make sure we can deal with attribute values that are
 not strings (i.e. DOMNodeList).

This is due to the update of the SAML2 library, that caused several other bugs, mainly with attributes like eduPersonTargetedID, which should always be an SAML NameID.
---
 www/authmemcookie.php | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/www/authmemcookie.php b/www/authmemcookie.php
index a24b0556b..914959135 100644
--- a/www/authmemcookie.php
+++ b/www/authmemcookie.php
@@ -74,11 +74,21 @@ try {
 
     // store the authentication data in the memcache server
     $data = '';
-    foreach ($authData as $n => $v) {
-        if (is_array($v)) {
-            $v = implode(':', $v);
+    foreach ($authData as $name => $values) {
+        if (is_array($values)) {
+            foreach ($values as $i => $value) {
+                if (!is_a($value, 'DOMNodeList')) {
+                    continue;
+                }
+                /* @var \DOMNodeList $value */
+                if ($value->length === 0) {
+                    continue;
+                }
+                $values[$i] = new \SAML2\XML\saml\AttributeValue($value->item(0)->parentNode);
+            }
+            $values = implode(':', $values);
         }
-        $data .= $n.'='.$v."\r\n";
+        $data .= $name.'='.$values."\r\n";
     }
 
     $memcache = $amc->getMemcache();
-- 
GitLab