parent
17e6402aa9
commit
4e41ce5cdc
|
@ -33,6 +33,7 @@ use \Zend_Config;
|
|||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Logger;
|
||||
use \Icinga\Web\Form\Decorator\HelpText;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Icinga\Web\Form;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use Icinga\Authentication\Backend\DbUserBackend;
|
||||
use \Icinga\Authentication\Backend\DbUserBackend;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Application\Icinga;
|
||||
|
@ -122,6 +122,23 @@ class DbBackendForm extends BaseBackendForm
|
|||
|
||||
public function validateAuthenticationBackend()
|
||||
{
|
||||
try {
|
||||
$name = $this->getBackendName();
|
||||
$db = DbAdapterFactory::getDbAdapter(
|
||||
$this->getValue('backend_' . $this->filterName($name) . '_' . 'resource')
|
||||
);
|
||||
$dbBackend = new DbUserBackend($db);
|
||||
if ($dbBackend->getUserCount() < 1) {
|
||||
$this->addErrorMessage("No users found under the specified database backend");
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->addErrorMessage("Using the specified backend failed: " . $e->getMessage());
|
||||
return false;
|
||||
} catch (\Zend_Db_Statement_Exception $e) {
|
||||
$this->addErrorMessage("Using the specified backend failed: " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ use \Zend_Config;
|
|||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Logger;
|
||||
use \Icinga\Web\Form\Decorator\HelpText;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Icinga\Web\Form;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
namespace Icinga\Authentication\Backend;
|
||||
|
||||
use Zend_Db;
|
||||
use \Zend_Db;
|
||||
use \Icinga\User;
|
||||
use \Icinga\Authentication\UserBackend;
|
||||
use \Icinga\Authentication\Credentials;
|
||||
|
@ -81,9 +81,7 @@ class DbUserBackend implements UserBackend
|
|||
{
|
||||
$this->db = $database;
|
||||
|
||||
/*
|
||||
* Test if the connection is available
|
||||
*/
|
||||
// Test if the connection is available
|
||||
$this->db->getConnection();
|
||||
}
|
||||
|
||||
|
@ -207,4 +205,12 @@ class DbUserBackend implements UserBackend
|
|||
);
|
||||
return $usr;
|
||||
}
|
||||
|
||||
public function getUserCount()
|
||||
{
|
||||
|
||||
$this->db->getConnection();
|
||||
$query = $this->db->select()->from($this->userTable, 'COUNT(*) as count')->query();
|
||||
return $query->fetch()->count;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,13 +31,15 @@ namespace Icinga\Authentication;
|
|||
interface UserBackend
|
||||
{
|
||||
/**
|
||||
* Creates a new object
|
||||
* Create a userbackend from the given configuration or resource
|
||||
*
|
||||
* @param $config
|
||||
*/
|
||||
public function __construct($config);
|
||||
|
||||
/**
|
||||
* Test if the username exists
|
||||
*
|
||||
* @param Credentials $credentials
|
||||
* @return boolean
|
||||
*/
|
||||
|
@ -45,8 +47,16 @@ interface UserBackend
|
|||
|
||||
/**
|
||||
* Authenticate
|
||||
*
|
||||
* @param Credentials $credentials
|
||||
* @return User
|
||||
*/
|
||||
public function authenticate(Credentials $credentials);
|
||||
|
||||
/**
|
||||
* Get the number of users available through this backend
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getUserCount();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue