diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-12-09 11:51:13 +0100 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-10-20 12:09:06 +0200 |
commit | 49aa352069f5c4703d01593cb51b2787d2a27aeb (patch) | |
tree | 2ea68770eb34d31f6f1b815ad0b087289652e768 /apps/user_ldap/lib | |
parent | 0fd7a51e3c78fabc50505f4c8c3a27eaad46b00b (diff) | |
download | nextcloud-server-49aa352069f5c4703d01593cb51b2787d2a27aeb.tar.gz nextcloud-server-49aa352069f5c4703d01593cb51b2787d2a27aeb.zip |
Unify a bit the types of the fetcher
Now it will only accept a string as parameter instead of either a string
(DN) or a array (complete record).
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index df34cd349ff..6b50c30ff0a 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -61,15 +61,13 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I protected CappedMemoryCache $cachedGroupsByMember; /** @var CappedMemoryCache<string[]> $cachedNestedGroups array of groups with gid (DN) as key */ protected CappedMemoryCache $cachedNestedGroups; - /** @var GroupPluginManager */ - protected $groupPluginManager; - /** @var LoggerInterface */ - protected $logger; + protected GroupInterface $groupPluginManager; + protected LoggerInterface $logger; /** * @var string $ldapGroupMemberAssocAttr contains the LDAP setting (in lower case) with the same name */ - protected $ldapGroupMemberAssocAttr; + protected string $ldapGroupMemberAssocAttr; public function __construct(Access $access, GroupPluginManager $groupPluginManager) { parent::__construct($access); @@ -305,7 +303,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I $rawMemberReads[$dnGroup] = $members; } if (is_array($members)) { - $fetcher = function ($memberDN) use (&$seen) { + $fetcher = function (string $memberDN) use (&$seen) { return $this->_groupMembers($memberDN, $seen); }; $allMembers = $this->walkNestedGroupsReturnDNs($dnGroup, $fetcher, $members, $seen); @@ -343,7 +341,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I return []; } - $fetcher = function ($groupDN) { + $fetcher = function (string $groupDN) { if (isset($this->cachedNestedGroups[$groupDN])) { $nestedGroups = $this->cachedNestedGroups[$groupDN]; } else { @@ -363,7 +361,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I /** * @psalm-param list<array{dn: list<string>}|string> $list * @psalm-param array<string, int|array|string> $seen List of DN that have already been processed. - * @param Closure(string) $fetcher + * @psalm-param Closure(string) $fetcher */ private function processListFromWalkingNestedGroups(array &$list, array &$seen, string $dn, Closure $fetcher): void { while ($record = array_shift($list)) { @@ -376,7 +374,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I $cacheKey = 'walkNestedGroups_' . $recordDN; $fetched = $this->access->connection->getFromCache($cacheKey); if ($fetched === null) { - $fetched = $fetcher($record); + $fetched = $fetcher($recordDN); $fetched = $this->access->connection->writeToCache($cacheKey, $fetched); } $list = array_merge($list, $fetched); @@ -389,7 +387,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I /** * @psalm-param list<array{dn: list<string>}|string> $list * @psalm-param array<string, int|array|string> $seen List of DN that have already been processed. - * @param Closure(string) $fetcher + * @psalm-param Closure(string) $fetcher */ private function walkNestedGroupsReturnDNs(string $dn, Closure $fetcher, array $list, array &$seen = []): array { $nesting = (int)$this->access->connection->ldapNestedGroups; @@ -405,15 +403,15 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I /** * @psalm-param list<array{dn: list<string>}> $list * @psalm-param array<string, int|array|string> $seen List of DN that have already been processed. + * @psalm-param Closure(string) $fetcher * @return array[] An array of records - * @param Closure(string) $fetcher */ private function walkNestedGroupsReturnRecords(string $dn, Closure $fetcher, array $list, array &$seen = []): array { $nesting = (int)$this->access->connection->ldapNestedGroups; if ($nesting !== 1) { // the keys are numeric, but should hold the DN - return array_reduce($list, function ($transformed, $record) use ($dn) { + return array_reduce($list, function (array $transformed, array $record) use ($dn) { if ($record['dn'][0] != $dn) { $transformed[$record['dn'][0]] = $record; } @@ -893,9 +891,12 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I $groups = $this->access->fetchListOfGroups($filter, [strtolower($this->access->connection->ldapGroupMemberAssocAttr), $this->access->connection->ldapGroupDisplayName, 'dn']); - $fetcher = function ($dn) use (&$seen) { - if (is_array($dn) && isset($dn['dn'][0])) { - $dn = $dn['dn'][0]; + $fetcher = function (string $dn) use (&$seen) { + return $this->getGroupsByMember($dn, $seen); + }; + + if (empty($dn)) { + $dn = ""; } return $this->getGroupsByMember($dn, $seen); }; @@ -1214,7 +1215,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I $validGroupDNs = []; foreach ($listOfGroups as $key => $item) { $dn = is_string($item) ? $item : $item['dn'][0]; - if(is_array($item) && !isset($item[$this->access->connection->ldapGroupDisplayName][0])) { + if (is_array($item) && !isset($item[$this->access->connection->ldapGroupDisplayName][0])) { continue; } $name = $item[$this->access->connection->ldapGroupDisplayName][0] ?? null; |