LdapUserGroupBackend: Allow to link a user backend

refs #7343
This commit is contained in:
Johannes Meyer 2015-06-05 10:41:47 +02:00
parent 127489ca20
commit 0ab192cd1f

View File

@ -3,7 +3,10 @@
namespace Icinga\Authentication\UserGroup; namespace Icinga\Authentication\UserGroup;
use Icinga\Authentication\User\UserBackend;
use Icinga\Authentication\User\LdapUserBackend;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Protocol\Ldap\Expression; use Icinga\Protocol\Ldap\Expression;
use Icinga\Repository\LdapRepository; use Icinga\Repository\LdapRepository;
@ -540,6 +543,8 @@ class LdapUserGroupBackend /*extends LdapRepository*/ implements UserGroupBacken
* @param ConfigObject $config * @param ConfigObject $config
* *
* @return $this * @return $this
*
* @throws ConfigurationError In case a linked user backend does not exist or is not a LdapUserBackend
*/ */
public function setConfig(ConfigObject $config) public function setConfig(ConfigObject $config)
{ {
@ -551,6 +556,20 @@ class LdapUserGroupBackend /*extends LdapRepository*/ implements UserGroupBacken
$defaults = new ConfigObject(); $defaults = new ConfigObject();
} }
if ($config->user_backend) {
$userBackend = UserBackend::create($config->user_backend);
if (! $userBackend instanceof LdapUserBackend) {
throw new ConfigurationError('User backend "%s" is not of type LDAP', $config->user_backend);
}
$defaults->merge(array(
'user_base_dn' => $userBackend->getBaseDn(),
'user_class' => $userBackend->getUserClass(),
'user_name_attribute' => $userBackend->getUserNameAttribute(),
'user_filter' => $userBackend->getFilter()
));
}
return $this return $this
->setGroupBaseDn($config->base_dn) ->setGroupBaseDn($config->base_dn)
->setUserBaseDn($config->get('user_base_dn', $this->getGroupBaseDn())) ->setUserBaseDn($config->get('user_base_dn', $this->getGroupBaseDn()))