From cfcaf019bdac01c493ef06650a26d130e175c1dc Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 2 Jun 2014 15:52:58 +0200 Subject: [PATCH] User backends: Throw exception when authentication fails due to an exception refs #5685 --- .../Authentication/Backend/DbUserBackend.php | 14 ++++++++------ .../Authentication/Backend/LdapUserBackend.php | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/library/Icinga/Authentication/Backend/DbUserBackend.php b/library/Icinga/Authentication/Backend/DbUserBackend.php index 03464adc7..fb36b70f3 100644 --- a/library/Icinga/Authentication/Backend/DbUserBackend.php +++ b/library/Icinga/Authentication/Backend/DbUserBackend.php @@ -34,8 +34,8 @@ use \Zend_Db_Expr; use \Zend_Db_Select; use Icinga\Authentication\UserBackend; use Icinga\Data\Db\Connection; -use Icinga\Logger\Logger; use Icinga\User; +use Icinga\Exception\AuthenticationException; class DbUserBackend extends UserBackend { @@ -75,6 +75,7 @@ class DbUserBackend extends UserBackend * @param string $password * * @return bool|null + * @throws AuthenticationException */ public function authenticate(User $user, $password) { @@ -96,13 +97,14 @@ class DbUserBackend extends UserBackend return ($row !== false) ? true : false; } catch (Exception $e) { - Logger::error( + throw new AuthenticationException( sprintf( - 'Failed to authenticate user "%s" with backend "%s". Exception occured: %s', + 'Failed to authenticate user "%s" against backend "%s". An exception was thrown:', $user->getUsername(), - $this->getName(), - $e->getMessage() - ) + $this->getName() + ), + 0, + $e ); } } diff --git a/library/Icinga/Authentication/Backend/LdapUserBackend.php b/library/Icinga/Authentication/Backend/LdapUserBackend.php index f0922e092..d17cb3624 100644 --- a/library/Icinga/Authentication/Backend/LdapUserBackend.php +++ b/library/Icinga/Authentication/Backend/LdapUserBackend.php @@ -31,9 +31,9 @@ namespace Icinga\Authentication\Backend; use \Exception; use Icinga\User; -use Icinga\Logger\Logger; use Icinga\Authentication\UserBackend; use Icinga\Protocol\Ldap\Connection; +use Icinga\Exception\AuthenticationException; class LdapUserBackend extends UserBackend { @@ -95,6 +95,7 @@ class LdapUserBackend extends UserBackend * @param string $password * * @return bool|null + * @throws AuthenticationException */ public function authenticate(User $user, $password) { @@ -104,13 +105,14 @@ class LdapUserBackend extends UserBackend $password ); } catch (Exception $e) { - Logger::error( + throw new AuthenticationException( sprintf( - 'Failed to authenticate user "%s" with backend "%s". Exception occured: %s', + 'Failed to authenticate user "%s" against backend "%s". An exception was thrown:', $user->getUsername(), - $this->getName(), - $e->getMessage() - ) + $this->getName() + ), + 0, + $e ); } }