From 49f3fa84798c1b9af56c69fdab95108d86ec033f Mon Sep 17 00:00:00 2001 From: Akhil Date: Mon, 16 Jan 2023 15:44:30 +0530 Subject: [PATCH] single argument in fn signature Signed-off-by: Akhil --- apps/user_ldap/lib/User_LDAP.php | 38 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index c4ec80285a647..6406cdc4b50b3 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -114,12 +114,12 @@ public function canChangeAvatar($uid) { * @return string|false * @throws \Exception */ - public function loginName2UserName($loginName, bool $ignoreCacheIfFalseFound = false, bool $processUserAttributes = false) { + public function loginName2UserName($loginName, bool $forceLdapRefetch = false) { $cacheKey = 'loginName2UserName-' . $loginName; $username = $this->access->connection->getFromCache($cacheKey); - $forceLdapFetch = ($username === false && $ignoreCacheIfFalseFound); - if ($username !== null && !$forceLdapFetch) { + $ignoreCache = ($username === false && $forceLdapRefetch); + if ($username !== null && !$ignoreCache) { return $username; } @@ -134,7 +134,7 @@ public function loginName2UserName($loginName, bool $ignoreCacheIfFalseFound = f } $username = $user->getUsername(); $this->access->connection->writeToCache($cacheKey, $username); - if($processUserAttributes) { + if ($forceLdapRefetch) { $user->processAttributes($ldapRecord); } return $username; @@ -180,27 +180,33 @@ public function getLDAPUserByLoginName($loginName) { * @return false|string */ public function checkPassword($uid, $password) { - $username = $this->loginName2UserName($uid, true, true); - if(!$username) { + $username = $this->loginName2UserName($uid, true); + if (!$username) { return false; } - $dn = $this->access->username2dn($username); - //are the credentials OK? - if ($dn && $this->access->areCredentialsValid($dn, $password)) { - $user = $this->access->userManager->get($username); - if (!$user instanceof User) { - $this->logger->warning( - 'LDAP Login: Could not get user object for DN ' . $dn . - '. Maybe the LDAP entry has no set display name attribute?', - ['app' => 'user_ldap'] - ); + $user = $this->access->userManager->get($dn); + + if (!$user instanceof User) { + $this->logger->warning( + 'LDAP Login: Could not get user object for DN ' . $dn . + '. Maybe the LDAP entry has no set display name attribute?', + ['app' => 'user_ldap'] + ); + return false; + } + if ($user->getUsername() !== false) { + //are the credentials OK? + if (!$this->access->areCredentialsValid($dn, $password)) { return false; } + $this->access->cacheUserExists($user->getUsername()); $user->markLogin(); + return $user->getUsername(); } + return false; }