Setup: Also list existing accounts for ActiveDirectory auth backends

fixes #9511
This commit is contained in:
Johannes Meyer 2015-06-25 15:26:56 +02:00
parent 3dddee8b7d
commit 39ea81ac7b
1 changed files with 6 additions and 21 deletions

View File

@ -4,12 +4,9 @@
namespace Icinga\Module\Setup\Forms; namespace Icinga\Module\Setup\Forms;
use Exception; use Exception;
use LogicException; use Icinga\Authentication\User\UserBackend;
use Icinga\Web\Form;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory; use Icinga\Web\Form;
use Icinga\Authentication\User\DbUserBackend;
use Icinga\Authentication\User\LdapUserBackend;
/** /**
* Wizard page to define the initial administrative account * Wizard page to define the initial administrative account
@ -95,7 +92,7 @@ class AdminAccountPage extends Form
} }
} }
if ($this->backendConfig['backend'] === 'db' || $this->backendConfig['backend'] === 'ldap') { if (in_array($this->backendConfig['backend'], array('db', 'ldap', 'msldap'))) {
$users = $this->fetchUsers(); $users = $this->fetchUsers();
if (false === empty($users)) { if (false === empty($users)) {
$choices['existing_user'] = $this->translate('Existing User'); $choices['existing_user'] = $this->translate('Existing User');
@ -260,24 +257,12 @@ class AdminAccountPage extends Form
* Return the names of all users this backend currently provides * Return the names of all users this backend currently provides
* *
* @return array * @return array
*
* @throws LogicException In case the backend to fetch users from is not supported
*/ */
protected function fetchUsers() protected function fetchUsers()
{ {
if ($this->backendConfig['backend'] === 'db') { $config = new ConfigObject($this->backendConfig);
$backend = new DbUserBackend(ResourceFactory::createResource(new ConfigObject($this->resourceConfig))); $config->resource = $this->resourceConfig;
} elseif ($this->backendConfig['backend'] === 'ldap') { $backend = UserBackend::create(null, $config);
$backend = new LdapUserBackend(ResourceFactory::createResource(new ConfigObject($this->resourceConfig)));
$backend->setConfig($this->backendConfig);
} else {
throw new LogicException(
sprintf(
'Tried to fetch users from an unsupported authentication backend: %s',
$this->backendConfig['backend']
)
);
}
try { try {
return $backend->select(array('user_name'))->fetchColumn(); return $backend->select(array('user_name'))->fetchColumn();