Skip to content

Commit

Permalink
Fix coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Meyer committed Aug 11, 2014
1 parent d260c3f commit a37e65b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
15 changes: 10 additions & 5 deletions application/forms/Config/Authentication/DbBackendForm.php
Expand Up @@ -4,18 +4,19 @@

namespace Icinga\Form\Config\Authentication;

use \Exception;
use Exception;
use Icinga\Data\ResourceFactory;
use Icinga\Authentication\DbConnection;
use Icinga\Authentication\Backend\DbUserBackend;
use Icinga\Exception\ConfigurationError;
use Icinga\Authentication\Backend\DbUserBackend;

/**
* Form class for adding/modifying database authentication backends
*/
class DbBackendForm extends BaseBackendForm
{
/**
* The available database resources prepared to be used as select input data
*
* @var array
*/
protected $resources;
Expand Down Expand Up @@ -43,6 +44,9 @@ public function init()
$this->resources = array_combine($dbResources, $dbResources);
}

/**
* @see Form::createElements()
*/
public function createElements(array $formData)
{
return array(
Expand Down Expand Up @@ -94,7 +98,7 @@ public function createElements(array $formData)
*
* @return bool Whether validation succeeded or not
*
* @see BaseBackendForm::isValidAuthenticationBackend
* @see BaseBackendForm::isValidAuthenticationBackend()
*/
public function isValidAuthenticationBackend()
{
Expand All @@ -104,13 +108,14 @@ public function isValidAuthenticationBackend()
));
$dbUserBackend = new DbUserBackend($testConnection);
if ($dbUserBackend->count() < 1) {
$this->addErrorMessage(t("No users found under the specified database backend"));
$this->addErrorMessage(t('No users found under the specified database backend'));
return false;
}
} catch (Exception $e) {
$this->addErrorMessage(sprintf(t('Using the specified backend failed: %s'), $e->getMessage()));
return false;
}

return true;
}
}
30 changes: 13 additions & 17 deletions application/forms/Config/Authentication/LdapBackendForm.php
Expand Up @@ -4,19 +4,19 @@

namespace Icinga\Form\Config\Authentication;

use \Exception;
use \Zend_Config;
use Icinga\Web\Form;
use Exception;
use Icinga\Data\ResourceFactory;
use Icinga\Authentication\Backend\LdapUserBackend;
use Icinga\Exception\ConfigurationError;
use Icinga\Authentication\Backend\LdapUserBackend;

/**
* Form for adding or modifying LDAP authentication backends
*/
class LdapBackendForm extends BaseBackendForm
{
/**
* The available ldap resources prepared to be used as select input data
*
* @var array
*/
protected $resources;
Expand Down Expand Up @@ -44,6 +44,9 @@ public function init()
$this->resources = array_combine($ldapResources, $ldapResources);
}

/**
* @see Form::createElements()
*/
public function createElements(array $formData)
{
return array(
Expand Down Expand Up @@ -130,23 +133,21 @@ public function getConfig()
}

/**
* Validate the current configuration by creating a backend and requesting the user count
* Validate the current configuration by connecting to a backend and requesting the user count
*
* @return bool Whether validation succeeded or not
*
* @see BaseBackendForm::isValidAuthenticationBacken
* @see BaseBackendForm::isValidAuthenticationBacken()
*/
public function isValidAuthenticationBackend()
{
if (! ResourceFactory::ldapAvailable()) {
/*
* It should be possible to run icingaweb without the php ldap extension, when
* no ldap backends are needed. When the user tries to create an ldap backend
* without ldap installed we need to show him an error.
*/
if (false === ResourceFactory::ldapAvailable()) {
// It should be possible to run icingaweb without the php ldap extension. When the user
// tries to create an ldap backend without ldap being installed we display an error.
$this->addErrorMessage(t('Using ldap is not possible, the php extension "ldap" is not installed.'));
return false;
}

try {
$cfg = $this->getConfig();
$backendConfig = new Zend_Config($cfg[$this->getValue('name')]);
Expand All @@ -157,11 +158,6 @@ public function isValidAuthenticationBackend()
$backendConfig->user_name_attribute
);
$testConn->assertAuthenticationPossible();
/*
if ($testConn->count() === 0) {
throw new Exception('No Users Found On Directory Server');
}
*/
} catch (Exception $exc) {
$this->addErrorMessage(
t('Connection Validation Failed: ' . $exc->getMessage())
Expand Down

0 comments on commit a37e65b

Please sign in to comment.