From e34253faf847d5fbd40741b58ebee21975aed9da Mon Sep 17 00:00:00 2001 From: "Angus B. Grieve-Smith" Date: Wed, 29 Apr 2020 18:02:50 -0400 Subject: [PATCH] Handle instance where user is not found in LDAP more gracefully --- oauth/LDAP/LDAP.php | 2 +- oauth/resource.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/oauth/LDAP/LDAP.php b/oauth/LDAP/LDAP.php index d9f79b8..42ed2fc 100755 --- a/oauth/LDAP/LDAP.php +++ b/oauth/LDAP/LDAP.php @@ -134,7 +134,7 @@ class LDAP implements LDAPInterface $data = ldap_first_entry($this->ldap_server, $result); if (!$data) { - throw new Exception('An error has occured during ldap_first_entry execution. Please check parameter of LDAP/checkLogin.'); + throw new Exception('No result from LDAP server', 404); } $dn = ldap_get_dn($this->ldap_server, $data); if (!$dn) diff --git a/oauth/resource.php b/oauth/resource.php index b083bb8..bd131d8 100755 --- a/oauth/resource.php +++ b/oauth/resource.php @@ -86,7 +86,17 @@ try } catch (Exception $e) { - $resp = array("error" => "Impossible to get data", "message" => $e->getMessage()); + if ($e->getCode() == 404) { + $resp = [ + "error" => "User not found", + "message" => "$user is not in the group of authorized users." + ]; + } else { + $resp = array( + "error" => "Impossible to get data", + "message" => $e->getMessage() + ); + } } // send data or error message in JSON format