diff --git a/application/forms/Config/UserBackend/LdapBackendForm.php b/application/forms/Config/UserBackend/LdapBackendForm.php index 9151134c3..6427fbf34 100644 --- a/application/forms/Config/UserBackend/LdapBackendForm.php +++ b/application/forms/Config/UserBackend/LdapBackendForm.php @@ -4,6 +4,8 @@ namespace Icinga\Forms\Config\UserBackend; use Exception; +use Icinga\Authentication\User\LdapUserBackend; +use Icinga\Data\Inspection; use Icinga\Web\Form; use Icinga\Data\ConfigObject; use Icinga\Data\ResourceFactory; @@ -184,22 +186,16 @@ class LdapBackendForm extends Form */ public static function isValidUserBackend(Form $form) { - try { - $ldapUserBackend = UserBackend::create(null, new ConfigObject($form->getValues())); - $ldapUserBackend->assertAuthenticationPossible(); - } catch (AuthenticationException $e) { - if (($previous = $e->getPrevious()) !== null) { - $form->addError($previous->getMessage()); - } else { - $form->addError($e->getMessage()); - } - - return false; - } catch (Exception $e) { - $form->addError(sprintf($form->translate('Unable to validate authentication: %s'), $e->getMessage())); - return false; + /** + * @var $result Inspection + */ + $result = UserBackend::create(null, new ConfigObject($form->getValues()))->inspect(); + if ($result->hasError()) { + $form->addError($result->getError()); } - return true; + // TODO: display diagnostics in $result->toArray() to the user + + return ! $result->hasError(); } } diff --git a/library/Icinga/Authentication/User/LdapUserBackend.php b/library/Icinga/Authentication/User/LdapUserBackend.php index c6efd0673..ecaa08ef4 100644 --- a/library/Icinga/Authentication/User/LdapUserBackend.php +++ b/library/Icinga/Authentication/User/LdapUserBackend.php @@ -5,6 +5,8 @@ namespace Icinga\Authentication\User; use DateTime; use Icinga\Data\ConfigObject; +use Icinga\Data\Inspectable; +use Icinga\Data\Inspection; use Icinga\Exception\AuthenticationException; use Icinga\Exception\ProgrammingError; use Icinga\Repository\LdapRepository; @@ -13,7 +15,7 @@ use Icinga\Protocol\Ldap\LdapException; use Icinga\Protocol\Ldap\Expression; use Icinga\User; -class LdapUserBackend extends LdapRepository implements UserBackendInterface +class LdapUserBackend extends LdapRepository implements UserBackendInterface, Inspectable { /** * The base DN to use for a query @@ -315,24 +317,32 @@ class LdapUserBackend extends LdapRepository implements UserBackendInterface *