Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit ed2694d

Browse files
committed
Bind user LDAP models during the Login event
#581
1 parent c6467e0 commit ed2694d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/AdldapAuthServiceProvider.php

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Support\Facades\Config;
1313
use Illuminate\Support\ServiceProvider;
1414
use Illuminate\Contracts\Hashing\Hasher;
15+
use Illuminate\Auth\Events\Login;
1516
use Illuminate\Auth\Events\Authenticated;
1617

1718
class AdldapAuthServiceProvider extends ServiceProvider
@@ -63,6 +64,7 @@ public function register()
6364
// model to their Eloquent model upon authentication (if configured).
6465
// This allows us to utilize their LDAP model right
6566
// after authentication has passed.
67+
Event::listen(Login::class, Listeners\BindsLdapUserModel::class);
6668
Event::listen(Authenticated::class, Listeners\BindsLdapUserModel::class);
6769

6870
if ($this->isLogging()) {

src/Listeners/BindsLdapUserModel.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@
66
use Adldap\Laravel\Facades\Resolver;
77
use Adldap\Laravel\Traits\HasLdapUser;
88
use Illuminate\Support\Facades\Auth;
9-
use Illuminate\Auth\Events\Authenticated;
109
use Illuminate\Contracts\Auth\Authenticatable;
1110

1211
class BindsLdapUserModel
1312
{
1413
/**
1514
* Binds the LDAP user record to their model.
1615
*
17-
* @param Authenticated $event
16+
* @param mixed $event
1817
*
1918
* @return void
2019
*/
21-
public function handle(Authenticated $event)
20+
public function handle($event)
2221
{
23-
if ($this->isUsingAdldapProvider() && $this->canBind($event->user)) {
22+
// Before we bind the users LDAP model, we will verify they are using the
23+
// Adldap authentication provider, the required trait, and the
24+
// users LDAP property has not already been set.
25+
if (
26+
$this->isUsingAdldapProvider()
27+
&& $this->canBind($event->user)
28+
&& is_null($event->user->ldap)
29+
) {
2430
$event->user->setLdapUser(
2531
Resolver::byModel($event->user)
2632
);

0 commit comments

Comments
 (0)