2014-10-20 13:42:15 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-10-20 13:42:15 +02:00
|
|
|
|
|
|
|
namespace Icinga\Authentication\Backend;
|
|
|
|
|
|
|
|
use Icinga\Application\Config;
|
|
|
|
use Icinga\Authentication\UserGroupBackend;
|
|
|
|
use Icinga\Exception\ConfigurationError;
|
|
|
|
use Icinga\User;
|
|
|
|
use Icinga\Util\String;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* INI user group backend
|
|
|
|
*/
|
|
|
|
class IniUserGroupBackend extends UserGroupBackend
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Config
|
|
|
|
*
|
|
|
|
* @var Config
|
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new INI user group backend
|
|
|
|
*
|
|
|
|
* @param Config $config
|
|
|
|
*/
|
|
|
|
public function __construct(Config $config)
|
|
|
|
{
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* (non-PHPDoc)
|
|
|
|
* @see UserGroupBackend::getMemberships() For the method documentation.
|
|
|
|
*/
|
|
|
|
public function getMemberships(User $user)
|
|
|
|
{
|
|
|
|
$username = strtolower($user->getUsername());
|
|
|
|
$groups = array();
|
|
|
|
foreach ($this->config as $name => $section) {
|
|
|
|
if (empty($section->users)) {
|
|
|
|
throw new ConfigurationError(
|
|
|
|
'Membership section \'%s\' in \'%s\' is missing the \'users\' section',
|
|
|
|
$name,
|
|
|
|
$this->config->getConfigFile()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (empty($section->groups)) {
|
|
|
|
throw new ConfigurationError(
|
|
|
|
'Membership section \'%s\' in \'%s\' is missing the \'groups\' section',
|
|
|
|
$name,
|
|
|
|
$this->config->getConfigFile()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$users = array_map('strtolower', String::trimSplit($section->users));
|
|
|
|
if (in_array($username, $users)) {
|
|
|
|
$groups = array_merge($groups, array_diff(String::trimSplit($section->groups), $groups));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $groups;
|
|
|
|
}
|
|
|
|
}
|