Merge pull request #50 from grvsmth/abg_user_not_found

Friendlier error if user is not found in LDAP
This commit is contained in:
Denis CLAVIER 2020-05-24 16:58:15 +02:00 committed by GitHub
commit 930b007e07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
config_init.sh
config_ldap.php
config_db.php

View File

@ -115,8 +115,10 @@ class LDAP implements LDAPInterface
} }
$data = ldap_first_entry($this->ldap_server, $result); $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.'); if (!$data)
{
throw new Exception('No result from LDAP server', 404);
} }
$dn = ldap_get_dn($this->ldap_server, $data); $dn = ldap_get_dn($this->ldap_server, $data);
if (!$dn) { if (!$dn) {

View File

@ -73,7 +73,17 @@ try {
// Below is the old version, still consistent with Mattermost before version 4.4 // Below is the old version, still consistent with Mattermost before version 4.4
// $resp = array("name" => $data['cn'],"username" => $user,"id" => $assoc_id,"state" => "active","email" => $data['mail']); // $resp = array("name" => $data['cn'],"username" => $user,"id" => $assoc_id,"state" => "active","email" => $data['mail']);
} catch (Exception $e) { } 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 // send data or error message in JSON format