From baac60b722cd53bb4c5d385d58cd0a0f6c070218 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 17 Jan 2014 17:08:29 -0600
Subject: [PATCH] Fixup user search using directory backends

---
 include/ajax.tickets.php | 2 +-
 include/ajax.users.php   | 6 +++---
 include/class.auth.php   | 6 ++++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php
index 8e53141a8..a7881b75a 100644
--- a/include/ajax.tickets.php
+++ b/include/ajax.tickets.php
@@ -464,7 +464,7 @@ class TicketsAjaxAPI extends AjaxController {
             Http::response(404, 'No such ticket');
         elseif (!$bk || !$id)
             Http::response(422, 'Backend and user id required');
-        elseif (!($backend = AuthenticationBackend::getBackend($bk)))
+        elseif (!($backend = StaffAuthenticationBackend::getBackend($bk)))
             Http::response(404, 'User not found');
 
         $user_info = $backend->lookup($id);
diff --git a/include/ajax.users.php b/include/ajax.users.php
index 7be4874ec..698f2f49d 100644
--- a/include/ajax.users.php
+++ b/include/ajax.users.php
@@ -51,7 +51,7 @@ class UsersAjaxAPI extends AjaxController {
             }
         }
 
-        foreach (AuthenticationBackend::searchUsers($_REQUEST['q']) as $u) {
+        foreach (StaffAuthenticationBackend::searchUsers($_REQUEST['q']) as $u) {
             $name = "{$u['first']} {$u['last']}";
             $users[] = array('email' => $u['email'], 'name'=>$name,
                 'info' => "{$u['email']} - $name (remote)",
@@ -122,7 +122,7 @@ class UsersAjaxAPI extends AjaxController {
             Http::response(403, 'Login Required');
         elseif (!$bk || !$id)
             Http::response(422, 'Backend and user id required');
-        elseif (!($backend = AuthenticationBackend::getBackend($bk)))
+        elseif (!($backend = StaffAuthenticationBackend::getBackend($bk)))
             Http::response(404, 'User not found');
 
         $user_info = $backend->lookup($id);
@@ -177,7 +177,7 @@ class UsersAjaxAPI extends AjaxController {
             Http::response(400, 'Query argument is required');
 
         $users = array();
-        foreach (AuthenticationBackend::allRegistered() as $ab) {
+        foreach (StaffAuthenticationBackend::allRegistered() as $ab) {
             if (!$ab instanceof AuthDirectorySearch)
                 continue;
 
diff --git a/include/class.auth.php b/include/class.auth.php
index 9a226c48e..e3bce85fe 100644
--- a/include/class.auth.php
+++ b/include/class.auth.php
@@ -156,7 +156,7 @@ abstract class AuthenticationBackend {
 
     static function searchUsers($query) {
         $users = array();
-        foreach (static::$registry as $bk) {
+        foreach (static::allRegistered() as $bk) {
             if ($bk instanceof AuthDirectorySearch) {
                 $users += $bk->search($query);
             }
@@ -631,7 +631,9 @@ StaffAuthenticationBackend::register(osTicketAuthentication);
 class PasswordResetTokenBackend extends StaffAuthenticationBackend {
     static $id = "pwreset.staff";
 
-    function authenticate($username, $password) {}
+    function supportsAuthentication() {
+        return false;
+    }
 
     function signOn($errors=array()) {
         if (!isset($_POST['userid']) || !isset($_POST['token']))
-- 
GitLab