From 8fcf21a6b80f353d6f033c7a6123aa22fa94b166 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 29 Sep 2014 11:21:40 +0200 Subject: [PATCH] Make it possible to retrieve a list of available users for authentication refs #7163 --- .../Authentication/Backend/DbUserBackend.php | 17 +++++++++++++++++ .../Authentication/Backend/LdapUserBackend.php | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/library/Icinga/Authentication/Backend/DbUserBackend.php b/library/Icinga/Authentication/Backend/DbUserBackend.php index a89a07c81..239ceb258 100644 --- a/library/Icinga/Authentication/Backend/DbUserBackend.php +++ b/library/Icinga/Authentication/Backend/DbUserBackend.php @@ -126,4 +126,21 @@ class DbUserBackend extends UserBackend return ($row !== false) ? $row->count : 0; } + + /** + * Return the names of all available users + * + * @return array + */ + public function listUsers() + { + $query = $this->conn->select()->from('account', array('username')); + + $users = array(); + foreach ($query->fetchAll() as $row) { + $users[] = $row->username; + } + + return $users; + } } diff --git a/library/Icinga/Authentication/Backend/LdapUserBackend.php b/library/Icinga/Authentication/Backend/LdapUserBackend.php index 23a79781d..8e5307fc8 100644 --- a/library/Icinga/Authentication/Backend/LdapUserBackend.php +++ b/library/Icinga/Authentication/Backend/LdapUserBackend.php @@ -159,5 +159,22 @@ class LdapUserBackend extends UserBackend ) ); } + + /** + * Return the names of all available users + * + * @return array + */ + public function listUsers() + { + $query = $this->conn->select()->from($this->userClass, array($this->userNameAttribute)); + + $users = array(); + foreach ($query->fetchAll() as $row) { + $users[] = $row->{$this->userNameAttribute}; + } + + return $users; + } }