2
2
3
3
namespace Adldap \Laravel ;
4
4
5
+ use Adldap \AdldapInterface ;
5
6
use InvalidArgumentException ;
6
- use Adldap \Laravel \Facades \Adldap ;
7
7
use Adldap \Laravel \Resolvers \UserResolver ;
8
8
use Adldap \Laravel \Resolvers \ResolverInterface ;
9
9
use Adldap \Laravel \Commands \Console \Import ;
10
10
use Adldap \Laravel \Auth \DatabaseUserProvider ;
11
- use Adldap \Laravel \Auth \NoDatabaseUserProvider ;
12
- use Adldap \Laravel \Listeners \BindsLdapUserModel ;
13
11
use Illuminate \Support \Facades \Auth ;
14
12
use Illuminate \Support \Facades \Event ;
15
13
use Illuminate \Support \Facades \Config ;
@@ -28,7 +26,6 @@ public function boot()
28
26
{
29
27
$ config = __DIR__ .'/Config/auth.php ' ;
30
28
31
- // Add publishable configuration.
32
29
$ this ->publishes ([
33
30
$ config => config_path ('adldap_auth.php ' ),
34
31
], 'adldap ' );
@@ -39,11 +36,11 @@ public function boot()
39
36
40
37
if (method_exists ($ auth , 'provider ' )) {
41
38
$ auth ->provider ('adldap ' , function ($ app , array $ config ) {
42
- return $ this ->newUserProvider ($ app ['hash ' ], $ config );
39
+ return $ this ->makeUserProvider ($ app ['hash ' ], $ config );
43
40
});
44
41
} else {
45
42
$ auth ->extend ('adldap ' , function ($ app ) {
46
- return $ this ->newUserProvider ($ app ['hash ' ], $ app ['config ' ]['auth ' ]);
43
+ return $ this ->makeUserProvider ($ app ['hash ' ], $ app ['config ' ]['auth ' ]);
47
44
});
48
45
}
49
46
@@ -80,7 +77,9 @@ public function provides()
80
77
protected function registerBindings ()
81
78
{
82
79
$ this ->app ->bind (ResolverInterface::class, function () {
83
- return $ this ->newUserResolver ();
80
+ $ ad = $ this ->app ->make (AdldapInterface::class);
81
+
82
+ return new UserResolver ($ ad );
84
83
});
85
84
}
86
85
@@ -91,7 +90,18 @@ protected function registerBindings()
91
90
*/
92
91
protected function registerListeners ()
93
92
{
94
- Event::listen (Authenticated::class, BindsLdapUserModel::class);
93
+ // Here we will register the event listener that will bind the users LDAP
94
+ // model to their Eloquent model upon authentication (if configured).
95
+ // This allows us to utilize their LDAP model right
96
+ // after authentication has passed.
97
+ Event::listen (Authenticated::class, Listeners \BindsLdapUserModel::class);
98
+
99
+ if ($ this ->isLogging ()) {
100
+ Event::listen (Events \Importing::class, Listeners \LogImport::class);
101
+ Event::listen (Events \Synchronized::class, Listeners \LogSynchronized::class);
102
+ Event::listen (Events \Synchronizing::class, Listeners \LogSynchronizing::class);
103
+ Event::listen (Events \DiscoveredWithCredentials::class, Listeners \LogDiscovery::class);
104
+ }
95
105
}
96
106
97
107
/**
@@ -100,69 +110,39 @@ protected function registerListeners()
100
110
* @param Hasher $hasher
101
111
* @param array $config
102
112
*
103
- * @return \Illuminate\Contracts\Auth\UserProvider
104
- *
105
113
* @throws InvalidArgumentException
114
+ *
115
+ * @return \Illuminate\Contracts\Auth\UserProvider
106
116
*/
107
- protected function newUserProvider (Hasher $ hasher , array $ config )
117
+ protected function makeUserProvider (Hasher $ hasher , array $ config )
108
118
{
109
- $ provider = $ this -> userProvider ( );
119
+ $ provider = Config:: get ( ' adldap_auth.provider ' , DatabaseUserProvider::class );
110
120
111
- switch ( $ provider ) {
112
- case DatabaseUserProvider::class:
113
- if ( $ model = array_get ( $ config , ' model ' )) {
114
- return new $ provider ( $ hasher , $ model );
115
- }
121
+ // The DatabaseUserProvider has some extra dependencies needed,
122
+ // so we will validate that we have them before
123
+ // constructing a new instance.
124
+ if ( $ provider == DatabaseUserProvider::class) {
125
+ $ model = array_get ( $ config , ' model ' );
116
126
127
+ if (!$ model ) {
117
128
throw new InvalidArgumentException (
118
129
"No model is configured. You must configure a model to use with the {$ provider }. "
119
130
);
120
- case NoDatabaseUserProvider::class:
121
- return new $ provider ;
122
- }
131
+ }
123
132
124
- throw new InvalidArgumentException (
125
- "The configured Adldap provider [ {$ provider }] is not supported or does not exist. "
126
- );
127
- }
128
-
129
- /**
130
- * Returns a new user resolver.
131
- *
132
- * @return ResolverInterface
133
- */
134
- protected function newUserResolver ()
135
- {
136
- return new UserResolver ($ this ->ldapProvider ());
137
- }
138
-
139
- /**
140
- * Retrieves a connection provider from the Adldap instance.
141
- *
142
- * @return \Adldap\Connections\ProviderInterface
143
- */
144
- protected function ldapProvider ()
145
- {
146
- return Adldap::getProvider ($ this ->connection ());
147
- }
148
-
149
- /**
150
- * Returns the configured user provider class.
151
- *
152
- * @return string
153
- */
154
- protected function userProvider ()
155
- {
156
- return Config::get ('adldap_auth.provider ' , DatabaseUserProvider::class);
133
+ return new $ provider ($ hasher , $ model );
134
+ }
135
+
136
+ return new $ provider ;
157
137
}
158
138
159
139
/**
160
- * Returns the configured default connection name .
140
+ * Determines if authentication requests are logged .
161
141
*
162
- * @return string
142
+ * @return bool
163
143
*/
164
- protected function connection ()
144
+ protected function isLogging ()
165
145
{
166
- return Config::get ('adldap_auth.connection ' , ' default ' );
146
+ return Config::get ('adldap_auth.logging ' , false );
167
147
}
168
148
}
0 commit comments