Skip to content

Commit

Permalink
Change way of obtaining groups to use UserDN for search
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPatzke committed Jun 6, 2019
1 parent ea3ca42 commit 0fd8ab5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Security/Provider/LDAPUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ public function loadUserByUsername($username)
$this->ldapClient->bind($this->baseDn,$this->basePw);
$username = $this->ldapClient->escape($username, '', LDAP_ESCAPE_FILTER);
$userQuery = str_replace('{username}', $username, $this->userQuery);
$user = $this->ldapClient->find($this->userDN,$userQuery, '(objectClass=*)');

$user = $this->ldapClient->find($this->userDN,$userQuery, '');
if($user){
// We assume here that our username has to be unique otherwise login would not work in general.
// LDAP search gives us a result set, so our user has to be the first entry and using user[0] should be save.
// According to RFC https://tools.ietf.org/html/rfc4511#page-20 a search result must provide the <DN> attribute
// and resulting from that we can always be save that $user[0]['dn']; will have the correct value!
$ldapGroupSearchQuery = str_replace('{userDN}', $user[0]['dn'], $this->groupQuery);

$groups = $this->defaultRoles;

$ldapGroupSearchQuery = str_replace('{username}', $username, $this->groupQuery);

$ldapGroups = $this->ldapClient->find($this->groupBaseDN,$ldapGroupSearchQuery);

if($ldapGroups) {
Expand Down

0 comments on commit 0fd8ab5

Please sign in to comment.