Skip to content

Commit

Permalink
* Handle entries now properly. Omit the binary objectsid and filter s…
Browse files Browse the repository at this point in the history
…ome elements.

* Breaking change: Change the code which reads the user data!:

            $userData = Yii::$app->ldap->fetchUserData();  // leave as-is!

                $user->email = $userData['mail'];             // instead of $userData['entries']['mail'][0]
                $user->firstname = $userData['givenname'];    // instead of $userData['entries']['givenname'][0]
                $user->lastname = $userData['sn'];            // instead of $userData['entries']['sn'][0]
                $user->phone = $userData['telephonenumber'];  // instead of $userData['entries']['telephonenumber'][0]
  • Loading branch information
Robin committed Aug 28, 2018
1 parent c1e32c2 commit 3d352e3
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/LdapAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ public function fetchUserData($attributes = ['sn', 'objectSid', 'givenName', 'ma

if ($result) {
$entries = ldap_get_entries($this->_l, $result);
if($entries['count'] > 1) {
return false;
}
$sid = self::SIDtoString($entries[0]['objectsid'][0]);
return ['sid' => $sid, 'entries' => $entries[0]];
return array_merge(['sid' => $sid], self::handleEntry($entries[0]));
} else {
return false;
}
Expand All @@ -140,7 +143,7 @@ public function searchUser($searchFor, $attributes = ['sn', 'objectSid', 'givenN
continue;
}
$sid = self::SIDtoString($entry['objectsid'][0]);
array_push($return, ['sid' => $sid, 'entry' => $entry]);
array_push($return, array_merge(['sid' => $sid], self::handleEntry($entry)));
}

return $return;
Expand Down Expand Up @@ -169,4 +172,20 @@ public static function SIDtoString($ADsid)
return $sid;
}

public static function handleEntry($entry) {
$newEntry = [];
foreach ($entry as $attr => $value) {
if(is_int($attr) || $attr == 'objectsid' || !isset($value['count'])) {
continue;
}
$count = $value['count'];
$newVal = "";
for($i=0;$i<$count;$i++) {
$newVal .= $value[$i];
}
$newEntry[$attr] = $newVal;
}
return $newEntry;
}

}

0 comments on commit 3d352e3

Please sign in to comment.