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

Commit d3a29ed

Browse files
committed
Return false on LDAP authentication failure
1 parent f4e5cff commit d3a29ed

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/Auth/DatabaseUserProvider.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,33 @@ public function retrieveByCredentials(array $credentials)
121121
*/
122122
public function validateCredentials(Authenticatable $model, array $credentials)
123123
{
124-
// We'll check if we have an LDAP user, and then make sure
125-
// they pass authentication before going further.
126-
if (
127-
$this->user instanceof User &&
128-
Resolver::authenticate($this->user, $credentials)
129-
) {
130-
Event::fire(new AuthenticatedWithCredentials($this->user, $model));
131-
132-
// Here we will perform authorization on the LDAP user. If all
133-
// validation rules pass, we will allow the authentication
134-
// attempt. Otherwise, it is automatically rejected.
135-
if ($this->passesValidation($this->user, $model)) {
136-
// Here we can now synchronize / set the users password since
137-
// they have successfully passed authentication
138-
// and our validation rules.
139-
Bus::dispatch(new SyncPassword($model, $credentials));
140-
141-
$model->save();
142-
143-
Event::fire(new AuthenticationSuccessful($this->user));
144-
145-
return true;
124+
if ($this->user instanceof User) {
125+
// If an LDAP user was discovered, we can go
126+
// ahead and try to authenticate them.
127+
if (Resolver::authenticate($this->user, $credentials)) {
128+
Event::fire(new AuthenticatedWithCredentials($this->user, $model));
129+
130+
// Here we will perform authorization on the LDAP user. If all
131+
// validation rules pass, we will allow the authentication
132+
// attempt. Otherwise, it is automatically rejected.
133+
if ($this->passesValidation($this->user, $model)) {
134+
// Here we can now synchronize / set the users password since
135+
// they have successfully passed authentication
136+
// and our validation rules.
137+
Bus::dispatch(new SyncPassword($model, $credentials));
138+
139+
$model->save();
140+
141+
Event::fire(new AuthenticationSuccessful($this->user));
142+
143+
return true;
144+
}
145+
146+
Event::fire(new AuthenticationRejected($this->user));
146147
}
147148

148-
Event::fire(new AuthenticationRejected($this->user));
149+
// LDAP Authentication failed.
150+
return false;
149151
}
150152

151153
if ($this->isFallingBack() && $model->exists) {

0 commit comments

Comments
 (0)