Skip to content

Commit

Permalink
Make it possible to create an authentication backend of type autologin
Browse files Browse the repository at this point in the history
refs #6434
  • Loading branch information
Al2Klimov committed Jul 24, 2014
1 parent 9c434fe commit 1902b4f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
60 changes: 35 additions & 25 deletions application/controllers/ConfigController.php
Expand Up @@ -16,6 +16,7 @@
use Icinga\Form\Config\GeneralForm;
use Icinga\Form\Config\Authentication\LdapBackendForm;
use Icinga\Form\Config\Authentication\DbBackendForm;
use Icinga\Form\Config\Authentication\AutologinBackendForm;
use Icinga\Form\Config\ResourceForm;
use Icinga\Form\Config\LoggingForm;
use Icinga\Form\Config\ConfirmRemovalForm;
Expand Down Expand Up @@ -228,38 +229,47 @@ public function authenticationAction()
public function createauthenticationbackendAction()
{
$this->view->messageBox = new AlertMessageBox(true);
$this->view->tabs->activate('authentication');

if ($this->getRequest()->getParam('type') === 'ldap') {
$backendType = $this->getRequest()->getParam('type');
$authenticationConfig = IcingaConfig::app('authentication')->toArray();
if ($backendType === 'ldap') {
$form = new LdapBackendForm();
} else {
} else if ($backendType === 'db') {
$form = new DbBackendForm();
} else if ($backendType === 'autologin') {
$existing = array_filter($authenticationConfig, function ($e) { return $e['backend'] === 'autologin'; });
if (false === empty($existing)) {
$this->addErrorMessage(
$this->translate('An autologin backend already exists')
);
$this->redirectNow('config/configurationerror');
}
$form = new AutologinBackendForm();
} else {
$this->addErrorMessage(sprintf(
$this->translate('There is no backend type `%s\''),
$backendType
));
$this->redirectNow('config/configurationerror');
}
if ($this->getParam('auth_backend')) {
$form->setBackendName($this->getParam('auth_backend'));
}
$form->setRequest($this->getRequest());

if ($form->isSubmittedAndValid()) {
$backendCfg = IcingaConfig::app('authentication')->toArray();
foreach ($backendCfg as $backendName => $settings) {
unset($backendCfg[$backendName]['name']);
}
foreach ($form->getConfig() as $backendName => $settings) {
unset($settings->{'name'});
if (isset($backendCfg[$backendName])) {
$this->addErrorMessage('Backend name already exists');
$this->view->form = $form;
$this->render('authentication/create');
return;
$request = $this->getRequest();
if ($request->isPost() && $form->isValid($request->getPost())) {
list($backendName, $backendConfig) = $form->getBackendConfig();
if (isset($authenticationConfig[$backendName])) {
$this->addErrorMessage(
$this->translate('Backend name already exists')
);
} else {
$authenticationConfig[$backendName] = $backendConfig;
if ($this->writeConfigFile($authenticationConfig, 'authentication')) {
$this->addSuccessMessage(
$this->translate('Backend Modification Written.')
);
$this->redirectNow('config/authentication');
}
$backendCfg[$backendName] = $settings;
}
if ($this->writeAuthenticationFile($backendCfg)) {
// redirect to overview with success message
Notification::success('Backend Modification Written.');
$this->redirectNow("config/authentication");
}
return;
}

$this->view->messageBox->addForm($form);
Expand Down
6 changes: 5 additions & 1 deletion application/views/scripts/config/authentication.phtml
Expand Up @@ -11,6 +11,10 @@
<a href="<?= $this->href('/config/createAuthenticationBackend', array('type' => 'db')); ?>">
<?= $this->icon('create.png'); ?><?= $this->translate('Create A New DB Authentication Backend'); ?>
</a>
<br>
<a href="<?= $this->href('/config/createAuthenticationBackend', array('type' => 'autologin')); ?>">
<?= $this->icon('create.png'); ?><?= $this->translate('Create A New Autologin Authentication Backend'); ?>
</a>
</p>
<form id="<?= $form->getName(); ?>" name="<?= $form->getName(); ?>" enctype="<?= $form->getEncType(); ?>" method="<?= $form->getMethod(); ?>">
<?= $form->getElement($form->getTokenElementName()); ?>
Expand Down Expand Up @@ -50,4 +54,4 @@
</tbody>
</table>
</form>
</div>
</div>

0 comments on commit 1902b4f

Please sign in to comment.