diff --git a/application/controllers/AuthenticationController.php b/application/controllers/AuthenticationController.php index b9a3e1216..be6a4a463 100644 --- a/application/controllers/AuthenticationController.php +++ b/application/controllers/AuthenticationController.php @@ -48,15 +48,6 @@ class AuthenticationController extends ActionController */ protected $requiresAuthentication = false; - /** - * This controller modifies the session - * - * @var bool - * - * @see \Icinga\Web\Controller\ActionController::$modifiesSession - */ - protected $modifiesSession = true; - /** * Log into the application */ @@ -69,9 +60,7 @@ class AuthenticationController extends ActionController $this->view->form->setRequest($this->_request); $this->view->title = "Icinga Web Login"; try { - $auth = AuthManager::getInstance(null, array( - 'writeSession' => $this->modifiesSession - )); + $auth = AuthManager::getInstance(); if ($auth->isAuthenticated()) { $this->redirectNow('index?_render=body'); @@ -104,9 +93,7 @@ class AuthenticationController extends ActionController public function logoutAction() { $this->_helper->layout->setLayout('inline'); - $auth = AuthManager::getInstance(null, array( - 'writeSession' => $this->modifiesSession - )); + $auth = AuthManager::getInstance(); $auth->removeAuthorization(); $this->redirectToLogin(); } diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 93b655090..edee923fa 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -5,7 +5,6 @@ * This file is part of Icinga Web 2. * * Icinga Web 2 - Head for multiple monitoring backends. - * Copyright (C) 2013 Icinga Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,13 +29,15 @@ use \Icinga\Web\Controller\BaseConfigController; use \Icinga\Web\Widget\Tab; +use \Icinga\Web\Widget\AlertMessageBox; use \Icinga\Web\Url; -use \Icinga\Web\Widget\Tabs; use \Icinga\Web\Hook\Configuration\ConfigurationTabBuilder; +use \Icinga\User\Message; use \Icinga\Application\Icinga; use \Icinga\Application\Config as IcingaConfig; use \Icinga\Data\ResourceFactory; use \Icinga\Form\Config\GeneralForm; +use \Icinga\Authentication\Manager as AuthenticationManager; use \Icinga\Form\Config\Authentication\ReorderForm; use \Icinga\Form\Config\Authentication\LdapBackendForm; use \Icinga\Form\Config\Authentication\DbBackendForm; @@ -110,17 +111,17 @@ class ConfigController extends BaseConfigController */ public function indexAction() { + $this->view->messageBox = new AlertMessageBox(true); $form = new GeneralForm(); - $form->setConfiguration(IcingaConfig::app()); $form->setRequest($this->_request); if ($form->isSubmittedAndValid()) { if (!$this->writeConfigFile($form->getConfig(), 'config')) { return; } - $this->view->successMessage = "Config Sucessfully Updated"; + $this->addSuccessMessage("Configuration Sucessfully Updated"); $form->setConfiguration(IcingaConfig::app(), true); - + $this->redirectNow('config/index'); } $this->view->form = $form; } @@ -130,6 +131,8 @@ class ConfigController extends BaseConfigController */ public function loggingAction() { + $this->view->messageBox = new AlertMessageBox(true); + $form = new LoggingForm(); $form->setConfiguration(IcingaConfig::app()); $form->setRequest($this->_request); @@ -137,8 +140,9 @@ class ConfigController extends BaseConfigController if (!$this->writeConfigFile($form->getConfig(), 'config')) { return; } - $this->view->successMessage = "Config Sucessfully Updated"; + $this->addSuccessMessage("Configuration Sucessfully Updated"); $form->setConfiguration(IcingaConfig::app(), true); + $this->redirectNow('config/logging'); } $this->view->form = $form; } @@ -148,6 +152,8 @@ class ConfigController extends BaseConfigController */ public function moduleoverviewAction() { + $this->view->messageBox = new AlertMessageBox(true); + $this->view->modules = Icinga::app()->getModuleManager()->select() ->from('modules') ->order('name'); @@ -164,10 +170,11 @@ class ConfigController extends BaseConfigController try { $manager->enableModule($module); $manager->loadModule($module); - $this->view->successMessage = 'Module "' . $module . '" enabled'; - $this->moduleoverviewAction(); + $this->addSuccessMessage('Module "' . $module . '" enabled'); + $this->redirectNow('config/moduleoverview'); + return; } catch (Exception $e) { - $this->view->exceptionMessage = $e->getMessage(); + $this->view->exceptionMesssage = $e->getMessage(); $this->view->moduleName = $module; $this->view->action = 'enable'; $this->render('module-configuration-error'); @@ -183,8 +190,9 @@ class ConfigController extends BaseConfigController $manager = Icinga::app()->getModuleManager(); try { $manager->disableModule($module); - $this->view->successMessage = 'Module "' . $module . '" disabled'; - $this->moduleoverviewAction(); + $this->addSuccessMessage('Module "' . $module . '" disabled'); + $this->redirectNow('config/moduleoverview'); + return; } catch (Exception $e) { $this->view->exceptionMessage = $e->getMessage(); $this->view->moduleName = $module; @@ -201,6 +209,7 @@ class ConfigController extends BaseConfigController $config = IcingaConfig::app('authentication', true); $order = array_keys($config->toArray()); $this->view->backends = array(); + $this->view->messageBox = new AlertMessageBox(true); foreach ($config as $backend=>$backendConfig) { $form = new ReorderForm(); @@ -211,8 +220,8 @@ class ConfigController extends BaseConfigController if (!$showOnly && $form->isSubmittedAndValid()) { if ($this->writeAuthenticationFile($form->getReorderedConfig($config))) { - $this->view->successMessage = 'Authentication Order Updated'; - $this->authenticationAction(true); + $this->addSuccessMessage('Authentication Order Updated'); + $this->redirectNow('config/authentication'); } return; } @@ -230,6 +239,8 @@ class ConfigController extends BaseConfigController */ public function createauthenticationbackendAction() { + $this->view->messageBox = new AlertMessageBox(true); + if ($this->getRequest()->getParam('type') === 'ldap') { $form = new LdapBackendForm(); } else { @@ -248,7 +259,7 @@ class ConfigController extends BaseConfigController foreach ($form->getConfig() as $backendName => $settings) { unset($settings->{'name'}); if (isset($backendCfg[$backendName])) { - $this->view->errorMessage = 'Backend name already exists'; + $this->addErrorMessage('Backend name already exists'); $this->view->form = $form; $this->render('authentication/create'); return; @@ -257,11 +268,13 @@ class ConfigController extends BaseConfigController } if ($this->writeAuthenticationFile($backendCfg)) { // redirect to overview with success message - $this->view->successMessage = 'Backend Modification Written'; - $this->authenticationAction(true); + $this->addSuccessMessage('Backend Modification Written.'); + $this->redirectNow("config/authentication"); } return; } + + $this->view->messageBox->addForm($form); $this->view->form = $form; $this->render('authentication/create'); } @@ -275,16 +288,18 @@ class ConfigController extends BaseConfigController */ public function editauthenticationbackendAction() { + $this->view->messageBox = new AlertMessageBox(true); + $configArray = IcingaConfig::app('authentication', true)->toArray(); $authBackend = $this->getParam('auth_backend'); if (!isset($configArray[$authBackend])) { - $this->view->errorMessage = 'Can\'t edit: Unknown Authentication Backend Provided'; - $this->authenticationAction(true); + $this->addErrorMessage('Can\'t edit: Unknown Authentication Backend Provided'); + $this->configurationerrorAction(); return; } if (!array_key_exists('resource', $configArray[$authBackend])) { - $this->view->errorMessage = 'Configuration error: Backend "' . $authBackend . '" has no Resource'; - $this->authenticationAction(true); + $this->addErrorMessage('Configuration error: Backend "' . $authBackend . '" has no Resource'); + $this->configurationerrorAction(); return; } @@ -297,8 +312,8 @@ class ConfigController extends BaseConfigController $form = new DbBackendForm(); break; default: - $this->view->errorMessage = 'Can\'t edit: backend type "' . $type . '" of given resource not supported.'; - $this->authenticationAction(true); + $this->addErrorMessage('Can\'t edit: backend type "' . $type . '" of given resource not supported.'); + $this->configurationerrorAction(); return; } @@ -318,12 +333,13 @@ class ConfigController extends BaseConfigController } if ($this->writeAuthenticationFile($backendCfg)) { // redirect to overview with success message - $this->view->successMessage = 'Backend "' . $authBackend . '" created'; - $this->authenticationAction(true); + $this->addSuccessMessage('Backend "' . $authBackend . '" created'); + $this->redirectNow("config/authentication"); } return; } + $this->view->messageBox->addForm($form); $this->view->name = $authBackend; $this->view->form = $form; $this->render('authentication/modify'); @@ -336,16 +352,13 @@ class ConfigController extends BaseConfigController */ public function removeauthenticationbackendAction() { + $this->view->messageBox = new AlertMessageBox(true); + $configArray = IcingaConfig::app('authentication', true)->toArray(); $authBackend = $this->getParam('auth_backend'); if (!isset($configArray[$authBackend])) { - $this->view->errorMessage = 'Can\'t perform removal: Unknown Authentication Backend Provided'; - $this->authenticationAction(true); - return; - } - if (!array_key_exists('resource', $configArray[$authBackend])) { - $this->view->errorMessage = 'Configuration error: Backend "' . $authBackend . '" has no Resource'; - $this->authenticationAction(true); + $this->addSuccessMessage('Can\'t perform removal: Unknown Authentication Backend Provided'); + $this->render('authentication/remove'); return; } @@ -356,8 +369,8 @@ class ConfigController extends BaseConfigController if ($form->isSubmittedAndValid()) { unset($configArray[$authBackend]); if ($this->writeAuthenticationFile($configArray)) { - $this->view->successMessage = 'Authentication Backend "' . $authBackend . '" Removed'; - $this->authenticationAction(true); + $this->addSuccessMessage('Authentication Backend "' . $authBackend . '" Removed'); + $this->redirectNow("config/authentication"); } return; } @@ -369,7 +382,7 @@ class ConfigController extends BaseConfigController public function resourceAction($showOnly = false) { - + $this->view->messageBox = new AlertMessageBox(true); $this->view->resources = IcingaConfig::app('resources', true)->toArray(); $this->render('resource'); } @@ -383,29 +396,31 @@ class ConfigController extends BaseConfigController if ($form->isSubmittedAndValid()) { $name = $form->getName(); if (isset($resources->{$name})) { - $this->view->errorMessage = 'Resource name "' . $name .'" already in use.'; - $this->view->form = $form; - $this->render('resource/create'); - return; + $this->addErrorMessage('Resource name "' . $name .'" already in use.'); + } else { + $resources->{$name} = $form->getConfig(); + if ($this->writeConfigFile($resources, 'resources')) { + $this->addSuccessMessage('Resource "' . $name . '" created.'); + $this->redirectNow("config/resource"); + } } - $resources->{$name} = $form->getConfig(); - if ($this->writeConfigFile($resources, 'resources')) { - $this->view->successMessage = 'Resource "' . $name . '" created.'; - $this->resourceAction(true); - } - return; } + + $this->view->messageBox = new AlertMessageBox(true); + $this->view->messageBox->addForm($form); $this->view->form = $form; $this->render('resource/create'); } public function editresourceAction() { + $this->view->messageBox = new AlertMessageBox(true); + $resources = ResourceFactory::getResourceConfigs(); $name = $this->getParam('resource'); if ($resources->get($name) === null) { - $this->view->errorMessage = 'Can\'t edit: Unknown Resource Provided'; - $this->resourceAction(true); + $this->addErrorMessage('Can\'t edit: Unknown Resource Provided'); + $this->render('resource/modify'); return; } $form = new EditResourceForm(); @@ -423,11 +438,13 @@ class ConfigController extends BaseConfigController } $resources->{$name} = $form->getConfig(); if ($this->writeConfigFile($resources, 'resources')) { - $this->view->successMessage = 'Resource "' . $name . '" created.'; - $this->resourceAction(true); + $this->addSuccessMessage('Resource "' . $name . '" edited.'); + $this->redirectNow("config/resource"); } return; } + + $this->view->messageBox->addForm($form); $this->view->form = $form; $this->view->name = $name; $this->render('resource/modify'); @@ -435,22 +452,36 @@ class ConfigController extends BaseConfigController public function removeresourceAction() { + $this->view->messageBox = new AlertMessageBox(true); + $resources = ResourceFactory::getResourceConfigs()->toArray(); $name = $this->getParam('resource'); if (!isset($resources[$name])) { - $this->view->errorMessage = 'Can\'t remove: Unknown resource provided'; - $this->resourceAction(true); + $this->addSuccessMessage('Can\'t remove: Unknown resource provided'); + $this->render('resource/remove'); return; } $form = new ConfirmRemovalForm(); $form->setRequest($this->getRequest()); $form->setRemoveTarget('resource', $name); + + // Check if selected resource is currently used for authentication + $authConfig = IcingaConfig::app('authentication', true)->toArray(); + foreach ($authConfig as $backendName => $config) { + if (array_key_exists('resource', $config) && $config['resource'] === $name) { + $this->addErrorMessage( + 'Warning: The resource "' . $name . '" is currently used for user authentication by "' . $backendName . '". ' . + ' Deleting it could eventally make login impossible.' + ); + } + } + if ($form->isSubmittedAndValid()) { unset($resources[$name]); if ($this->writeConfigFile($resources, 'resources')) { - $this->view->successMessage = 'Resource "' . $name . '" removed'; - $this->resourceAction(true); + $this->addSuccessMessage('Resource "' . $name . '" removed.'); + $this->redirectNow('config/resource'); } return; } @@ -460,6 +491,19 @@ class ConfigController extends BaseConfigController $this->render('resource/remove'); } + + /** + * Redirect target only for error-states + * + * When an error is opened in the side-pane, redirecting this request to the index or the overview will look + * weird. This action returns a clear page containing only an AlertMessageBox. + */ + public function configurationerrorAction() + { + $this->view->messageBox = new AlertMessageBox(true); + $this->render('error/error'); + } + /** * Write changes to an authentication file * diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index b7d64ec4f..a8245e136 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -40,15 +40,6 @@ use \Icinga\Form\Preference\GeneralForm; class PreferenceController extends BasePreferenceController { - /** - * This controller modifies the session - * - * @var bool - * - * @see \Icinga\Web\Controller\ActionController::$modifiesSession - */ - protected $modifiesSession = true; - /** * Create tabs for this preference controller * diff --git a/application/forms/Config/Resource/EditResourceForm.php b/application/forms/Config/Resource/EditResourceForm.php index 800720097..a70263efe 100644 --- a/application/forms/Config/Resource/EditResourceForm.php +++ b/application/forms/Config/Resource/EditResourceForm.php @@ -390,6 +390,9 @@ class EditResourceForm extends Form !file_exists($config->object_file) || !file_exists($config->status_file) ) { + $this->addErrorMessage( + 'Connectivity validation failed, the provided file or socket does not exist.' + ); return false; } break; @@ -402,6 +405,7 @@ class EditResourceForm extends Form break; } } catch (\Exception $exc) { + $this->addErrorMessage('Connectivity validation failed, connection to the given resource not possible.'); return false; } return true; diff --git a/application/views/scripts/config/authentication.phtml b/application/views/scripts/config/authentication.phtml index 4bb8d947d..ab96e4f13 100644 --- a/application/views/scripts/config/authentication.phtml +++ b/application/views/scripts/config/authentication.phtml @@ -6,20 +6,9 @@ $createDbBackend = $this->href('/config/createAuthenticationBackend', array('typ = $this->tabs->render($this); ?> -errorMessage): ?> -
Create a new backend for authenticating your users. This backend will be added at the end of your authentication order. diff --git a/application/views/scripts/config/authentication/modify.phtml b/application/views/scripts/config/authentication/modify.phtml index 298cbdd6e..ce7ca8a0a 100644 --- a/application/views/scripts/config/authentication/modify.phtml +++ b/application/views/scripts/config/authentication/modify.phtml @@ -3,11 +3,14 @@ Edit Backend "= $this->escape($this->name); ?>" -errorMessage || $this->form->getErrorMessages()): ?> +messageBox)): ?> + = $this->messageBox->render() ?> + + +form->getErrorMessages()): ?>
- Create a new resource to describes a data sourc + Resources are entities that provide data to Icingaweb.
= $this->form ?> \ No newline at end of file diff --git a/application/views/scripts/config/resource/modify.phtml b/application/views/scripts/config/resource/modify.phtml index 9956c3cdf..079c9464d 100644 --- a/application/views/scripts/config/resource/modify.phtml +++ b/application/views/scripts/config/resource/modify.phtml @@ -3,13 +3,16 @@ Edit Resource "= $this->escape($this->name); ?>" -errorMessage || $this->form->getErrorMessages()): ?> +messageBox)): ?> + = $this->messageBox->render() ?> + + +form->getErrorMessages()): ?>- message ?> -
- exception)): ?> -- Message: - = $this->exception->getMessage(); ?> -
- -- = $this->exception->getTraceAsString(); ?> -- -
= var_export(\Zend_Controller_Front::getInstance()->getParams(), true); ?> --
Are you sure you want to remove the backend = $this->escape($this->name) ?>? diff --git a/modules/monitoring/application/views/scripts/config/removeinstance.phtml b/modules/monitoring/application/views/scripts/config/removeinstance.phtml index 6a9711a44..a278cf9b1 100644 --- a/modules/monitoring/application/views/scripts/config/removeinstance.phtml +++ b/modules/monitoring/application/views/scripts/config/removeinstance.phtml @@ -1,12 +1,12 @@ -= $this->tabs->render($this); ?> -
Are you sure you want to remove the instance = $this->escape($this->name) ?>?
- {{WARNING_ICON}} If you have still any environments or views refering to this instance, you won't be able to send commands anymore + If you have still any environments or views refering to this instance, you won't be able to send commands anymore after deletion.
diff --git a/modules/monitoring/application/views/scripts/config/show-configuration.phtml b/modules/monitoring/application/views/scripts/config/show-configuration.phtml index 884a46aac..356c42b7b 100644 --- a/modules/monitoring/application/views/scripts/config/show-configuration.phtml +++ b/modules/monitoring/application/views/scripts/config/show-configuration.phtml @@ -1,7 +1,7 @@ = $this->tabs->render($this); ?>
Your = $this->escape($this->file); ?> configuration couldn't be stored (error: "= $this->exceptionMessage; ?>").
diff --git a/test/php/library/Icinga/Authentication/ManagerTest.php b/test/php/library/Icinga/Authentication/ManagerTest.php
index 73fc430d4..18e58ff9f 100644
--- a/test/php/library/Icinga/Authentication/ManagerTest.php
+++ b/test/php/library/Icinga/Authentication/ManagerTest.php
@@ -179,17 +179,6 @@ class ManagerTest extends BaseTestCase
$this->assertTrue($auth->isAuthenticated());
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Session write after close
- */
- public function testWriteSessionTwice()
- {
- $auth = $this->getManagerInstance($session, false);
- $this->assertFalse($auth->isAuthenticated(true));
- $auth->authenticate(new Credential("jdoe", "passjdoe"));
- }
-
/**
* @expectedException Icinga\Exception\ConfigurationError
* @expectedExceptionMessage No authentication backend set
diff --git a/test/php/library/Icinga/Authentication/PhpSessionTest.php b/test/php/library/Icinga/Authentication/PhpSessionTest.php
index 793293980..cf7e2fee9 100644
--- a/test/php/library/Icinga/Authentication/PhpSessionTest.php
+++ b/test/php/library/Icinga/Authentication/PhpSessionTest.php
@@ -49,67 +49,54 @@ class PhpSessionTest extends BaseTestCase
{
private function getSession()
{
-
if (!is_writable('/tmp')) {
$this->markTestSkipped('Could not write to session directory');
}
return new PhpSession(
array(
'use_cookies' => false,
- 'save_path' => '/tmp'
+ 'save_path' => '/tmp',
+ 'test_session_name' => 'IcingawebUnittest'
)
);
-
}
/**
- * Test the creation of a PhpSession object
- *
- * @runInSeparateProcess
- **/
+ * Test the creation of a PhpSession object
+ *
+ * @runInSeparateProcess
+ */
public function testSessionCreation()
{
$this->getSession();
}
/**
- * Test PhpSession::open()
+ * Test PhpSession::open()
*
- * @runInSeparateProcess
+ * @runInSeparateProcess
*/
- public function testOpenSession()
+ public function testSessionReadWrite()
{
- $this->assertEquals(session_id(), '', 'Asserting test precondition: session not being setup yet ');
$session = $this->getSession();
- $session->open();
- $this->assertNotEquals(session_id(), '', 'Asserting a Session ID being available after PhpSession::open()');
+ $session->purge();
+ $this->assertEquals(null, $session->get('key'));
+ $session->set('key', 'value');
+ $session->write();
+ $session->read();
+ $this->assertEquals('value', $session->get('key'));
}
/**
- * Test a session being closed by PhpSession::close()
+ * Test a session being closed by PhpSession::close()
*
- * @runInSeparateProcess
- **/
- public function testCloseSession()
- {
- $this->assertEquals(session_id(), '', 'Asserting test precondition: session not being setup yet ');
- $session = $this->getSession();
- $session->open();
- $this->assertNotEquals(session_id(), '', 'Asserting a Session ID being available after PhpSession::open()');
- $session->close();
- }
-
- /**
- * Test if a session is correctly purged when calling PhpSession::purge()
- *
- * @runInSeparateProcess
+ * @runInSeparateProcess
*/
public function testPurgeSession()
{
- $this->assertEquals(session_id(), '', 'Asserting test precondition: session not being setup yet ');
$session = $this->getSession();
- $session->open();
- $this->assertNotEquals(session_id(), '', 'Asserting a Session ID being available after PhpSession::open()');
+ $session->set('key2', 'value2');
$session->purge();
- $this->assertEquals(session_id(), '', 'Asserting no Session ID being available after PhpSession::purge()');
+ $session->read();
+ $this->assertEquals(null, $session->get('key2'));
}
}