Skip to content

Commit 5ef0f62

Browse files
committed
Allow the bind failure trait to be more extensible
#80
1 parent 53275dd commit 5ef0f62

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/Auth/ListensForLdapBindFailure.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,35 @@ protected function ldapBindFailed($errorMessage, $diagnosticMessage = null)
3535
{
3636
switch (true) {
3737
case $this->causedByLostConnection($errorMessage):
38-
$this->throwLoginValidationException($errorMessage);
38+
$this->handleLdapBindError($errorMessage);
3939
break;
40-
case $this->causedByInvalidCredentials($errorMessage):
40+
case $this->causedByInvalidCredentials($errorMessage, $diagnosticMessage):
4141
// We'll bypass any invalid LDAP credential errors and let
4242
// the login controller handle it. This is so proper
4343
// translation can be done on the validation error.
4444
break;
4545
default:
4646
foreach ($this->ldapDiagnosticCodeErrorMap() as $code => $message) {
4747
if ($this->errorContainsMessage($diagnosticMessage, (string) $code)) {
48-
$this->throwLoginValidationException($message);
48+
$this->handleLdapBindError($message, $code);
4949
}
5050
}
5151
}
5252
}
5353

54+
/**
55+
* Handle the LDAP bind error.
56+
*
57+
* @param string $message
58+
* @param string $code
59+
*
60+
* @throws ValidationException
61+
*/
62+
protected function handleLdapBindError($message, $code = null)
63+
{
64+
$this->throwLoginValidationException($message);
65+
}
66+
5467
/**
5568
* Throw a login validation exception.
5669
*
@@ -69,12 +82,15 @@ protected function throwLoginValidationException($message)
6982
* Determine if the LDAP error generated is caused by invalid credentials.
7083
*
7184
* @param string $errorMessage
85+
* @param string $diagnosticMessage
7286
*
7387
* @return bool
7488
*/
75-
protected function causedByInvalidCredentials($errorMessage)
89+
protected function causedByInvalidCredentials($errorMessage, $diagnosticMessage)
7690
{
77-
return $this->errorContainsMessage($errorMessage, 'Invalid credentials');
91+
return
92+
$this->errorContainsMessage($errorMessage, 'Invalid credentials') &&
93+
$this->errorContainsMessage($diagnosticMessage, '52e');
7894
}
7995

8096
/**

0 commit comments

Comments
 (0)