(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
This commit is contained in:
Brady Wetherington 2021-04-20 14:53:47 -07:00 committed by GitHub
parent cacb707a7f
commit 2a28f5e66c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View file

@ -58,12 +58,12 @@ class LoginController extends Controller
* *
* @return void * @return void
*/ */
public function __construct(LdapAd $ldap, Saml $saml) public function __construct(/*LdapAd $ldap, */ Saml $saml)
{ {
parent::__construct(); parent::__construct();
$this->middleware('guest', ['except' => ['logout','postTwoFactorAuth','getTwoFactorAuth','getTwoFactorEnroll']]); $this->middleware('guest', ['except' => ['logout','postTwoFactorAuth','getTwoFactorAuth','getTwoFactorEnroll']]);
Session::put('backUrl', \URL::previous()); Session::put('backUrl', \URL::previous());
$this->ldap = $ldap; // $this->ldap = $ldap;
$this->saml = $saml; $this->saml = $saml;
} }
@ -140,10 +140,10 @@ class LoginController extends Controller
* *
* @throws \Exception * @throws \Exception
*/ */
private function loginViaLdap(Request $request): User private function loginViaLdap(LdapAd $ldap, Request $request): User
{ {
try { try {
return $this->ldap->ldapLogin($request->input('username'), $request->input('password')); return $ldap->ldapLogin($request->input('username'), $request->input('password'));
} catch (\Exception $ex) { } catch (\Exception $ex) {
LOG::debug("LDAP user login: " . $ex->getMessage()); LOG::debug("LDAP user login: " . $ex->getMessage());
throw new \Exception($ex->getMessage()); throw new \Exception($ex->getMessage());
@ -217,7 +217,7 @@ class LoginController extends Controller
$user = null; $user = null;
// Should we even check for LDAP users? // 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."); LOG::debug("LDAP is enabled.");
try { try {
LOG::debug("Attempting to log user in by LDAP authentication."); LOG::debug("Attempting to log user in by LDAP authentication.");

View file

@ -2,8 +2,9 @@
use App\Services\LdapAd; use App\Services\LdapAd;
use Illuminate\Support\ServiceProvider; 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); $this->app->singleton(LdapAd::class, LdapAd::class);
} }
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [LdapAd::class];
}
} }