Show an error message if a ConfigurationError is thrown

This commit is contained in:
Alexander Klimov 2014-07-29 12:25:48 +02:00
parent 4e1e845675
commit e07f2a2b0d

View File

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