Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
Use fallback authenticator if can't find username and email login. (#75)
Browse files Browse the repository at this point in the history
This means a user can still authenticate with their local credentials
by means of fallback authenticator, if LDAP is configured but we can't
find a username in LDAP for the given email address.
  • Loading branch information
Sean Harvey authored and mateusz committed Jul 13, 2016
1 parent 2c9da88 commit 832e0c0
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions code/authenticators/LDAPAuthenticator.php
Expand Up @@ -86,6 +86,13 @@ public static function authenticate($data, Form $form = null)

// No user found with this email.
if (!$username) {
if (Config::inst()->get('LDAPAuthenticator', 'fallback_authenticator') === 'yes') {
$fallbackMember = self::fallback_authenticate($data);
if ($fallbackMember) {
return $fallbackMember;
}
}

$form->sessionMessage(_t('LDAPAuthenticator.INVALIDCREDENTIALS', 'Invalid credentials'), 'bad');
return;
}
Expand All @@ -97,11 +104,7 @@ public static function authenticate($data, Form $form = null)
$success = $result['success'] === true;
if (!$success) {
if (Config::inst()->get('LDAPAuthenticator', 'fallback_authenticator') === 'yes') {
$fallbackMember = call_user_func(
array(Config::inst()->get('LDAPAuthenticator', 'fallback_authenticator_class'), 'authenticate'),
array_merge($data, array('Email' => $data['Login'])),
$form
);
$fallbackMember = self::fallback_authenticate($data);
if ($fallbackMember) {
return $fallbackMember;
}
Expand Down Expand Up @@ -139,4 +142,20 @@ public static function authenticate($data, Form $form = null)

return $member;
}

/**
* Try to authenticate using the fallback authenticator.
*
* @param array $data
* @return null|Member
*/
protected static function fallback_authenticate($data)
{
return call_user_func(
array(Config::inst()->get('LDAPAuthenticator', 'fallback_authenticator_class'), 'authenticate'),
array_merge($data, array('Email' => $data['Login'])),
$form
);
}

}

0 comments on commit 832e0c0

Please sign in to comment.