Skip to content

Commit 3f26043

Browse files
ArtificialOwlAndyScherzinger
authored andcommitted
add idp-based prefix to gid
1 parent f16104d commit 3f26043

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/UserBackend.php

+21-4
Original file line numberDiff line numberDiff line change
@@ -660,17 +660,34 @@ public function updateAttributes($uid,
660660
}
661661

662662
if ($newGroups !== null) {
663+
$prefix = '';
664+
if ($this->config->getAppValue('user_saml', 'unique_groups_per_idp', '0') === '1') {
665+
list(, $idp) = explode('@', $uid);
666+
$prefix = substr(md5($idp), 0, 7);
667+
$newGroups = array_map(
668+
function($g) use ($prefix) {
669+
return $prefix . '-' . $g;
670+
}, $newGroups
671+
);
672+
}
673+
663674
$groupManager = $this->groupManager;
664675
$oldGroups = $groupManager->getUserGroupIds($user);
665676

666677
$groupsToAdd = array_unique(array_diff($newGroups, $oldGroups));
667678
$groupsToRemove = array_diff($oldGroups, $newGroups);
668679

669-
foreach ($groupsToAdd as $group) {
670-
if (!($groupManager->groupExists($group))) {
671-
$groupManager->createGroup($group);
680+
foreach ($groupsToAdd as $gid) {
681+
if (!($groupManager->groupExists($gid))) {
682+
$group = $groupManager->createGroup($gid);
683+
if ($prefix !== '') {
684+
$group->setDisplayName(substr($gid, strlen($prefix) + 1));
685+
}
686+
} else {
687+
$group = $groupManager->get($gid);
672688
}
673-
$groupManager->get($group)->addUser($user);
689+
690+
$group->addUser($user);
674691
}
675692

676693
foreach ($groupsToRemove as $group) {

0 commit comments

Comments
 (0)