From 2a28f5e66c23b79e8725dac941a0fb93de6341d6 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Tue, 20 Apr 2021 14:53:47 -0700 Subject: [PATCH] (Maybe?) Fixes the problem where we always need LDAP enabled (#9321) * I *think* this fixes the problem where we need LDAP even if we aren't using it? * Pull the LdapAd dependency out of the AuthController constructor --- app/Http/Controllers/Auth/LoginController.php | 10 +++++----- app/Providers/LdapServiceProvider.php | 13 ++++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 001c45e7a1..1dd8f1f150 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -58,12 +58,12 @@ class LoginController extends Controller * * @return void */ - public function __construct(LdapAd $ldap, Saml $saml) + public function __construct(/*LdapAd $ldap, */ Saml $saml) { parent::__construct(); $this->middleware('guest', ['except' => ['logout','postTwoFactorAuth','getTwoFactorAuth','getTwoFactorEnroll']]); Session::put('backUrl', \URL::previous()); - $this->ldap = $ldap; + // $this->ldap = $ldap; $this->saml = $saml; } @@ -140,10 +140,10 @@ class LoginController extends Controller * * @throws \Exception */ - private function loginViaLdap(Request $request): User + private function loginViaLdap(LdapAd $ldap, Request $request): User { try { - return $this->ldap->ldapLogin($request->input('username'), $request->input('password')); + return $ldap->ldapLogin($request->input('username'), $request->input('password')); } catch (\Exception $ex) { LOG::debug("LDAP user login: " . $ex->getMessage()); throw new \Exception($ex->getMessage()); @@ -217,7 +217,7 @@ class LoginController extends Controller $user = null; // Should we even check for LDAP users? - if ($this->ldap->init()) { + if (Setting::getSettings()->ldap_enabled) { // avoid hitting the $this->ldap LOG::debug("LDAP is enabled."); try { LOG::debug("Attempting to log user in by LDAP authentication."); diff --git a/app/Providers/LdapServiceProvider.php b/app/Providers/LdapServiceProvider.php index cc91bac1a5..5b3e71761c 100644 --- a/app/Providers/LdapServiceProvider.php +++ b/app/Providers/LdapServiceProvider.php @@ -2,8 +2,9 @@ use App\Services\LdapAd; use Illuminate\Support\ServiceProvider; +use Illuminate\Contracts\Support\DeferrableProvider; -class LdapServiceProvider extends ServiceProvider +class LdapServiceProvider extends ServiceProvider implements DeferrableProvider { /** @@ -26,4 +27,14 @@ class LdapServiceProvider extends ServiceProvider { $this->app->singleton(LdapAd::class, LdapAd::class); } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [LdapAd::class]; + } }