From f1a6926ad9ee09889da85f51b4f458df446c47d6 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 16 Oct 2017 06:34:04 -0700 Subject: [PATCH] LDAP test login --- .../Controllers/Api/SettingsController.php | 31 ++++++++ resources/views/settings/ldap.blade.php | 73 +++++++++++++++++-- routes/api.php | 5 ++ 3 files changed, 103 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php index baefb1eb97..81d9d32320 100644 --- a/app/Http/Controllers/Api/SettingsController.php +++ b/app/Http/Controllers/Api/SettingsController.php @@ -99,4 +99,35 @@ class SettingsController extends Controller } + public function ldaptestlogin(Request $request) + { + + \Log::debug('Preparing to test LDAP login'); + + try { + $connection = Ldap::connectToLdap(); + try { + \Log::debug('attempting to bind to LDAP for LDAP test'); + Ldap::bindAdminToLdap($connection); + try { + $ldap_user = Ldap::findAndBindUserLdap($request->input('ldaptest_user'), $request->input('ldaptest_password')); + return response()->json(['message' => 'It worked! '. $request->input('username').' successfully binded to LDAP.'], 200); + } catch (\Exception $e) { + \Log::debug('LDAP login failed'); + return response()->json(['message' => $e->getMessage()], 400); + } + + } catch (\Exception $e) { + \Log::debug('Bind failed'); + return response()->json(['message' => $e->getMessage()], 400); + //return response()->json(['message' => $e->getMessage()], 500); + } + } catch (\Exception $e) { + \Log::debug('Connection failed'); + return response()->json(['message' => $e->getMessage()], 600); + } + + + } + } diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php index d114fcfbe4..4ed8661d21 100644 --- a/resources/views/settings/ldap.blade.php +++ b/resources/views/settings/ldap.blade.php @@ -328,24 +328,52 @@ + @if ($setting->ldap_enabled)
- Test LDAP Connection + Test LDAP Sync
-
- -
+
+

This only tests that LDAP can sync correctly. If your LDAP Authentication query is not correct, users may still not be able to login.

+
+
+ +
+
+ Test LDAP Login +
+
+
+
+ +
+
+ +
+
+ Test LDAP +
+ + + +
+
+
+

Enter a valid LDAP username and password to test whether your LDAP login is configured correctly.

+
+ +
+ @endif -