Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix user's roles update
Browse files Browse the repository at this point in the history
  • Loading branch information
c12simple committed Jun 15, 2016
1 parent 0e000ff commit 4d3dc1f
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions core/src/plugins/auth.ldap/class.ldapAuthDriver.php
Expand Up @@ -760,15 +760,25 @@ public function updateUserObject(&$userObject)
$userroles = $userObject->getRoles();
//remove all mapped roles before

$userroles = $userObject->getRoles();
//remove all mapped roles before

$oldRoles = array();
$newRoles = array();

if (is_array($userroles)) {
foreach ($userroles as $key => $role) {
if ((AuthService::getRole($key)) && !(strpos($key, $this->mappedRolePrefix) === false)) {
$userObject->removeRole($key);
if (isSet($matchFilter) && !preg_match($matchFilter, $key)) continue;
if (isSet($valueFilters) && !in_array($key, $valueFilters)) continue;
//$userObject->removeRole($key);
$oldRoles[$key] = $role;
}
}
}
$userObject->recomputeMergedRole();
//$userObject->recomputeMergedRole();

// Detect changes
foreach ($memberValues as $uniqValue => $fullDN) {
$uniqValueWithPrefix = $rolePrefix . $uniqValue;
if (isSet($matchFilter) && !preg_match($matchFilter, $uniqValueWithPrefix)) continue;
Expand All @@ -779,9 +789,30 @@ public function updateUserObject(&$userObject)
$roleToAdd->setLabel($uniqValue);
AuthService::updateRole($roleToAdd);
}
$userObject->addRole($roleToAdd);
$newRoles[$roleToAdd->getId()] = $roleToAdd;
//$userObject->addRole($roleToAdd);
}

if((count(array_diff(array_keys($oldRoles), array_keys($newRoles))) > 0) ||
(count(array_diff(array_keys($newRoles), array_keys($oldRoles))) > 0) )
{
// remove old roles
foreach ($oldRoles as $key => $role) {
if ((AuthService::getRole($key)) && !(strpos($key, $this->mappedRolePrefix) === false)) {
$userObject->removeRole($key);
}
}

//Add new roles;
foreach($newRoles as $key => $role){
if ((AuthService::getRole($key)) && !(strpos($key, $this->mappedRolePrefix) === false)) {
$userObject->addRole($role);
}
}
$userObject->recomputeMergedRole();
$changes = true;
}

} else {
foreach ($entry[$key] as $uniqValue) {
if (isSet($matchFilter) && !preg_match($matchFilter, $uniqValue)) continue;
Expand Down

0 comments on commit 4d3dc1f

Please sign in to comment.