ConfigController: We're configuring user backends from now on
refs #8826
This commit is contained in:
parent
8875ce7d95
commit
2490d0ae67
|
@ -5,14 +5,15 @@ use Icinga\Application\Config;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Application\Modules\Module;
|
use Icinga\Application\Modules\Module;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Forms\Config\AuthenticationBackendConfigForm;
|
use Icinga\Forms\Config\UserBackendConfigForm;
|
||||||
use Icinga\Forms\Config\AuthenticationBackendReorderForm;
|
use Icinga\Forms\Config\UserBackendReorderForm;
|
||||||
use Icinga\Forms\Config\GeneralConfigForm;
|
use Icinga\Forms\Config\GeneralConfigForm;
|
||||||
use Icinga\Forms\Config\ResourceConfigForm;
|
use Icinga\Forms\Config\ResourceConfigForm;
|
||||||
use Icinga\Forms\ConfirmRemovalForm;
|
use Icinga\Forms\ConfirmRemovalForm;
|
||||||
use Icinga\Security\SecurityException;
|
use Icinga\Security\SecurityException;
|
||||||
use Icinga\Web\Controller;
|
use Icinga\Web\Controller;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
use Icinga\Web\Url;
|
||||||
use Icinga\Web\Widget;
|
use Icinga\Web\Widget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,13 +46,13 @@ class ConfigController extends Controller
|
||||||
));
|
));
|
||||||
$allowedActions[] = 'general';
|
$allowedActions[] = 'general';
|
||||||
}
|
}
|
||||||
if ($auth->hasPermission('config/application/authentication')) {
|
if ($auth->hasPermission('config/application/userbackend')) {
|
||||||
$tabs->add('authentication', array(
|
$tabs->add('userbackend', array(
|
||||||
'title' => $this->translate('Configure how users authenticate with and log into Icinga Web 2'),
|
'title' => $this->translate('Configure how users authenticate with and log into Icinga Web 2'),
|
||||||
'label' => $this->translate('Authentication'),
|
'label' => $this->translate('Authentication'),
|
||||||
'url' => 'config/authentication'
|
'url' => 'config/userbackend'
|
||||||
));
|
));
|
||||||
$allowedActions[] = 'authentication';
|
$allowedActions[] = 'userbackend';
|
||||||
}
|
}
|
||||||
if ($auth->hasPermission('config/application/resources')) {
|
if ($auth->hasPermission('config/application/resources')) {
|
||||||
$tabs->add('resource', array(
|
$tabs->add('resource', array(
|
||||||
|
@ -191,71 +192,72 @@ class ConfigController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for listing and reordering authentication backends
|
* Action for listing and reordering user backends
|
||||||
*/
|
*/
|
||||||
public function authenticationAction()
|
public function userbackendAction()
|
||||||
{
|
{
|
||||||
$this->assertPermission('config/application/authentication');
|
$this->assertPermission('config/application/userbackend');
|
||||||
$form = new AuthenticationBackendReorderForm();
|
$form = new UserBackendReorderForm();
|
||||||
$form->setIniConfig(Config::app('authentication'));
|
$form->setIniConfig(Config::app('authentication'));
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
$this->view->tabs->activate('authentication');
|
$this->view->tabs->activate('userbackend');
|
||||||
$this->render('authentication/reorder');
|
$this->render('userbackend/reorder');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for creating a new authentication backend
|
* Action for creating a new user backend
|
||||||
*/
|
*/
|
||||||
public function createauthenticationbackendAction()
|
public function createuserbackendAction()
|
||||||
{
|
{
|
||||||
$this->assertPermission('config/application/authentication');
|
$this->assertPermission('config/application/userbackend');
|
||||||
$form = new AuthenticationBackendConfigForm();
|
$form = new UserBackendConfigForm();
|
||||||
$form->setTitle($this->translate('Create New Authentication Backend'));
|
$form->setTitle($this->translate('Create New User Backend'));
|
||||||
$form->addDescription($this->translate(
|
$form->addDescription($this->translate(
|
||||||
'Create a new backend for authenticating your users. This backend'
|
'Create a new backend for authenticating your users. This backend'
|
||||||
. ' will be added at the end of your authentication order.'
|
. ' will be added at the end of your authentication order.'
|
||||||
));
|
));
|
||||||
$form->setIniConfig(Config::app('authentication'));
|
$form->setIniConfig(Config::app('authentication'));
|
||||||
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
||||||
$form->setRedirectUrl('config/authentication');
|
$form->setRedirectUrl('config/userbackend');
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
$this->view->tabs->activate('authentication');
|
$this->view->tabs->activate('userbackend');
|
||||||
$this->render('authentication/create');
|
$this->render('userbackend/create');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for editing authentication backends
|
* Action for editing user backends
|
||||||
*/
|
*/
|
||||||
public function editauthenticationbackendAction()
|
public function edituserbackendAction()
|
||||||
{
|
{
|
||||||
$this->assertPermission('config/application/authentication');
|
$this->assertPermission('config/application/userbackend');
|
||||||
$form = new AuthenticationBackendConfigForm();
|
$form = new UserBackendConfigForm();
|
||||||
$form->setTitle($this->translate('Edit Backend'));
|
$form->setTitle($this->translate('Edit User Backend'));
|
||||||
$form->setIniConfig(Config::app('authentication'));
|
$form->setIniConfig(Config::app('authentication'));
|
||||||
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
||||||
$form->setRedirectUrl('config/authentication');
|
$form->setRedirectUrl('config/userbackend');
|
||||||
|
$form->setAction(Url::fromRequest());
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
$this->view->tabs->activate('authentication');
|
$this->view->tabs->activate('userbackend');
|
||||||
$this->render('authentication/modify');
|
$this->render('userbackend/modify');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for removing a backend from the authentication list
|
* Action for removing a user backend
|
||||||
*/
|
*/
|
||||||
public function removeauthenticationbackendAction()
|
public function removeuserbackendAction()
|
||||||
{
|
{
|
||||||
$this->assertPermission('config/application/authentication');
|
$this->assertPermission('config/application/userbackend');
|
||||||
$form = new ConfirmRemovalForm(array(
|
$form = new ConfirmRemovalForm(array(
|
||||||
'onSuccess' => function ($form) {
|
'onSuccess' => function ($form) {
|
||||||
$configForm = new AuthenticationBackendConfigForm();
|
$configForm = new UserBackendConfigForm();
|
||||||
$configForm->setIniConfig(Config::app('authentication'));
|
$configForm->setIniConfig(Config::app('authentication'));
|
||||||
$authBackend = $form->getRequest()->getQuery('auth_backend');
|
$authBackend = $form->getRequest()->getQuery('backend');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$configForm->remove($authBackend);
|
$configForm->remove($authBackend);
|
||||||
|
@ -266,7 +268,7 @@ class ConfigController extends Controller
|
||||||
|
|
||||||
if ($configForm->save()) {
|
if ($configForm->save()) {
|
||||||
Notification::success(sprintf(
|
Notification::success(sprintf(
|
||||||
t('Authentication backend "%s" has been successfully removed'),
|
t('User backend "%s" has been successfully removed'),
|
||||||
$authBackend
|
$authBackend
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
@ -274,13 +276,14 @@ class ConfigController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
$form->setTitle($this->translate('Remove Backend'));
|
$form->setTitle($this->translate('Remove User Backend'));
|
||||||
$form->setRedirectUrl('config/authentication');
|
$form->setRedirectUrl('config/userbackend');
|
||||||
|
$form->setAction(Url::fromRequest());
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
$this->view->tabs->activate('authentication');
|
$this->view->tabs->activate('userbackend');
|
||||||
$this->render('authentication/remove');
|
$this->render('userbackend/remove');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -363,7 +366,7 @@ class ConfigController extends Controller
|
||||||
if ($config->get('resource') === $resource) {
|
if ($config->get('resource') === $resource) {
|
||||||
$form->addDescription(sprintf(
|
$form->addDescription(sprintf(
|
||||||
$this->translate(
|
$this->translate(
|
||||||
'The resource "%s" is currently in use by the authentication backend "%s". ' .
|
'The resource "%s" is currently utilized for authentication by user backend "%s". ' .
|
||||||
'Removing the resource can result in noone being able to log in any longer.'
|
'Removing the resource can result in noone being able to log in any longer.'
|
||||||
),
|
),
|
||||||
$resource,
|
$resource,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
namespace Icinga\Forms\Config\Authentication;
|
namespace Icinga\Forms\Config\UserBackend;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
@ -10,7 +10,7 @@ use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Authentication\User\DbUserBackend;
|
use Icinga\Authentication\User\DbUserBackend;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form class for adding/modifying database authentication backends
|
* Form class for adding/modifying database user backends
|
||||||
*/
|
*/
|
||||||
class DbBackendForm extends Form
|
class DbBackendForm extends Form
|
||||||
{
|
{
|
||||||
|
@ -85,13 +85,13 @@ class DbBackendForm extends Form
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that the selected resource is a valid database authentication backend
|
* Validate that the selected resource is a valid database user backend
|
||||||
*
|
*
|
||||||
* @see Form::onSuccess()
|
* @see Form::onSuccess()
|
||||||
*/
|
*/
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
if (false === static::isValidAuthenticationBackend($this)) {
|
if (false === static::isValidUserBackend($this)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ class DbBackendForm extends Form
|
||||||
*
|
*
|
||||||
* @return bool Whether validation succeeded or not
|
* @return bool Whether validation succeeded or not
|
||||||
*/
|
*/
|
||||||
public static function isValidAuthenticationBackend(Form $form)
|
public static function isValidUserBackend(Form $form)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$dbUserBackend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig()));
|
$dbUserBackend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig()));
|
|
@ -1,13 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
namespace Icinga\Forms\Config\Authentication;
|
namespace Icinga\Forms\Config\UserBackend;
|
||||||
|
|
||||||
use Zend_Validate_Callback;
|
use Zend_Validate_Callback;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form class for adding/modifying authentication backends of type "external"
|
* Form class for adding/modifying user backends of type "external"
|
||||||
*/
|
*/
|
||||||
class ExternalBackendForm extends Form
|
class ExternalBackendForm extends Form
|
||||||
{
|
{
|
||||||
|
@ -90,7 +90,7 @@ class ExternalBackendForm extends Form
|
||||||
*
|
*
|
||||||
* @return bool Whether validation succeeded or not
|
* @return bool Whether validation succeeded or not
|
||||||
*/
|
*/
|
||||||
public static function isValidAuthenticationBackend(Form $form)
|
public static function isValidUserBackend(Form $form)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
namespace Icinga\Forms\Config\Authentication;
|
namespace Icinga\Forms\Config\UserBackend;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
@ -11,7 +11,7 @@ use Icinga\Exception\AuthenticationException;
|
||||||
use Icinga\Authentication\User\LdapUserBackend;
|
use Icinga\Authentication\User\LdapUserBackend;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form class for adding/modifying LDAP authentication backends
|
* Form class for adding/modifying LDAP user backends
|
||||||
*/
|
*/
|
||||||
class LdapBackendForm extends Form
|
class LdapBackendForm extends Form
|
||||||
{
|
{
|
||||||
|
@ -149,13 +149,13 @@ class LdapBackendForm extends Form
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that the selected resource is a valid ldap authentication backend
|
* Validate that the selected resource is a valid ldap user backend
|
||||||
*
|
*
|
||||||
* @see Form::onSuccess()
|
* @see Form::onSuccess()
|
||||||
*/
|
*/
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
if (false === static::isValidAuthenticationBackend($this)) {
|
if (false === static::isValidUserBackend($this)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ class LdapBackendForm extends Form
|
||||||
*
|
*
|
||||||
* @return bool Whether validation succeeded or not
|
* @return bool Whether validation succeeded or not
|
||||||
*/
|
*/
|
||||||
public static function isValidAuthenticationBackend(Form $form)
|
public static function isValidUserBackend(Form $form)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$ldapUserBackend = new LdapUserBackend(ResourceFactory::createResource($form->getResourceConfig()));
|
$ldapUserBackend = new LdapUserBackend(ResourceFactory::createResource($form->getResourceConfig()));
|
|
@ -11,11 +11,11 @@ use Icinga\Application\Platform;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Forms\Config\Authentication\DbBackendForm;
|
use Icinga\Forms\Config\UserBackend\DbBackendForm;
|
||||||
use Icinga\Forms\Config\Authentication\LdapBackendForm;
|
use Icinga\Forms\Config\UserBackend\LdapBackendForm;
|
||||||
use Icinga\Forms\Config\Authentication\ExternalBackendForm;
|
use Icinga\Forms\Config\UserBackend\ExternalBackendForm;
|
||||||
|
|
||||||
class AuthenticationBackendConfigForm extends ConfigForm
|
class UserBackendConfigForm extends ConfigForm
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The available resources split by type
|
* The available resources split by type
|
||||||
|
@ -76,7 +76,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a particular authentication backend
|
* Add a particular user backend
|
||||||
*
|
*
|
||||||
* The backend to add is identified by the array-key `name'.
|
* The backend to add is identified by the array-key `name'.
|
||||||
*
|
*
|
||||||
|
@ -90,9 +90,9 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
{
|
{
|
||||||
$name = isset($values['name']) ? $values['name'] : '';
|
$name = isset($values['name']) ? $values['name'] : '';
|
||||||
if (! $name) {
|
if (! $name) {
|
||||||
throw new InvalidArgumentException($this->translate('Authentication backend name missing'));
|
throw new InvalidArgumentException($this->translate('User backend name missing'));
|
||||||
} elseif ($this->config->hasSection($name)) {
|
} elseif ($this->config->hasSection($name)) {
|
||||||
throw new InvalidArgumentException($this->translate('Authentication backend already exists'));
|
throw new InvalidArgumentException($this->translate('User backend already exists'));
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($values['name']);
|
unset($values['name']);
|
||||||
|
@ -101,7 +101,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit a particular authentication backend
|
* Edit a particular user backend
|
||||||
*
|
*
|
||||||
* @param string $name The name of the backend to edit
|
* @param string $name The name of the backend to edit
|
||||||
* @param array $values The values to edit the configuration with
|
* @param array $values The values to edit the configuration with
|
||||||
|
@ -113,11 +113,11 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
public function edit($name, array $values)
|
public function edit($name, array $values)
|
||||||
{
|
{
|
||||||
if (! $name) {
|
if (! $name) {
|
||||||
throw new InvalidArgumentException($this->translate('Old authentication backend name missing'));
|
throw new InvalidArgumentException($this->translate('Old user backend name missing'));
|
||||||
} elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) {
|
} elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) {
|
||||||
throw new InvalidArgumentException($this->translate('New authentication backend name missing'));
|
throw new InvalidArgumentException($this->translate('New user backend name missing'));
|
||||||
} elseif (! $this->config->hasSection($name)) {
|
} elseif (! $this->config->hasSection($name)) {
|
||||||
throw new InvalidArgumentException($this->translate('Unknown authentication backend provided'));
|
throw new InvalidArgumentException($this->translate('Unknown user backend provided'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$backendConfig = $this->config->getSection($name);
|
$backendConfig = $this->config->getSection($name);
|
||||||
|
@ -132,7 +132,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the given authentication backend
|
* Remove the given user backend
|
||||||
*
|
*
|
||||||
* @param string $name The name of the backend to remove
|
* @param string $name The name of the backend to remove
|
||||||
*
|
*
|
||||||
|
@ -143,9 +143,9 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
public function remove($name)
|
public function remove($name)
|
||||||
{
|
{
|
||||||
if (! $name) {
|
if (! $name) {
|
||||||
throw new InvalidArgumentException($this->translate('Authentication backend name missing'));
|
throw new InvalidArgumentException($this->translate('user backend name missing'));
|
||||||
} elseif (! $this->config->hasSection($name)) {
|
} elseif (! $this->config->hasSection($name)) {
|
||||||
throw new InvalidArgumentException($this->translate('Unknown authentication backend provided'));
|
throw new InvalidArgumentException($this->translate('Unknown user backend provided'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$backendConfig = $this->config->getSection($name);
|
$backendConfig = $this->config->getSection($name);
|
||||||
|
@ -154,7 +154,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the given authentication backend up or down in order
|
* Move the given user backend up or down in order
|
||||||
*
|
*
|
||||||
* @param string $name The name of the backend to be moved
|
* @param string $name The name of the backend to be moved
|
||||||
* @param int $position The new (absolute) position of the backend
|
* @param int $position The new (absolute) position of the backend
|
||||||
|
@ -166,9 +166,9 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
public function move($name, $position)
|
public function move($name, $position)
|
||||||
{
|
{
|
||||||
if (! $name) {
|
if (! $name) {
|
||||||
throw new InvalidArgumentException($this->translate('Authentication backend name missing'));
|
throw new InvalidArgumentException($this->translate('User backend name missing'));
|
||||||
} elseif (! $this->config->hasSection($name)) {
|
} elseif (! $this->config->hasSection($name)) {
|
||||||
throw new InvalidArgumentException($this->translate('Unknown authentication backend provided'));
|
throw new InvalidArgumentException($this->translate('Unknown user backend provided'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$backendOrder = $this->config->keys();
|
$backendOrder = $this->config->keys();
|
||||||
|
@ -186,7 +186,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add or edit an authentication backend and save the configuration
|
* Add or edit an user backend and save the configuration
|
||||||
*
|
*
|
||||||
* Performs a connectivity validation using the submitted values. A checkbox is
|
* Performs a connectivity validation using the submitted values. A checkbox is
|
||||||
* added to the form to skip the check if it fails and redirection is aborted.
|
* added to the form to skip the check if it fails and redirection is aborted.
|
||||||
|
@ -197,20 +197,20 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
{
|
{
|
||||||
if (($el = $this->getElement('force_creation')) === null || false === $el->isChecked()) {
|
if (($el = $this->getElement('force_creation')) === null || false === $el->isChecked()) {
|
||||||
$backendForm = $this->getBackendForm($this->getElement('type')->getValue());
|
$backendForm = $this->getBackendForm($this->getElement('type')->getValue());
|
||||||
if (false === $backendForm::isValidAuthenticationBackend($this)) {
|
if (false === $backendForm::isValidUserBackend($this)) {
|
||||||
$this->addElement($this->getForceCreationCheckbox());
|
$this->addElement($this->getForceCreationCheckbox());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$authBackend = $this->request->getQuery('auth_backend');
|
$authBackend = $this->request->getQuery('backend');
|
||||||
try {
|
try {
|
||||||
if ($authBackend === null) { // create new backend
|
if ($authBackend === null) { // create new backend
|
||||||
$this->add($this->getValues());
|
$this->add($this->getValues());
|
||||||
$message = $this->translate('Authentication backend "%s" has been successfully created');
|
$message = $this->translate('User backend "%s" has been successfully created');
|
||||||
} else { // edit existing backend
|
} else { // edit existing backend
|
||||||
$this->edit($authBackend, $this->getValues());
|
$this->edit($authBackend, $this->getValues());
|
||||||
$message = $this->translate('Authentication backend "%s" has been successfully changed');
|
$message = $this->translate('User backend "%s" has been successfully changed');
|
||||||
}
|
}
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
Notification::error($e->getMessage());
|
Notification::error($e->getMessage());
|
||||||
|
@ -225,7 +225,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populate the form in case an authentication backend is being edited
|
* Populate the form in case an user backend is being edited
|
||||||
*
|
*
|
||||||
* @see Form::onRequest()
|
* @see Form::onRequest()
|
||||||
*
|
*
|
||||||
|
@ -233,12 +233,12 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
||||||
*/
|
*/
|
||||||
public function onRequest()
|
public function onRequest()
|
||||||
{
|
{
|
||||||
$authBackend = $this->request->getQuery('auth_backend');
|
$authBackend = $this->request->getQuery('backend');
|
||||||
if ($authBackend !== null) {
|
if ($authBackend !== null) {
|
||||||
if ($authBackend === '') {
|
if ($authBackend === '') {
|
||||||
throw new ConfigurationError($this->translate('Authentication backend name missing'));
|
throw new ConfigurationError($this->translate('User backend name missing'));
|
||||||
} elseif (! $this->config->hasSection($authBackend)) {
|
} elseif (! $this->config->hasSection($authBackend)) {
|
||||||
throw new ConfigurationError($this->translate('Unknown authentication backend provided'));
|
throw new ConfigurationError($this->translate('Unknown user backend provided'));
|
||||||
} elseif ($this->config->getSection($authBackend)->backend === null) {
|
} elseif ($this->config->getSection($authBackend)->backend === null) {
|
||||||
throw new ConfigurationError(
|
throw new ConfigurationError(
|
||||||
sprintf($this->translate('Backend "%s" has no `backend\' setting'), $authBackend)
|
sprintf($this->translate('Backend "%s" has no `backend\' setting'), $authBackend)
|
|
@ -7,7 +7,7 @@ use InvalidArgumentException;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Forms\ConfigForm;
|
use Icinga\Forms\ConfigForm;
|
||||||
|
|
||||||
class AuthenticationBackendReorderForm extends ConfigForm
|
class UserBackendReorderForm extends ConfigForm
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Initialize this form
|
* Initialize this form
|
||||||
|
@ -38,7 +38,7 @@ class AuthenticationBackendReorderForm extends ConfigForm
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the authentication backend order and save the configuration
|
* Update the user backend order and save the configuration
|
||||||
*
|
*
|
||||||
* @see Form::onSuccess()
|
* @see Form::onSuccess()
|
||||||
*/
|
*/
|
||||||
|
@ -62,13 +62,13 @@ class AuthenticationBackendReorderForm extends ConfigForm
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the config form for authentication backends
|
* Return the config form for user backends
|
||||||
*
|
*
|
||||||
* @return ConfigForm
|
* @return ConfigForm
|
||||||
*/
|
*/
|
||||||
protected function getConfigForm()
|
protected function getConfigForm()
|
||||||
{
|
{
|
||||||
$form = new AuthenticationBackendConfigForm();
|
$form = new UserBackendConfigForm();
|
||||||
$form->setIniConfig($this->config);
|
$form->setIniConfig($this->config);
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
|
@ -25,8 +25,8 @@ class RoleForm extends ConfigForm
|
||||||
'config/*' => 'config/*',
|
'config/*' => 'config/*',
|
||||||
'config/application/*' => 'config/application/*',
|
'config/application/*' => 'config/application/*',
|
||||||
'config/application/general' => 'config/application/general',
|
'config/application/general' => 'config/application/general',
|
||||||
'config/application/authentication' => 'config/application/authentication',
|
|
||||||
'config/application/resources' => 'config/application/resources',
|
'config/application/resources' => 'config/application/resources',
|
||||||
|
'config/application/userbackend' => 'config/application/userbackend',
|
||||||
'config/application/usergroupbackend' => 'config/application/usergroupbackend',
|
'config/application/usergroupbackend' => 'config/application/usergroupbackend',
|
||||||
'config/authentication/*' => 'config/authentication/*',
|
'config/authentication/*' => 'config/authentication/*',
|
||||||
'config/authentication/users/*' => 'config/authentication/users/*',
|
'config/authentication/users/*' => 'config/authentication/users/*',
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
<?= $tabs; ?>
|
<?= $tabs; ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="content" data-base-target="_next">
|
<div class="content" data-base-target="_next">
|
||||||
<a href="<?= $this->href('/config/createAuthenticationBackend'); ?>">
|
<a href="<?= $this->href('/config/createuserbackend'); ?>">
|
||||||
<?= $this->icon('plus'); ?><?= $this->translate('Create A New Authentication Backend'); ?>
|
<?= $this->icon('plus'); ?><?= $this->translate('Create A New User Backend'); ?>
|
||||||
</a>
|
</a>
|
||||||
<div id="authentication-reorder-form">
|
<div id="authentication-reorder-form">
|
||||||
<?= $form; ?>
|
<?= $form; ?>
|
|
@ -12,22 +12,22 @@
|
||||||
<td class="action">
|
<td class="action">
|
||||||
<?= $this->qlink(
|
<?= $this->qlink(
|
||||||
$backendNames[$i],
|
$backendNames[$i],
|
||||||
'config/editAuthenticationBackend',
|
'config/edituserbackend',
|
||||||
array('auth_backend' => $backendNames[$i]),
|
array('backend' => $backendNames[$i]),
|
||||||
array(
|
array(
|
||||||
'icon' => 'edit',
|
'icon' => 'edit',
|
||||||
'title' => sprintf($this->translate('Edit authentication backend %s'), $backendNames[$i])
|
'title' => sprintf($this->translate('Edit user backend %s'), $backendNames[$i])
|
||||||
)
|
)
|
||||||
); ?>
|
); ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= $this->qlink(
|
<?= $this->qlink(
|
||||||
'',
|
'',
|
||||||
'config/removeAuthenticationBackend',
|
'config/removeuserbackend',
|
||||||
array('auth_backend' => $backendNames[$i]),
|
array('backend' => $backendNames[$i]),
|
||||||
array(
|
array(
|
||||||
'icon' => 'trash',
|
'icon' => 'trash',
|
||||||
'title' => sprintf($this->translate('Remove authentication backend %s'), $backendNames[$i])
|
'title' => sprintf($this->translate('Remove user backend %s'), $backendNames[$i])
|
||||||
)
|
)
|
||||||
); ?>
|
); ?>
|
||||||
</td>
|
</td>
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
); ?>" title="<?= $this->translate(
|
); ?>" title="<?= $this->translate(
|
||||||
'Move up in authentication order'
|
'Move up in authentication order'
|
||||||
); ?>" aria-label="<?= sprintf(
|
); ?>" aria-label="<?= sprintf(
|
||||||
$this->translate('Move authentication backend %s upwards'),
|
$this->translate('Move user backend %s upwards'),
|
||||||
$backendNames[$i]
|
$backendNames[$i]
|
||||||
); ?>">
|
); ?>">
|
||||||
<?= $this->icon('up-big'); ?>
|
<?= $this->icon('up-big'); ?>
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
); ?>" title="<?= $this->translate(
|
); ?>" title="<?= $this->translate(
|
||||||
'Move down in authentication order'
|
'Move down in authentication order'
|
||||||
); ?>" aria-label="<?= sprintf(
|
); ?>" aria-label="<?= sprintf(
|
||||||
$this->translate('Move authentication backend %s downwards'),
|
$this->translate('Move user backend %s downwards'),
|
||||||
$backendNames[$i]
|
$backendNames[$i]
|
||||||
); ?>">
|
); ?>">
|
||||||
<?= $this->icon('down-big'); ?>
|
<?= $this->icon('down-big'); ?>
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
namespace Icinga\Module\Setup\Forms;
|
namespace Icinga\Module\Setup\Forms;
|
||||||
|
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
use Icinga\Forms\Config\Authentication\DbBackendForm;
|
use Icinga\Forms\Config\UserBackend\DbBackendForm;
|
||||||
use Icinga\Forms\Config\Authentication\LdapBackendForm;
|
use Icinga\Forms\Config\UserBackend\LdapBackendForm;
|
||||||
use Icinga\Forms\Config\Authentication\ExternalBackendForm;
|
use Icinga\Forms\Config\UserBackend\ExternalBackendForm;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,7 +105,7 @@ class AuthBackendPage extends Form
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) {
|
if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) {
|
||||||
if ($this->config['type'] === 'ldap' && false === LdapBackendForm::isValidAuthenticationBackend($this)) {
|
if ($this->config['type'] === 'ldap' && false === LdapBackendForm::isValidUserBackend($this)) {
|
||||||
$this->addSkipValidationCheckbox();
|
$this->addSkipValidationCheckbox();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
namespace Tests\Icinga\Forms\Config\Authentication;
|
namespace Tests\Icinga\Forms\Config\UserBackend;
|
||||||
|
|
||||||
// Necessary as some of these tests disable phpunit's preservation
|
// Necessary as some of these tests disable phpunit's preservation
|
||||||
// of the global state (e.g. autoloaders are in the global state)
|
// of the global state (e.g. autoloaders are in the global state)
|
||||||
|
@ -10,7 +10,7 @@ require_once realpath(dirname(__FILE__) . '/../../../../bootstrap.php');
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Icinga\Forms\Config\Authentication\DbBackendForm;
|
use Icinga\Forms\Config\UserBackend\DbBackendForm;
|
||||||
|
|
||||||
class DbBackendFormTest extends BaseTestCase
|
class DbBackendFormTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ class DbBackendFormTest extends BaseTestCase
|
||||||
->andReturn(2);
|
->andReturn(2);
|
||||||
|
|
||||||
// Passing array(null) is required to make Mockery call the constructor...
|
// Passing array(null) is required to make Mockery call the constructor...
|
||||||
$form = Mockery::mock('Icinga\Forms\Config\Authentication\DbBackendForm[getView]', array(null));
|
$form = Mockery::mock('Icinga\Forms\Config\UserBackend\DbBackendForm[getView]', array(null));
|
||||||
$form->shouldReceive('getView->escape')
|
$form->shouldReceive('getView->escape')
|
||||||
->with(Mockery::type('string'))
|
->with(Mockery::type('string'))
|
||||||
->andReturnUsing(function ($s) { return $s; });
|
->andReturnUsing(function ($s) { return $s; });
|
||||||
|
@ -41,8 +41,8 @@ class DbBackendFormTest extends BaseTestCase
|
||||||
$form->populate(array('resource' => 'test_db_backend'));
|
$form->populate(array('resource' => 'test_db_backend'));
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
DbBackendForm::isValidAuthenticationBackend($form),
|
DbBackendForm::isValidUserBackend($form),
|
||||||
'DbBackendForm claims that a valid authentication backend with users is not valid'
|
'DbBackendForm claims that a valid user backend with users is not valid'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class DbBackendFormTest extends BaseTestCase
|
||||||
->andReturn(0);
|
->andReturn(0);
|
||||||
|
|
||||||
// Passing array(null) is required to make Mockery call the constructor...
|
// Passing array(null) is required to make Mockery call the constructor...
|
||||||
$form = Mockery::mock('Icinga\Forms\Config\Authentication\DbBackendForm[getView]', array(null));
|
$form = Mockery::mock('Icinga\Forms\Config\UserBackend\DbBackendForm[getView]', array(null));
|
||||||
$form->shouldReceive('getView->escape')
|
$form->shouldReceive('getView->escape')
|
||||||
->with(Mockery::type('string'))
|
->with(Mockery::type('string'))
|
||||||
->andReturnUsing(function ($s) { return $s; });
|
->andReturnUsing(function ($s) { return $s; });
|
||||||
|
@ -67,8 +67,8 @@ class DbBackendFormTest extends BaseTestCase
|
||||||
$form->populate(array('resource' => 'test_db_backend'));
|
$form->populate(array('resource' => 'test_db_backend'));
|
||||||
|
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
DbBackendForm::isValidAuthenticationBackend($form),
|
DbBackendForm::isValidUserBackend($form),
|
||||||
'DbBackendForm claims that an invalid authentication backend without users is valid'
|
'DbBackendForm claims that an invalid user backend without users is valid'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
namespace Tests\Icinga\Forms\Config\Authentication;
|
namespace Tests\Icinga\Forms\Config\UserBackend;
|
||||||
|
|
||||||
// Necessary as some of these tests disable phpunit's preservation
|
// Necessary as some of these tests disable phpunit's preservation
|
||||||
// of the global state (e.g. autoloaders are in the global state)
|
// of the global state (e.g. autoloaders are in the global state)
|
||||||
|
@ -10,7 +10,7 @@ require_once realpath(dirname(__FILE__) . '/../../../../bootstrap.php');
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Icinga\Forms\Config\Authentication\LdapBackendForm;
|
use Icinga\Forms\Config\UserBackend\LdapBackendForm;
|
||||||
use Icinga\Exception\AuthenticationException;
|
use Icinga\Exception\AuthenticationException;
|
||||||
|
|
||||||
class LdapBackendFormTest extends BaseTestCase
|
class LdapBackendFormTest extends BaseTestCase
|
||||||
|
@ -33,7 +33,7 @@ class LdapBackendFormTest extends BaseTestCase
|
||||||
->shouldReceive('setConfig')->andReturnNull();
|
->shouldReceive('setConfig')->andReturnNull();
|
||||||
|
|
||||||
// Passing array(null) is required to make Mockery call the constructor...
|
// Passing array(null) is required to make Mockery call the constructor...
|
||||||
$form = Mockery::mock('Icinga\Forms\Config\Authentication\LdapBackendForm[getView]', array(null));
|
$form = Mockery::mock('Icinga\Forms\Config\UserBackend\LdapBackendForm[getView]', array(null));
|
||||||
$form->shouldReceive('getView->escape')
|
$form->shouldReceive('getView->escape')
|
||||||
->with(Mockery::type('string'))
|
->with(Mockery::type('string'))
|
||||||
->andReturnUsing(function ($s) { return $s; });
|
->andReturnUsing(function ($s) { return $s; });
|
||||||
|
@ -42,8 +42,8 @@ class LdapBackendFormTest extends BaseTestCase
|
||||||
$form->populate(array('resource' => 'test_ldap_backend'));
|
$form->populate(array('resource' => 'test_ldap_backend'));
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
LdapBackendForm::isValidAuthenticationBackend($form),
|
LdapBackendForm::isValidUserBackend($form),
|
||||||
'LdapBackendForm claims that a valid authentication backend with users is not valid'
|
'LdapBackendForm claims that a valid user backend with users is not valid'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class LdapBackendFormTest extends BaseTestCase
|
||||||
->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException);
|
->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException);
|
||||||
|
|
||||||
// Passing array(null) is required to make Mockery call the constructor...
|
// Passing array(null) is required to make Mockery call the constructor...
|
||||||
$form = Mockery::mock('Icinga\Forms\Config\Authentication\LdapBackendForm[getView]', array(null));
|
$form = Mockery::mock('Icinga\Forms\Config\UserBackend\LdapBackendForm[getView]', array(null));
|
||||||
$form->shouldReceive('getView->escape')
|
$form->shouldReceive('getView->escape')
|
||||||
->with(Mockery::type('string'))
|
->with(Mockery::type('string'))
|
||||||
->andReturnUsing(function ($s) { return $s; });
|
->andReturnUsing(function ($s) { return $s; });
|
||||||
|
@ -67,8 +67,8 @@ class LdapBackendFormTest extends BaseTestCase
|
||||||
$form->populate(array('resource' => 'test_ldap_backend'));
|
$form->populate(array('resource' => 'test_ldap_backend'));
|
||||||
|
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
LdapBackendForm::isValidAuthenticationBackend($form),
|
LdapBackendForm::isValidUserBackend($form),
|
||||||
'LdapBackendForm claims that an invalid authentication backend without users is valid'
|
'LdapBackendForm claims that an invalid user backend without users is valid'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@ namespace Tests\Icinga\Forms\Config;
|
||||||
|
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Forms\Config\AuthenticationBackendConfigForm;
|
use Icinga\Forms\Config\UserBackendConfigForm;
|
||||||
use Icinga\Forms\Config\AuthenticationBackendReorderForm;
|
use Icinga\Forms\Config\UserBackendReorderForm;
|
||||||
|
|
||||||
class AuthenticationBackendConfigFormWithoutSave extends AuthenticationBackendConfigForm
|
class UserBackendConfigFormWithoutSave extends UserBackendConfigForm
|
||||||
{
|
{
|
||||||
public static $newConfig;
|
public static $newConfig;
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@ class AuthenticationBackendConfigFormWithoutSave extends AuthenticationBackendCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AuthenticationBackendReorderFormProvidingConfigFormWithoutSave extends AuthenticationBackendReorderForm
|
class UserBackendReorderFormProvidingConfigFormWithoutSave extends UserBackendReorderForm
|
||||||
{
|
{
|
||||||
public function getConfigForm()
|
public function getConfigForm()
|
||||||
{
|
{
|
||||||
$form = new AuthenticationBackendConfigFormWithoutSave();
|
$form = new UserBackendConfigFormWithoutSave();
|
||||||
$form->setIniConfig($this->config);
|
$form->setIniConfig($this->config);
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class AuthenticationBackendReorderFormTest extends BaseTestCase
|
||||||
->shouldReceive('isPost')->andReturn(true)
|
->shouldReceive('isPost')->andReturn(true)
|
||||||
->shouldReceive('getPost')->andReturn(array('backend_newpos' => 'test3|1'));
|
->shouldReceive('getPost')->andReturn(array('backend_newpos' => 'test3|1'));
|
||||||
|
|
||||||
$form = new AuthenticationBackendReorderFormProvidingConfigFormWithoutSave();
|
$form = new UserBackendReorderFormProvidingConfigFormWithoutSave();
|
||||||
$form->setIniConfig($config);
|
$form->setIniConfig($config);
|
||||||
$form->setTokenDisabled();
|
$form->setTokenDisabled();
|
||||||
$form->setUidDisabled();
|
$form->setUidDisabled();
|
||||||
|
@ -53,8 +53,8 @@ class AuthenticationBackendReorderFormTest extends BaseTestCase
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('test1', 'test3', 'test2'),
|
array('test1', 'test3', 'test2'),
|
||||||
AuthenticationBackendConfigFormWithoutSave::$newConfig->keys(),
|
UserBackendConfigFormWithoutSave::$newConfig->keys(),
|
||||||
'Moving elements with AuthenticationBackendReorderForm does not seem to properly work'
|
'Moving elements with UserBackendReorderForm does not seem to properly work'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue