mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Use cache in LDAP backend's checkPassword
Signed-off-by: Akhil <akhil@e.email>
This commit is contained in:
parent
13a72d0f0e
commit
b1230cd53d
2 changed files with 13 additions and 11 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -148,6 +148,10 @@ class User_LDAPTest extends TestCase {
|
|||
->method('dn2username')
|
||||
->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'))
|
||||
|
|
|
|||
Loading…
Reference in a new issue