diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 2205bc4b2..6358bb42d 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -3,7 +3,6 @@ // {{{ICINGA_LICENSE_HEADER}}} use Icinga\Web\Controller\BaseConfigController; -use Icinga\Web\Widget\Tab; use Icinga\Web\Widget\AlertMessageBox; use Icinga\Web\Notification; use Icinga\Application\Modules\Module; @@ -12,7 +11,6 @@ use Icinga\Web\Form; use Icinga\Web\Widget; use Icinga\Application\Icinga; use Icinga\Application\Config as IcingaConfig; -use Icinga\Data\ResourceFactory; use Icinga\Form\Config\GeneralForm; use Icinga\Form\Config\Authentication\LdapBackendForm; use Icinga\Form\Config\Authentication\DbBackendForm; @@ -21,6 +19,7 @@ use Icinga\Form\Config\ResourceForm; use Icinga\Form\Config\LoggingForm; use Icinga\Form\Config\ConfirmRemovalForm; use Icinga\Config\PreservingIniWriter; +use Icinga\Exception\ConfigurationError; /** @@ -233,29 +232,34 @@ class ConfigController extends BaseConfigController $backendType = $this->getRequest()->getParam('type'); $authenticationConfig = IcingaConfig::app('authentication')->toArray(); - switch ($backendType) { - case 'ldap': - $form = new LdapBackendForm(); - break; - case 'db': - $form = new DbBackendForm(); - break; - case 'autologin': - $existing = array_filter($authenticationConfig, function ($e) { return $e['backend'] === 'autologin'; }); - if (false === empty($existing)) { - $this->addErrorMessage( - $this->translate('An autologin backend already exists') - ); + try { + switch ($backendType) { + case 'ldap': + $form = new LdapBackendForm(); + break; + case 'db': + $form = new DbBackendForm(); + break; + case 'autologin': + foreach ($authenticationConfig as $ac) { + if (array_key_exists('backend', $ac) && $ac['backend'] === 'autologin') { + throw new ConfigurationError( + $this->translate('An autologin backend already exists') + ); + } + } + $form = new AutologinBackendForm(); + break; + default: + $this->addErrorMessage(sprintf( + $this->translate('There is no backend type `%s\''), + $backendType + )); $this->redirectNow('config/configurationerror'); - } - $form = new AutologinBackendForm(); - break; - default: - $this->addErrorMessage(sprintf( - $this->translate('There is no backend type `%s\''), - $backendType - )); - $this->redirectNow('config/configurationerror'); + } + } catch (ConfigurationError $e) { + $this->addErrorMessage($e->getMessage()); + $this->redirectNow('config/configurationerror'); } $request = $this->getRequest();