Skip to content

Commit

Permalink
Let the form decide where to get the resource configuration from
Browse files Browse the repository at this point in the history
refs #7163
  • Loading branch information
Johannes Meyer committed Sep 29, 2014
1 parent 0e92e33 commit 4f688fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
18 changes: 13 additions & 5 deletions application/forms/Config/Authentication/DbBackendForm.php
Expand Up @@ -102,19 +102,27 @@ public function onSuccess(Request $request)
*/
public static function isValidAuthenticationBackend(Form $form)
{
$element = $form->getElement('resource');

try {
$dbUserBackend = new DbUserBackend(ResourceFactory::create($element->getValue()));
$dbUserBackend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig()));
if ($dbUserBackend->count() < 1) {
$element->addError(t('No users found under the specified database backend'));
$form->addError(t('No users found under the specified database backend'));
return false;
}
} catch (Exception $e) {
$element->addError(sprintf(t('Using the specified backend failed: %s'), $e->getMessage()));
$form->addError(sprintf(t('Using the specified backend failed: %s'), $e->getMessage()));
return false;
}

return true;
}

/**
* Return the configuration for the chosen resource
*
* @return Zend_Config
*/
public function getResourceConfig()
{
return ResourceFactory::getResourceConfig($this->getValue('resource'));
}
}
20 changes: 16 additions & 4 deletions application/forms/Config/Authentication/LdapBackendForm.php
Expand Up @@ -8,6 +8,7 @@
use Icinga\Web\Form;
use Icinga\Web\Request;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\AuthenticationException;
use Icinga\Authentication\Backend\LdapUserBackend;

/**
Expand Down Expand Up @@ -122,20 +123,31 @@ public function onSuccess(Request $request)
*/
public static function isValidAuthenticationBackend(Form $form)
{
$element = $form->getElement('resource');

try {
$ldapUserBackend = new LdapUserBackend(
ResourceFactory::create($element->getValue()),
ResourceFactory::createResource($form->getResourceConfig()),
$form->getElement('user_class')->getValue(),
$form->getElement('user_name_attribute')->getValue()
);
$ldapUserBackend->assertAuthenticationPossible();
} catch (AuthenticationException $e) {
$form->addError($e->getMessage());
return false;
} catch (Exception $e) {
$element->addError(sprintf(t('Connection validation failed: %s'), $e->getMessage()));
$form->addError(sprintf(t('Unable to validate authentication: %s'), $e->getMessage()));
return false;
}

return true;
}

/**
* Return the configuration for the chosen resource
*
* @return Zend_Config
*/
public function getResourceConfig()
{
return ResourceFactory::getResourceConfig($this->getValue('resource'));
}
}

0 comments on commit 4f688fa

Please sign in to comment.