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

Commit 688ce91

Browse files
committed
Sync ldap group membership, filter groups from group DN
1 parent 7546380 commit 688ce91

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

core/src/plugins/auth.ldap/class.ldapAuthDriver.php

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ public function getUserEntries($login = null, $countOnly = false, $offset = -1,
250250
}
251251

252252
if(isset($searchAttrArray)){
253-
if(count($searchAttrArray) > 1){
254-
$searchAttrFilter = "(|";
255-
foreach($searchAttrArray as $attr){
256-
$searchAttrFilter .= "(". $attr . "=" . $login . ")";
253+
if(count($searchAttrArray) > 1){
254+
$searchAttrFilter = "(|";
255+
foreach($searchAttrArray as $attr){
256+
$searchAttrFilter .= "(". $attr . "=" . $login . ")";
257257
}
258-
$searchAttrFilter .= ")";
259-
}
258+
$searchAttrFilter .= ")";
259+
}
260260
else{
261261
$searchAttrFilter = "(" . $searchAttrArray[0] . "=" . $login . ")";
262262
}
@@ -748,14 +748,15 @@ public function updateUserObject(&$userObject)
748748
$valueFilters = array_map("trim", explode(",", $filter));
749749
}
750750
if ($key == "memberof") {
751-
751+
if (empty($valueFilters)) {
752+
$valueFilters = $this->getLdapGroupListFromDN();
753+
}
752754
if ($this->mappedRolePrefix) {
753755
$rolePrefix = $this->mappedRolePrefix;
754756
} else {
755757
$rolePrefix = "";
756758
}
757759

758-
/*
759760
$userroles = $userObject->getRoles();
760761
//remove all mapped roles before
761762

@@ -767,7 +768,6 @@ public function updateUserObject(&$userObject)
767768
}
768769
}
769770
$userObject->recomputeMergedRole();
770-
*/
771771

772772
foreach ($memberValues as $uniqValue => $fullDN) {
773773
$uniqValueWithPrefix = $rolePrefix . $uniqValue;
@@ -914,4 +914,35 @@ public function saveCountToCache($fileContent)
914914
file_put_contents($this->getPluginCacheDir() . DIRECTORY_SEPARATOR . $fileName, serialize($fileContent));
915915
}
916916
}
917-
}
917+
918+
public function getLdapGroupListFromDN()
919+
{
920+
$origUsersDN = $this->ldapDN;
921+
$origUsersFilter = $this->ldapFilter;
922+
$origUsersAttr = $this->ldapUserAttr;
923+
$this->ldapDN = $this->ldapGDN;
924+
$this->ldapFilter = $this->ldapGFilter;
925+
$this->ldapUserAttr = $this->ldapGroupAttr;
926+
927+
$entries = $this->getUserEntries();
928+
$returnArray = array();
929+
if (is_array($entries) && $entries["count"] > 0) {
930+
unset($entries["count"]);
931+
foreach ($entries as $key => $entry) {
932+
if(isset($this->mappedRolePrefix)){
933+
$returnArray[$this->mappedRolePrefix . $entry[$this->ldapGroupAttr][0]] = $this->mappedRolePrefix . $entry[$this->ldapGroupAttr][0];
934+
}
935+
else{
936+
$returnArray[$entry[$this->ldapGroupAttr][0]] = $entry[$this->ldapGroupAttr][0];
937+
}
938+
}
939+
}
940+
941+
$this->dynamicFilter = null;
942+
$this->ldapDN = $origUsersDN;
943+
$this->ldapFilter = $origUsersFilter;
944+
$this->ldapUserAttr = $origUsersAttr;
945+
946+
return $returnArray;
947+
}
948+
}

0 commit comments

Comments
 (0)