Skip to content

Commit

Permalink
add idp-based prefix to gid
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl authored and AndyScherzinger committed May 9, 2024
1 parent f16104d commit 3f26043
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3f26043

Please sign in to comment.