From 99409ffb7ecd07d32efd4d2ae9b828a69d9141ac Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 16 Feb 2019 10:21:25 +0100 Subject: [PATCH] Create and merge array from (multi-valued) attributes When consuming attributes from headers instead of env, multi-valued attributes are sometimes header name postfixed (_01, _02) or merged using a separator. The prior can not easily be solved without extra logic, but the latter can be exploded using the separator character. The advantage is that everything will now be cast into an array, so that values can always be array_merged. Even multi separator-merged-multi-valued attributes will result in the correct multi-valued value this way. This will solve https://github.com/nextcloud/user_saml/issues/293 TODO: I lack the time and Nextcloud app development experience to introduce a seperator setting in UI. Please add one before merging this PR. --- lib/UserBackend.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/UserBackend.php b/lib/UserBackend.php index bc8d9f3fc..730afcc1d 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -586,19 +586,8 @@ private function getAttributeValue($name, array $attributes) { $value = ''; foreach($keys as $key) { if (isset($attributes[$key])) { - if (is_array($attributes[$key])) { - foreach ($attributes[$key] as $attribute_part_value) { - if($value !== '') { - $value .= ' '; - } - $value .= $attribute_part_value; - } - } else { - if($value !== '') { - $value .= ' '; - } - $value .= $attributes[$key]; - } + $array = explode(";", $attributes[$key]); + $value = array_merge($value, array_values($array)); } }