Skip to content

Commit

Permalink
fix: corrected login via LDAP (#3319)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jan 11, 2025
1 parent 253cec2 commit 5a8710e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion phpmyfaq/src/phpMyFAQ/Auth/AuthLdap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 16 additions & 0 deletions phpmyfaq/src/phpMyFAQ/User/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 5a8710e

Please sign in to comment.