Skip to content

Commit

Permalink
Merge pull request #5 from stuvusIT/configurable-filter
Browse files Browse the repository at this point in the history
feat(autoconfig): configurable user filter
  • Loading branch information
SF2311 authored Jan 17, 2024
2 parents 95e92d6 + 1fa3c09 commit dbf4dc5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/autoconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ public function findUsername($request);
class LDAPUsernameResolver implements UsernameResolver {
private $fileName;

function __construct($server, $user_dn, $password, $tree, $attrs) {
function __construct($server, $user_dn, $password, $filter, $tree, $attrs) {
$this->server = $server;
$this->user_dn = $user_dn;
$this->password = $password;
$this->tree = $tree;
$this->attrs = $attrs;
$this->filter = $filter;
}

public function findUsername($request) {
Expand All @@ -131,8 +132,8 @@ public function findUsername($request) {
if ($ldapbind) {
$mail = $request->email;
$mail_escaped = ldap_escape($mail, "", LDAP_ESCAPE_FILTER);
$filter = "(|(mail=" . $mail_escaped . ")(gosaMailAlternateAddress=" . $mail_escaped . "))";
$result = ldap_search($ldapconn, $this->tree, $filter, $this->attrs) or die ("Error in search query: ".ldap_error($ldapconn));
$expanded_filter = str_replace("%m",$mail_escaped, $this->filter);
$result = ldap_search($ldapconn, $this->tree, $expanded_filter, $this->attrs) or die ("Error in search query: ".ldap_error($ldapconn));
$data = ldap_get_entries($ldapconn, $result);
if($data["count"]==1){
$username = $data[0]["uid"][0];
Expand Down

0 comments on commit dbf4dc5

Please sign in to comment.