Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add idp-based prefix to gid #474

Open
wants to merge 2 commits into
base: stable-3.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions lib/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,43 @@ public function updateAttributes($uid,
}

if ($newGroups !== null) {
$prefix = '';
$mapping = $this->config->getSystemValue('user_saml.unique_groups_per_idp', '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are both settings new? then let's leave out the system one. do not need to make it more bloated then necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requested by customer to have the config in config/config.php instead of using the occ config:app:set

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) {
Comment on lines +669 to +672
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd fancy to have the operators on the left handside for better readability. On the right they are rugged and thus harder to spot. I am not sure whether we have written it down though in the coding style though.

$realUid = $attributes[$mapping][0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking of user id but that's not what it should be, or did I misunderstand it?

Copy link
Member Author

@ArtificialOwl ArtificialOwl Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to avoid a spoof of the domain from one of the idp

list(, $idp) = explode('@', $realUid);
$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