A free open source IT asset/license management system
Changed debug level on bad LDAP connection (#9314)
snipe8fd8e716ac83
diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.phpindex f4177ea663..462c685361 100644--- a/app/Http/Controllers/Api/SettingsController.php+++ b/app/Http/Controllers/Api/SettingsController.php@@ -36,13 +36,17 @@ class SettingsController extends Controllerpublic function ldapAdSettingsTest(LdapAd $ldap): JsonResponse{if(!$ldap->init()) {- Log::info('LDAP is not enabled cannot test.');+ Log::info('LDAP is not enabled so we cannot test.');return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400);}// The connect, bind and resulting users message$message = [];++ // This is all kinda fucked right now. The connection test doesn't actually do what you think,+ // // and the way we parse the errors+ // on the JS side is horrible.Log::info('Preparing to test LDAP user login');// Test user can connect to the LDAP servertry {@@ -51,13 +55,11 @@ class SettingsController extends Controller'message' => 'Successfully connected to LDAP server.'];} catch (\Exception $ex) {- \Log::debug('LDAP connected but Bind failed. Please check your LDAP settings and try again.');- return response()->json([- 'message' => 'Error logging into LDAP server, error: ' . $ex->getMessage() . ' - Verify your that your username and password are correct']);+ \Log::debug('Connection to LDAP server '.Setting::getSettings()->ldap_server.' failed. Please check your LDAP settings and try again. Server Responded with error: ' . $ex->getMessage());+ return response()->json(+ ['message' => 'Connection to LDAP server '.Setting::getSettings()->ldap_server." failed. Verify that the LDAP hostname is entered correctly and that it can be reached from this web server. \n\nServer Responded with error: " . $ex->getMessage()- } catch (\Exception $e) {- \Log::info('LDAP connection failed but we cannot debug it any further on our end.');- return response()->json(['message' => 'The LDAP connection failed but we cannot debug it any further on our end. The error from the server is: '.$e->getMessage()], 500);+ ], 400);}Log::info('Preparing to test LDAP bind connection');@@ -66,12 +68,11 @@ class SettingsController extends ControllerLog::info('Testing Bind');$ldap->testLdapAdBindConnection();$message['bind'] = [- 'message' => 'Successfully binded to LDAP server.'+ 'message' => 'Successfully bound to LDAP server.'];} catch (\Exception $ex) {Log::info('LDAP Bind failed');- return response()->json([- 'message' => 'Error binding to LDAP server, error: ' . $ex->getMessage()+ return response()->json(['message' => 'Connection to LDAP successful, but we were unable to Bind the LDAP user '.Setting::getSettings()->ldap_uname.". Verify your that your LDAP Bind username and password are correct. \n\nServer Responded with error: " . $ex->getMessage()], 400);}@@ -94,9 +95,17 @@ class SettingsController extends Controller'email' => $item[$settings['ldap_email']][0] ?? null,];});- $message['user_sync'] = [- 'users' => $users- ];+ if ($users->count() > 0) {+ $message['user_sync'] = [+ 'users' => $users+ ];+ } else {+ $message['user_sync'] = [+ 'message' => 'Connection to LDAP was successful, however there were no users returned from your query. You should confirm the Base Bind DN above.'+ ];+ return response()->json($message, 400);+ }+} catch (\Exception $ex) {Log::info('LDAP sync failed');$message['user_sync'] = [diff --git a/app/Services/LdapAd.php b/app/Services/LdapAd.phpindex 85410ce7d1..01e6f77d59 100644--- a/app/Services/LdapAd.php+++ b/app/Services/LdapAd.php@@ -504,9 +504,9 @@ class LdapAd extends LdapAdConfiguration{try {$this->ldap->connect();- } catch (\Adldap\Auth\BindException $e) {- Log::error($e);- throw new Exception('Unable to connect to LDAP directory!');+ } catch (\Exception $e) {+ Log::debug('LDAP ERROR: '.$e->getMessage());+ throw new Exception($e->getMessage());}}