3
3
namespace Adldap \Laravel \Resolvers ;
4
4
5
5
use Adldap \Models \User ;
6
- use Adldap \Connections \ ProviderInterface ;
6
+ use Adldap \AdldapInterface ;
7
7
use Illuminate \Support \Facades \Config ;
8
8
use Illuminate \Contracts \Auth \Authenticatable ;
9
9
10
10
class UserResolver implements ResolverInterface
11
11
{
12
12
/**
13
- * The LDAP connection provider .
13
+ * The underlying Adldap instance .
14
14
*
15
- * @var ProviderInterface
15
+ * @var AdldapInterface
16
16
*/
17
- protected $ provider ;
17
+ protected $ ldap ;
18
+
19
+ /**
20
+ * The LDAP connection to utilize.
21
+ *
22
+ * @var string
23
+ */
24
+ protected $ connection = 'default ' ;
18
25
19
26
/**
20
27
* {@inheritdoc}
21
28
*/
22
- public function __construct (ProviderInterface $ provider )
29
+ public function __construct (AdldapInterface $ ldap )
23
30
{
24
- $ this ->provider = $ provider ;
31
+ $ this ->ldap = $ ldap ;
32
+ }
33
+
34
+ /**
35
+ * Sets the LDAP connection to use.
36
+ *
37
+ * @param string $connection
38
+ *
39
+ * @return void
40
+ */
41
+ public function setConnection ($ connection )
42
+ {
43
+ $ this ->connection = $ connection ;
25
44
}
26
45
27
46
/**
@@ -42,7 +61,7 @@ public function byCredentials(array $credentials = [])
42
61
}
43
62
44
63
return $ this ->query ()
45
- ->whereEquals ($ this ->getLdapUsername (), $ credentials [$ this ->getEloquentUsername ()])
64
+ ->whereEquals ($ this ->getLdapDiscoveryAttribute (), $ credentials [$ this ->getEloquentUsernameAttribute ()])
46
65
->first ();
47
66
}
48
67
@@ -52,7 +71,7 @@ public function byCredentials(array $credentials = [])
52
71
public function byModel (Authenticatable $ model )
53
72
{
54
73
return $ this ->query ()
55
- ->whereEquals ($ this ->getLdapUsername (), $ model ->{$ this ->getEloquentUsername ()})
74
+ ->whereEquals ($ this ->getLdapDiscoveryAttribute (), $ model ->{$ this ->getEloquentUsernameAttribute ()})
56
75
->first ();
57
76
}
58
77
@@ -61,17 +80,17 @@ public function byModel(Authenticatable $model)
61
80
*/
62
81
public function authenticate (User $ user , array $ credentials = [])
63
82
{
64
- $ username = $ user ->getFirstAttribute ($ this ->getLdapAuthUsername ());
83
+ $ username = $ user ->getFirstAttribute ($ this ->getLdapAuthAttribute ());
65
84
66
- return $ this ->provider ->auth ()->attempt ($ username , $ credentials ['password ' ]);
85
+ return $ this ->getProvider () ->auth ()->attempt ($ username , $ credentials ['password ' ]);
67
86
}
68
87
69
88
/**
70
89
* {@inheritdoc}
71
90
*/
72
91
public function query ()
73
92
{
74
- $ query = $ this ->provider ->search ()->users ();
93
+ $ query = $ this ->getProvider () ->search ()->users ();
75
94
76
95
foreach ($ this ->getScopes () as $ scope ) {
77
96
// Create the scope.
@@ -84,26 +103,36 @@ public function query()
84
103
return $ query ;
85
104
}
86
105
106
+ /**
107
+ * Returns the configured connection provider.
108
+ *
109
+ * @return \Adldap\Connections\ProviderInterface
110
+ */
111
+ protected function getProvider ()
112
+ {
113
+ return $ this ->ldap ->getProvider ($ this ->connection );
114
+ }
115
+
87
116
/**
88
117
* {@inheritdoc}
89
118
*/
90
- public function getLdapUsername ()
119
+ public function getLdapDiscoveryAttribute ()
91
120
{
92
121
return Config::get ('adldap_auth.usernames.ldap.discover ' , 'userprincipalname ' );
93
122
}
94
123
95
124
/**
96
125
* {@inheritdoc}
97
126
*/
98
- public function getLdapAuthUsername ()
127
+ public function getLdapAuthAttribute ()
99
128
{
100
129
return Config::get ('adldap_auth.usernames.ldap.authenticate ' , 'userprincipalname ' );
101
130
}
102
131
103
132
/**
104
133
* {@inheritdoc}
105
134
*/
106
- public function getEloquentUsername ()
135
+ public function getEloquentUsernameAttribute ()
107
136
{
108
137
return Config::get ('adldap_auth.usernames.eloquent ' , 'email ' );
109
138
}
0 commit comments