From 5a8710e65b85551389ca72badcb8ea755fc4f934 Mon Sep 17 00:00:00 2001 From: Thorsten Rinne Date: Sat, 11 Jan 2025 11:50:54 +0100 Subject: [PATCH] fix: corrected login via LDAP (#3319) --- phpmyfaq/src/phpMyFAQ/Auth/AuthLdap.php | 8 +++++++- phpmyfaq/src/phpMyFAQ/User/CurrentUser.php | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/phpmyfaq/src/phpMyFAQ/Auth/AuthLdap.php b/phpmyfaq/src/phpMyFAQ/Auth/AuthLdap.php index 1f9386eceb..facab26eb4 100644 --- a/phpmyfaq/src/phpMyFAQ/Auth/AuthLdap.php +++ b/phpmyfaq/src/phpMyFAQ/Auth/AuthLdap.php @@ -71,8 +71,14 @@ public function __construct(Configuration $configuration) */ public function create(string $login, #[SensitiveParameter] string $password, string $domain = ''): bool { + $result = false; $user = new User($this->configuration); - $result = $user->createUser($login, '', $domain); + + try { + $result = $user->createUser($login, '', $domain); + } catch (\Exception $e) { + $this->configuration->getLogger()->info($e->getMessage()); + } $this->connect($this->activeServer); diff --git a/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php b/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php index ee773fb3a4..ec5bed6186 100644 --- a/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php +++ b/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php @@ -147,6 +147,7 @@ public function login(string $login, string $password): bool } // Attempt to authenticate user by login and password + $this->authContainer = $this->sortAuthContainer($this->authContainer); foreach ($this->authContainer as $authSource => $auth) { if (!$this->checkAuth($auth)) { continue; // Skip invalid Auth objects @@ -753,4 +754,19 @@ protected function isFailedLastLoginAttempt(): bool $result = $this->configuration->getDb()->query($select); return $this->configuration->getDb()->numRows($result) !== 0; } + + protected function sortAuthContainer(array $authContainer): array + { + uksort($authContainer, function ($a, $b) { + if ($a === 'local') { + return 1; + } + if ($b === 'local') { + return -1; + } + return 0; + }); + + return $authContainer; + } }