aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkhil <akhil.potukuchi@gmail.com>2022-12-22 16:43:24 +0530
committerAkhil <akhil@e.email>2024-08-16 17:55:47 +0530
commitb1230cd53d666bb71bb87165c8b5246d5be583e4 (patch)
tree6801999f01e45dac58000bc7cbffd992da966975
parent13a72d0f0e8f9ba12df2a7f2e0f28a02f4b9ce4a (diff)
downloadnextcloud-server-b1230cd53d666bb71bb87165c8b5246d5be583e4.tar.gz
nextcloud-server-b1230cd53d666bb71bb87165c8b5246d5be583e4.zip
Use cache in LDAP backend's checkPassword
Signed-off-by: Akhil <akhil@e.email>
-rw-r--r--apps/user_ldap/lib/User_LDAP.php20
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php4
2 files changed, 13 insertions, 11 deletions
diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php
index 4273563ff02..7d4cd7ca634 100644
--- a/apps/user_ldap/lib/User_LDAP.php
+++ b/apps/user_ldap/lib/User_LDAP.php
@@ -76,11 +76,12 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I
* @return string|false
* @throws \Exception
*/
- public function loginName2UserName($loginName) {
+ public function loginName2UserName($loginName, bool $forceLdapRefetch = false) {
$cacheKey = 'loginName2UserName-' . $loginName;
$username = $this->access->connection->getFromCache($cacheKey);
- if ($username !== null) {
+ $ignoreCache = ($username === false && $forceLdapRefetch);
+ if ($username !== null && !$ignoreCache) {
return $username;
}
@@ -95,6 +96,9 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I
}
$username = $user->getUsername();
$this->access->connection->writeToCache($cacheKey, $username);
+ if ($forceLdapRefetch) {
+ $user->processAttributes($ldapRecord);
+ }
return $username;
} catch (NotOnLDAP $e) {
$this->access->connection->writeToCache($cacheKey, false);
@@ -138,16 +142,11 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I
* @return false|string
*/
public function checkPassword($uid, $password) {
- try {
- $ldapRecord = $this->getLDAPUserByLoginName($uid);
- } catch (NotOnLDAP $e) {
- $this->logger->debug(
- $e->getMessage(),
- ['app' => 'user_ldap', 'exception' => $e]
- );
+ $username = $this->loginName2UserName($uid, true);
+ if ($username === false) {
return false;
}
- $dn = $ldapRecord['dn'][0];
+ $dn = $this->access->username2dn($username);
$user = $this->access->userManager->get($dn);
if (!$user instanceof User) {
@@ -165,7 +164,6 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I
}
$this->access->cacheUserExists($user->getUsername());
- $user->processAttributes($ldapRecord);
$user->markLogin();
return $user->getUsername();
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index 030e44cc34d..227f13e8538 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -149,6 +149,10 @@ class User_LDAPTest extends TestCase {
->with($this->equalTo('dnOfRoland,dc=test'))
->willReturn($retVal);
$this->access->expects($this->any())
+ ->method('username2dn')
+ ->with($this->equalTo('gunslinger'))
+ ->willReturn('dnOfRoland,dc=test');
+ $this->access->expects($this->any())
->method('stringResemblesDN')
->with($this->equalTo('dnOfRoland,dc=test'))
->willReturn(true);