fix(user_ldap): Do not block access to configuration page upon bad configuration

It should be possible to access configuration page with the local admin
 user even when LDAP configuration is not valid.
This prevent ldap backend from throwing in countUsers to allow this.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2024-02-12 14:17:27 +01:00
parent 61f58e8043
commit b15e4d518a
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
2 changed files with 12 additions and 7 deletions

View file

@ -241,6 +241,7 @@ class Connection extends LDAPUtility {
}
/**
* @throws ServerNotAvailableException When connection failed or configuration is invalid
* @return resource|\LDAP\Connection The LDAP resource
*/
public function getConnectionResource() {

View file

@ -300,7 +300,7 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I
* @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
* name or an instance of that user
* @throws \Exception
* @throws \OC\ServerNotAvailableException
* @throws ServerNotAvailableException
*/
public function userExistsOnLDAP($user, bool $ignoreCache = false): bool {
if (is_string($user)) {
@ -586,14 +586,18 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I
return $this->userPluginManager->countUsers();
}
$filter = $this->access->getFilterForUserCount();
$cacheKey = 'countUsers-'.$filter;
if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
try {
$filter = $this->access->getFilterForUserCount();
$cacheKey = 'countUsers-'.$filter;
if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
return $entries;
}
$entries = $this->access->countUsers($filter);
$this->access->connection->writeToCache($cacheKey, $entries);
return $entries;
} catch (ServerNotAvailableException $e) {
return false;
}
$entries = $this->access->countUsers($filter);
$this->access->connection->writeToCache($cacheKey, $entries);
return $entries;
}
public function countMappedUsers(): int {