mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 07:14:35 +02:00
lib: Add DbUserGroupBackend
This commit is contained in:
parent
d170cf0c9d
commit
aa56f3010c
63
library/Icinga/Authentication/Backend/DbUserGroupBackend.php
Normal file
63
library/Icinga/Authentication/Backend/DbUserGroupBackend.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Authentication\Backend;
|
||||||
|
|
||||||
|
use Icinga\Authentication\UserGroupBackend;
|
||||||
|
use Icinga\Data\Db\DbConnection;
|
||||||
|
use Icinga\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database user group backend
|
||||||
|
*/
|
||||||
|
class DbUserGroupBackend extends UserGroupBackend
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Connection to the database
|
||||||
|
*
|
||||||
|
* @var DbConnection
|
||||||
|
*/
|
||||||
|
private $conn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new database user group backend
|
||||||
|
*
|
||||||
|
* @param DbConnection $conn
|
||||||
|
*/
|
||||||
|
public function __construct(DbConnection $conn)
|
||||||
|
{
|
||||||
|
$this->conn = $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see UserGroupBackend::getMemberships() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function getMemberships(User $user)
|
||||||
|
{
|
||||||
|
$groups = array();
|
||||||
|
$groupsStmt = $this->conn->getDbAdapter()
|
||||||
|
->select()
|
||||||
|
->from($this->conn->getTablePrefix() . 'group', array('name', 'parent'))
|
||||||
|
->query();
|
||||||
|
foreach ($groupsStmt as $group) {
|
||||||
|
$groups[$group->name] = $group->parent;
|
||||||
|
}
|
||||||
|
$memberships = array();
|
||||||
|
$membershipsStmt = $this->conn->getDbAdapter()
|
||||||
|
->select()
|
||||||
|
->from($this->conn->getTablePrefix() . 'group_membership', array('group_name'))
|
||||||
|
->where('username = ?', $user->getUsername())
|
||||||
|
->query();
|
||||||
|
foreach ($membershipsStmt as $membership) {
|
||||||
|
$memberships[] = $membership->group_name;
|
||||||
|
$parent = $groups[$membership->group_name];
|
||||||
|
while (isset($parent)) {
|
||||||
|
$memberships[] = $parent;
|
||||||
|
$parent = $groups[$parent];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $memberships;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user