9
9
use Adldap \Laravel \Events \Authenticated ;
10
10
use Adldap \Laravel \Events \Authenticating ;
11
11
use Adldap \Laravel \Events \AuthenticationFailed ;
12
- use Adldap \Laravel \Auth \DatabaseUserProvider ;
13
12
use Adldap \Laravel \Auth \NoDatabaseUserProvider ;
13
+ use Illuminate \Support \Facades \Auth ;
14
14
use Illuminate \Support \Facades \Event ;
15
15
use Illuminate \Support \Facades \Config ;
16
+ use Illuminate \Contracts \Auth \UserProvider ;
16
17
use Illuminate \Contracts \Auth \Authenticatable ;
17
18
18
19
class UserResolver implements ResolverInterface
@@ -25,7 +26,7 @@ class UserResolver implements ResolverInterface
25
26
protected $ ldap ;
26
27
27
28
/**
28
- * The LDAP connection to utilize.
29
+ * The name of the LDAP connection to utilize.
29
30
*
30
31
* @var string
31
32
*/
@@ -38,7 +39,7 @@ public function __construct(AdldapInterface $ldap)
38
39
{
39
40
$ this ->ldap = $ ldap ;
40
41
41
- $ this ->setConnection ($ this ->getAuthConnection ());
42
+ $ this ->setConnection ($ this ->getLdapAuthConnectionName ());
42
43
}
43
44
44
45
/**
@@ -66,12 +67,10 @@ public function byCredentials(array $credentials = [])
66
67
return ;
67
68
}
68
69
69
- $ provider = Config::get ('adldap_auth.provider ' , DatabaseUserProvider::class);
70
-
71
70
// Depending on the configured user provider, the
72
71
// username field will differ for retrieving
73
72
// users by their credentials.
74
- if ($ provider == NoDatabaseUserProvider::class ) {
73
+ if ($ this -> getAppAuthProvider () instanceof NoDatabaseUserProvider) {
75
74
$ username = $ credentials [$ this ->getLdapDiscoveryAttribute ()];
76
75
} else {
77
76
$ username = $ credentials [$ this ->getEloquentUsernameAttribute ()];
@@ -114,7 +113,7 @@ public function authenticate(User $user, array $credentials = [])
114
113
115
114
Event::fire (new Authenticating ($ user , $ username ));
116
115
117
- if ($ this ->getProvider ()->auth ()->attempt ($ username , $ password )) {
116
+ if ($ this ->getLdapAuthProvider ()->auth ()->attempt ($ username , $ password )) {
118
117
Event::fire (new Authenticated ($ user ));
119
118
120
119
return true ;
@@ -130,7 +129,7 @@ public function authenticate(User $user, array $credentials = [])
130
129
*/
131
130
public function query () : Builder
132
131
{
133
- $ query = $ this ->getProvider ()->search ()->users ();
132
+ $ query = $ this ->getLdapAuthProvider ()->search ()->users ();
134
133
135
134
$ scopes = Config::get ('adldap_auth.scopes ' , []);
136
135
@@ -192,19 +191,29 @@ protected function getPasswordFromCredentials($credentials)
192
191
*
193
192
* @throws \Adldap\AdldapException
194
193
*
195
- * @return \Adldap\Connections\ ProviderInterface
194
+ * @return ProviderInterface
196
195
*/
197
- protected function getProvider () : ProviderInterface
196
+ protected function getLdapAuthProvider () : ProviderInterface
198
197
{
199
198
return $ this ->ldap ->getProvider ($ this ->connection );
200
199
}
201
200
201
+ /**
202
+ * Returns the default guards provider instance.
203
+ *
204
+ * @return UserProvider
205
+ */
206
+ protected function getAppAuthProvider () : UserProvider
207
+ {
208
+ return Auth::guard ()->getProvider ();
209
+ }
210
+
202
211
/**
203
212
* Returns the connection name of the authentication provider.
204
213
*
205
214
* @return string
206
215
*/
207
- protected function getAuthConnection ()
216
+ protected function getLdapAuthConnectionName ()
208
217
{
209
218
return Config::get ('adldap_auth.connection ' , 'default ' );
210
219
}
0 commit comments