Skip to content

Commit

Permalink
Show an error message if a ConfigurationError is thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Jul 29, 2014
1 parent 4e1e845 commit e07f2a2
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions application/controllers/ConfigController.php
Expand Up @@ -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;
Expand All @@ -12,7 +11,6 @@
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;
Expand All @@ -21,6 +19,7 @@
use Icinga\Form\Config\LoggingForm;
use Icinga\Form\Config\ConfirmRemovalForm;
use Icinga\Config\PreservingIniWriter;
use Icinga\Exception\ConfigurationError;


/**
Expand Down Expand Up @@ -233,29 +232,34 @@ public function createauthenticationbackendAction()

$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();
Expand Down

0 comments on commit e07f2a2

Please sign in to comment.