Skip to content

Commit

Permalink
single argument in fn signature
Browse files Browse the repository at this point in the history
Signed-off-by: Akhil <akhil@e.email>
  • Loading branch information
akhil1508 committed Feb 26, 2023
1 parent 1b58bbe commit 49f3fa8
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions apps/user_ldap/lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 49f3fa8

Please sign in to comment.