From 3f26043297d719ed6b63633ab4572e1898073962 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 22 Oct 2020 11:05:32 -0100 Subject: [PATCH 1/2] add idp-based prefix to gid --- lib/UserBackend.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/UserBackend.php b/lib/UserBackend.php index 6dd1a36ee..adf9edcbd 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -660,17 +660,34 @@ public function updateAttributes($uid, } if ($newGroups !== null) { + $prefix = ''; + if ($this->config->getAppValue('user_saml', 'unique_groups_per_idp', '0') === '1') { + list(, $idp) = explode('@', $uid); + $prefix = substr(md5($idp), 0, 7); + $newGroups = array_map( + function($g) use ($prefix) { + return $prefix . '-' . $g; + }, $newGroups + ); + } + $groupManager = $this->groupManager; $oldGroups = $groupManager->getUserGroupIds($user); $groupsToAdd = array_unique(array_diff($newGroups, $oldGroups)); $groupsToRemove = array_diff($oldGroups, $newGroups); - foreach ($groupsToAdd as $group) { - if (!($groupManager->groupExists($group))) { - $groupManager->createGroup($group); + foreach ($groupsToAdd as $gid) { + if (!($groupManager->groupExists($gid))) { + $group = $groupManager->createGroup($gid); + if ($prefix !== '') { + $group->setDisplayName(substr($gid, strlen($prefix) + 1)); + } + } else { + $group = $groupManager->get($gid); } - $groupManager->get($group)->addUser($user); + + $group->addUser($user); } foreach ($groupsToRemove as $group) { From 9e19e04d8ebcfe142a7e964de87644b3dde34ddc Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 14 Jan 2021 12:28:12 -0100 Subject: [PATCH 2/2] mapping in config --- lib/UserBackend.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/UserBackend.php b/lib/UserBackend.php index adf9edcbd..6e5b5cad1 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -661,8 +661,17 @@ public function updateAttributes($uid, if ($newGroups !== null) { $prefix = ''; - if ($this->config->getAppValue('user_saml', 'unique_groups_per_idp', '0') === '1') { - list(, $idp) = explode('@', $uid); + $mapping = $this->config->getSystemValue('user_saml.unique_groups_per_idp', ''); + if ($mapping === '') { + $mapping = $this->config->getAppValue('user_saml', 'unique_groups_per_idp', ''); + } + + if ($mapping !== '' && + array_key_exists($mapping, $attributes) && + is_array($attributes[$mapping]) && + sizeof($attributes[$mapping]) === 1) { + $realUid = $attributes[$mapping][0]; + list(, $idp) = explode('@', $realUid); $prefix = substr(md5($idp), 0, 7); $newGroups = array_map( function($g) use ($prefix) {