Skip to content

Commit

Permalink
Check if user is null before getUsername
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Sep 16, 2018
1 parent 40bb452 commit 2d30511
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apps/user_ldap/lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,26 @@ public function canChangeAvatar($uid) {
}

/**
* returns the username for the given login name, if available
* Return the username for the given login name, if available
*
* @param string $loginName
* @return string|false
* @throws \Exception
*/
public function loginName2UserName($loginName) {
$cacheKey = 'loginName2UserName-'.$loginName;
$cacheKey = 'loginName2UserName-' . $loginName;
$username = $this->access->connection->getFromCache($cacheKey);
if(!is_null($username)) {

if ($username !== null) {
return $username;
}

try {
$ldapRecord = $this->getLDAPUserByLoginName($loginName);
$user = $this->access->userManager->get($ldapRecord['dn'][0]);
if($user instanceof OfflineUser) {
if ($user === null || $user instanceof OfflineUser) {
// this path is not really possible, however get() is documented
// to return User or OfflineUser so we are very defensive here.
// to return User, OfflineUser or null so we are very defensive here.
$this->access->connection->writeToCache($cacheKey, false);
return false;
}
Expand Down

0 comments on commit 2d30511

Please sign in to comment.