Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/user_ldap/lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public function init($force = false) {
}

/**
* @throws ServerNotAvailableException When connection failed or configuration is invalid
* @return resource|\LDAP\Connection The LDAP resource
*/
public function getConnectionResource() {
Expand Down
18 changes: 11 additions & 7 deletions apps/user_ldap/lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function getUsers($search = '', $limit = 10, $offset = 0) {
* @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)) {
Expand Down Expand Up @@ -586,14 +586,18 @@ public function countUsers() {
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 {
Expand Down
Loading