diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2021-06-15 17:30:27 +0200 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2021-06-16 11:35:27 +0200 |
commit | 04411df6950a60a371ac8a4cb175dacfcd917772 (patch) | |
tree | 4cc268b6db987b4b7c50469d02696c6d8b7e8ec9 /apps/user_ldap/lib/LDAPProvider.php | |
parent | eb4e4c462b4d72833aec1f2ba4b97ffe52d1387e (diff) | |
download | nextcloud-server-04411df6950a60a371ac8a4cb175dacfcd917772.tar.gz nextcloud-server-04411df6950a60a371ac8a4cb175dacfcd917772.zip |
Add method to read multi-value attributes from ldap.
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps/user_ldap/lib/LDAPProvider.php')
-rw-r--r-- | apps/user_ldap/lib/LDAPProvider.php | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/apps/user_ldap/lib/LDAPProvider.php b/apps/user_ldap/lib/LDAPProvider.php index 1d2354026d6..dd86ce486ac 100644 --- a/apps/user_ldap/lib/LDAPProvider.php +++ b/apps/user_ldap/lib/LDAPProvider.php @@ -309,32 +309,42 @@ class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport { /** * Get an LDAP attribute for a nextcloud user - * @param string $uid the nextcloud user id to get the attribute for - * @param string $attribute the name of the attribute to read - * @return string|null + * * @throws \Exception if user id was not found in LDAP */ public function getUserAttribute(string $uid, string $attribute): ?string { + $values = $this->getMultiValueUserAttribute($uid, $attribute); + if (count($values) === 0) { + return null; + } + return current($values); + } + + /** + * Get a multi-value LDAP attribute for a nextcloud user + * + * @throws \Exception if user id was not found in LDAP + */ + public function getMultiValueUserAttribute(string $uid, string $attribute): array { if (!$this->userBackend->userExists($uid)) { throw new \Exception('User id not found in LDAP'); } + $access = $this->userBackend->getLDAPAccess($uid); $connection = $access->getConnection(); - $key = $uid . "::" . $attribute; - $cached = $connection->getFromCache($key); + $key = $uid . '-' . $attribute; - if ($cached !== null) { + $cached = $connection->getFromCache($key); + if (is_array($cached)) { return $cached; } - $value = $access->readAttribute($access->username2dn($uid), $attribute); - if (is_array($value) && count($value) > 0) { - $value = current($value); - } else { - return null; + $values = $access->readAttribute($access->username2dn($uid), $attribute); + if ($values === false) { + $values = []; } - $connection->writeToCache($key, $value); - return $value; + $connection->writeToCache($key, $values); + return $values; } } |