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

Commit d9b7e7a

Browse files
committed
2 parents d410a14 + d53f7e2 commit d9b7e7a

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<p align="center">
44
<a href="www.laravel.com"><img src="https://img.shields.io/badge/Built_for-Laravel-green.svg?style=flat-square"></a>
55
<a href="https://travis-ci.org/Adldap2/Adldap2-Laravel"><img src="https://img.shields.io/travis/Adldap2/Adldap2-Laravel.svg?style=flat-square"></a>
6-
<a href="https://travis-ci.org/Adldap2/Adldap2-Laravel"><img src="https://img.shields.io/travis/Adldap2/Adldap2-Laravel.svg?style=flat-square"></a>
76
<a href="https://scrutinizer-ci.com/g/Adldap2/Adldap2-Laravel"><img src="https://img.shields.io/scrutinizer/g/Adldap2/Adldap2-laravel/master.svg?style=flat-square"></a>
87
<a href="https://packagist.org/packages/adldap2/adldap2-laravel"><img src="https://img.shields.io/packagist/dt/adldap2/adldap2-laravel.svg?style=flat-square"></a>
98
<a href="https://packagist.org/packages/adldap2/adldap2-laravel"><img src="https://img.shields.io/packagist/v/adldap2/adldap2-laravel.svg?style=flat-square"></a>

src/AdldapAuthServiceProvider.php

Lines changed: 2 additions & 0 deletions
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

Lines changed: 10 additions & 4 deletions
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
);

tests/DatabaseProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function auth_attempts_fallback_using_config_option()
133133
];
134134

135135
Resolver::shouldReceive('byCredentials')->times(3)->andReturn(null)
136-
->shouldReceive('byModel')->once()->andReturn(null);
136+
->shouldReceive('byModel')->times(2)->andReturn(null);
137137

138138
$this->assertTrue(Auth::attempt($credentials));
139139

0 commit comments

Comments
 (0)