diff --git a/lib/private/User/LazyUser.php b/lib/private/User/LazyUser.php index cd3e268be48bc..92a0c73521514 100644 --- a/lib/private/User/LazyUser.php +++ b/lib/private/User/LazyUser.php @@ -36,9 +36,12 @@ private function getUser(): IUser { $this->user = $this->userManager->get($this->uid); } } - /** @var IUser */ - $user = $this->user; - return $user; + + if ($this->user === null) { + throw new NoUserException('User not found in backend'); + } + + return $this->user; } public function getUID() { diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index e21759b1e9865..773f806750c23 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -60,14 +60,13 @@ class Manager extends PublicEmitter implements IUserManager { */ private array $cachedUsers = []; - private ICache $cache; - private DisplayNameCache $displayNameCache; public function __construct( private IConfig $config, ICacheFactory $cacheFactory, private IEventDispatcher $eventDispatcher, + private LoggerInterface $logger, ) { $this->cache = new WithLocalCache($cacheFactory->createDistributed('user_backend_map')); $this->listen('\OC\User', 'postDelete', function (IUser $user): void { @@ -201,7 +200,7 @@ public function checkPassword($loginName, $password) { $result = $this->checkPasswordNoLogging($loginName, $password); if ($result === false) { - \OCP\Server::get(LoggerInterface::class)->warning('Login failed: \'' . $loginName . '\' (Remote IP: \'' . \OC::$server->getRequest()->getRemoteAddress() . '\')', ['app' => 'core']); + $this->logger->warning('Login failed: \'' . $loginName . '\' (Remote IP: \'' . \OC::$server->getRequest()->getRemoteAddress() . '\')', ['app' => 'core']); } return $result; @@ -319,11 +318,16 @@ public function getDisabledUsers(?int $limit = null, int $offset = 0, string $se if ($search !== '') { $users = array_filter( $users, - fn (IUser $user): bool => - mb_stripos($user->getUID(), $search) !== false || - mb_stripos($user->getDisplayName(), $search) !== false || - mb_stripos($user->getEMailAddress() ?? '', $search) !== false, - ); + function (IUser $user) use ($search): bool { + try { + return mb_stripos($user->getUID(), $search) !== false || + mb_stripos($user->getDisplayName(), $search) !== false || + mb_stripos($user->getEMailAddress() ?? '', $search) !== false; + } catch (NoUserException $ex) { + $this->logger->error('Error while filtering disabled users', ['exception' => $ex, 'userUID' => $user->getUID()]); + return false; + } + }); } $tempLimit = ($limit === null ? null : $limit + $offset);