mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 08:44:10 +02:00
parent
7f30b587be
commit
e6c57f029d
@ -177,11 +177,9 @@ class DbAdapterFactory implements ConfigAwareFactory
|
|||||||
);
|
);
|
||||||
switch ($config->db) {
|
switch ($config->db) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
return self::callFactory('Pdo_Mysql' ,$options);
|
return self::callFactory('Pdo_Mysql', $options);
|
||||||
|
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
return self::callFactory('Pdo_Pgsql', $options);
|
return self::callFactory('Pdo_Pgsql', $options);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ConfigurationError('Unsupported db type ' . $config->db . '.');
|
throw new ConfigurationError('Unsupported db type ' . $config->db . '.');
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,28 @@ use \Icinga\Application\Logger;
|
|||||||
*/
|
*/
|
||||||
class DbUserBackend implements UserBackend
|
class DbUserBackend implements UserBackend
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Mapping of all table column names
|
||||||
|
*/
|
||||||
|
|
||||||
|
const USER_NAME_COLUMN = 'user_name';
|
||||||
|
|
||||||
|
const FIRST_NAME_COLUMN = 'first_name';
|
||||||
|
|
||||||
|
const LAST_NAME_COLUMN = 'last_name';
|
||||||
|
|
||||||
|
const LAST_LOGIN_COLUMN = 'last_login';
|
||||||
|
|
||||||
|
const SALT_COLUMN = 'salt';
|
||||||
|
|
||||||
|
const PASSWORD_COLUMN = 'password';
|
||||||
|
|
||||||
|
const ACTIVE_COLUMN = 'active';
|
||||||
|
|
||||||
|
const DOMAIN_COLUMN = 'domain';
|
||||||
|
|
||||||
|
const EMAIL_COLUMN = 'email';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The database connection that will be used for fetching users
|
* The database connection that will be used for fetching users
|
||||||
*
|
*
|
||||||
@ -58,22 +80,6 @@ class DbUserBackend implements UserBackend
|
|||||||
* @var String
|
* @var String
|
||||||
*/
|
*/
|
||||||
private $userTable = "account";
|
private $userTable = "account";
|
||||||
|
|
||||||
/**
|
|
||||||
* Mapping of columns
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $USER_NAME_COLUMN = 'user_name',
|
|
||||||
$FIRST_NAME_COLUMN = 'first_name',
|
|
||||||
$LAST_NAME_COLUMN = 'last_name',
|
|
||||||
$LAST_LOGIN_COLUMN = 'last_login',
|
|
||||||
$SALT_COLUMN = 'salt',
|
|
||||||
$PASSWORD_COLUMN = 'password',
|
|
||||||
$ACTIVE_COLUMN = 'active',
|
|
||||||
$DOMAIN_COLUMN = 'domain',
|
|
||||||
$EMAIL_COLUMN = 'email';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a DbUserBackend
|
* Create a DbUserBackend
|
||||||
*
|
*
|
||||||
@ -122,12 +128,15 @@ class DbUserBackend implements UserBackend
|
|||||||
$this->db->getConnection();
|
$this->db->getConnection();
|
||||||
$res = $this->db
|
$res = $this->db
|
||||||
->select()->from($this->userTable)
|
->select()->from($this->userTable)
|
||||||
->where($this->USER_NAME_COLUMN.' = ?', $credential->getUsername())
|
->where(self::USER_NAME_COLUMN.' = ?', $credential->getUsername())
|
||||||
->where($this->ACTIVE_COLUMN. ' = ?', true)
|
->where(self::ACTIVE_COLUMN. ' = ?', true)
|
||||||
->where(
|
->where(
|
||||||
$this->PASSWORD_COLUMN. ' = ?', hash_hmac('sha256',
|
self::PASSWORD_COLUMN. ' = ?',
|
||||||
$this->getUserSalt($credential->getUsername()),
|
hash_hmac(
|
||||||
$credential->getPassword())
|
'sha256',
|
||||||
|
$this->getUserSalt($credential->getUsername()),
|
||||||
|
$credential->getPassword()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
->query()->fetch();
|
->query()->fetch();
|
||||||
if (!empty($res)) {
|
if (!empty($res)) {
|
||||||
@ -148,9 +157,10 @@ class DbUserBackend implements UserBackend
|
|||||||
$this->db->update(
|
$this->db->update(
|
||||||
$this->userTable,
|
$this->userTable,
|
||||||
array(
|
array(
|
||||||
$this->LAST_LOGIN_COLUMN => new \Zend_Db_Expr('NOW()')
|
self::LAST_LOGIN_COLUMN => new \Zend_Db_Expr('NOW()')
|
||||||
),
|
),
|
||||||
$this->USER_NAME_COLUMN.' = '.$this->db->quoteInto('?', $username));
|
self::USER_NAME_COLUMN.' = '.$this->db->quoteInto('?', $username)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,10 +174,10 @@ class DbUserBackend implements UserBackend
|
|||||||
{
|
{
|
||||||
$this->db->getConnection();
|
$this->db->getConnection();
|
||||||
$res = $this->db->select()
|
$res = $this->db->select()
|
||||||
->from($this->userTable, $this->SALT_COLUMN)
|
->from($this->userTable, self::SALT_COLUMN)
|
||||||
->where($this->USER_NAME_COLUMN.' = ?', $username)
|
->where(self::USER_NAME_COLUMN.' = ?', $username)
|
||||||
->query()->fetch();
|
->query()->fetch();
|
||||||
return $res[$this->SALT_COLUMN];
|
return $res[self::SALT_COLUMN];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,8 +197,8 @@ class DbUserBackend implements UserBackend
|
|||||||
$this->db->getConnection();
|
$this->db->getConnection();
|
||||||
$res = $this->db->
|
$res = $this->db->
|
||||||
select()->from($this->userTable)
|
select()->from($this->userTable)
|
||||||
->where($this->USER_NAME_COLUMN.' = ?',$username)
|
->where(self::USER_NAME_COLUMN.' = ?', $username)
|
||||||
->where($this->ACTIVE_COLUMN.' = ?',true)
|
->where(self::ACTIVE_COLUMN.' = ?', true)
|
||||||
->query()->fetch();
|
->query()->fetch();
|
||||||
if (empty($res)) {
|
if (empty($res)) {
|
||||||
return null;
|
return null;
|
||||||
@ -210,12 +220,12 @@ class DbUserBackend implements UserBackend
|
|||||||
private function createUserFromResult(Array $result)
|
private function createUserFromResult(Array $result)
|
||||||
{
|
{
|
||||||
$usr = new User(
|
$usr = new User(
|
||||||
$result[$this->USER_NAME_COLUMN],
|
$result[self::USER_NAME_COLUMN],
|
||||||
$result[$this->FIRST_NAME_COLUMN],
|
$result[self::FIRST_NAME_COLUMN],
|
||||||
$result[$this->LAST_NAME_COLUMN],
|
$result[self::LAST_NAME_COLUMN],
|
||||||
$result[$this->EMAIL_COLUMN]
|
$result[self::EMAIL_COLUMN]
|
||||||
);
|
);
|
||||||
$usr->setDomain($result[$this->DOMAIN_COLUMN]);
|
$usr->setDomain($result[self::DOMAIN_COLUMN]);
|
||||||
return $usr;
|
return $usr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,4 +41,3 @@ interface ConfigAwareFactory
|
|||||||
*/
|
*/
|
||||||
public static function setConfig($config);
|
public static function setConfig($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user