parent
17e6402aa9
commit
4e41ce5cdc
|
@ -33,6 +33,7 @@ use \Zend_Config;
|
||||||
use \Icinga\Application\Config as IcingaConfig;
|
use \Icinga\Application\Config as IcingaConfig;
|
||||||
use \Icinga\Application\Icinga;
|
use \Icinga\Application\Icinga;
|
||||||
use \Icinga\Application\Logger;
|
use \Icinga\Application\Logger;
|
||||||
|
use \Icinga\Web\Form\Decorator\HelpText;
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
use \Icinga\Application\DbAdapterFactory;
|
||||||
use \Icinga\Web\Form;
|
use \Icinga\Web\Form;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
namespace Icinga\Form\Config\Authentication;
|
namespace Icinga\Form\Config\Authentication;
|
||||||
|
|
||||||
use Icinga\Authentication\Backend\DbUserBackend;
|
use \Icinga\Authentication\Backend\DbUserBackend;
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use \Icinga\Application\Config as IcingaConfig;
|
use \Icinga\Application\Config as IcingaConfig;
|
||||||
use \Icinga\Application\Icinga;
|
use \Icinga\Application\Icinga;
|
||||||
|
@ -122,6 +122,23 @@ class DbBackendForm extends BaseBackendForm
|
||||||
|
|
||||||
public function validateAuthenticationBackend()
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ use \Zend_Config;
|
||||||
use \Icinga\Application\Config as IcingaConfig;
|
use \Icinga\Application\Config as IcingaConfig;
|
||||||
use \Icinga\Application\Icinga;
|
use \Icinga\Application\Icinga;
|
||||||
use \Icinga\Application\Logger;
|
use \Icinga\Application\Logger;
|
||||||
use \Icinga\Web\Form\Decorator\HelpText;
|
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
use \Icinga\Application\DbAdapterFactory;
|
||||||
use \Icinga\Web\Form;
|
use \Icinga\Web\Form;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
namespace Icinga\Authentication\Backend;
|
namespace Icinga\Authentication\Backend;
|
||||||
|
|
||||||
use Zend_Db;
|
use \Zend_Db;
|
||||||
use \Icinga\User;
|
use \Icinga\User;
|
||||||
use \Icinga\Authentication\UserBackend;
|
use \Icinga\Authentication\UserBackend;
|
||||||
use \Icinga\Authentication\Credentials;
|
use \Icinga\Authentication\Credentials;
|
||||||
|
@ -81,9 +81,7 @@ class DbUserBackend implements UserBackend
|
||||||
{
|
{
|
||||||
$this->db = $database;
|
$this->db = $database;
|
||||||
|
|
||||||
/*
|
// Test if the connection is available
|
||||||
* Test if the connection is available
|
|
||||||
*/
|
|
||||||
$this->db->getConnection();
|
$this->db->getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,4 +205,12 @@ class DbUserBackend implements UserBackend
|
||||||
);
|
);
|
||||||
return $usr;
|
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
|
interface UserBackend
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a new object
|
* Create a userbackend from the given configuration or resource
|
||||||
|
*
|
||||||
* @param $config
|
* @param $config
|
||||||
*/
|
*/
|
||||||
public function __construct($config);
|
public function __construct($config);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if the username exists
|
* Test if the username exists
|
||||||
|
*
|
||||||
* @param Credentials $credentials
|
* @param Credentials $credentials
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
@ -45,8 +47,16 @@ interface UserBackend
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticate
|
* Authenticate
|
||||||
|
*
|
||||||
* @param Credentials $credentials
|
* @param Credentials $credentials
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
public function authenticate(Credentials $credentials);
|
public function authenticate(Credentials $credentials);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of users available through this backend
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getUserCount();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue