-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] make LdapBindAuthenticationProvider capable of searching for the DN #21402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ class LdapBindAuthenticationProvider extends UserAuthenticationProvider | |
private $userProvider; | ||
private $ldap; | ||
private $dnString; | ||
private $queryString; | ||
|
||
/** | ||
* Constructor. | ||
|
@@ -53,6 +54,16 @@ public function __construct(UserProviderInterface $userProvider, UserCheckerInte | |
$this->dnString = $dnString; | ||
} | ||
|
||
/** | ||
* Set a query string to use in order to find a DN for the username. | ||
* | ||
* @param string $queryString | ||
*/ | ||
public function setQueryString($queryString) | ||
{ | ||
$this->queryString = $queryString; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -79,7 +90,20 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke | |
|
||
try { | ||
$username = $this->ldap->escape($username, '', LdapInterface::ESCAPE_DN); | ||
$dn = str_replace('{username}', $username, $this->dnString); | ||
|
||
if ($this->queryString) { | ||
$query = str_replace('{username}', $username, $this->queryString); | ||
|
||
$query = $this->ldap->query($this->dnString, $query); | ||
$result = $query->execute(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add newline after this one and merge this line with the previous one (no need to keep the query variable, as it is not used for anything but for running its There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (1 !== $result->count()) { | ||
throw new BadCredentialsException('The presented username is invalid.'); | ||
} | ||
|
||
$dn = $result[0]->getDn(); | ||
} else { | ||
$dn = str_replace('{username}', $username, $this->dnString); | ||
} | ||
|
||
$this->ldap->bind($dn, $password); | ||
} catch (ConnectionException $e) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done