path() !== 'logout') && Session::has('username_encrypt') && Session::has('password_encrypt')) { Config::set('ldap.connections.'.$key.'.username',Crypt::decryptString(Session::get('username_encrypt'))); Config::set('ldap.connections.'.$key.'.password',Crypt::decryptString(Session::get('password_encrypt'))); Log::debug('Swapping out configured LDAP credentials with the user\'s session.',['key'=>$key]); } // We need to override our Connection object so that we can store and retrieve the logged in user and swap out the credentials to use them. $c = Container::getInstance() ->getConnection($key); $c->setConfiguration(config('ldap.connections.'.$key)); $c->setGuardResolver(fn()=>new Guard($c->getLdapConnection(),$c->getConfiguration())); return $next($request); } }