Skip to content

Commit f7f5e78

Browse files
committed
add idp-based prefix to gid
1 parent ef250f3 commit f7f5e78

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/UserBackend.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,17 +673,34 @@ public function updateAttributes($uid,
673673
}
674674

675675
if ($newGroups !== null) {
676+
$prefix = '';
677+
if ($this->config->getAppValue('user_saml', 'unique_groups_per_idp', '0') === '1') {
678+
list(, $idp) = explode('@', $uid);
679+
$prefix = substr(md5($idp), 0, 7);
680+
$newGroups = array_map(
681+
function($g) use ($prefix) {
682+
return $prefix . '-' . $g;
683+
}, $newGroups
684+
);
685+
}
686+
676687
$groupManager = $this->groupManager;
677688
$oldGroups = $groupManager->getUserGroupIds($user);
678689

679690
$groupsToAdd = array_unique(array_diff($newGroups, $oldGroups));
680691
$groupsToRemove = array_diff($oldGroups, $newGroups);
681692

682-
foreach ($groupsToAdd as $group) {
683-
if (!($groupManager->groupExists($group))) {
684-
$groupManager->createGroup($group);
693+
foreach ($groupsToAdd as $gid) {
694+
if (!($groupManager->groupExists($gid))) {
695+
$group = $groupManager->createGroup($gid);
696+
if ($prefix !== '') {
697+
$group->setDisplayName(substr($gid, strlen($prefix) + 1));
698+
}
699+
} else {
700+
$group = $groupManager->get($gid);
685701
}
686-
$groupManager->get($group)->addUser($user);
702+
703+
$group->addUser($user);
687704
}
688705

689706
foreach ($groupsToRemove as $group) {

0 commit comments

Comments
 (0)