From a90f564980608f8682d65a8558fb7ed5a0d6f43c Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sun, 26 Feb 2017 14:51:49 +0000 Subject: [PATCH] Made LDAP email attribute configurable via .env Closes #306 --- app/Services/LdapService.php | 5 +++-- config/services.php | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Services/LdapService.php b/app/Services/LdapService.php index f8a4b88bb..71dc9c0e1 100644 --- a/app/Services/LdapService.php +++ b/app/Services/LdapService.php @@ -41,7 +41,8 @@ class LdapService // Find user $userFilter = $this->buildFilter($this->config['user_filter'], ['user' => $userName]); $baseDn = $this->config['base_dn']; - $users = $this->ldap->searchAndGetEntries($ldapConnection, $baseDn, $userFilter, ['cn', 'uid', 'dn', 'mail']); + $emailAttr = $this->config['email_attribute']; + $users = $this->ldap->searchAndGetEntries($ldapConnection, $baseDn, $userFilter, ['cn', 'uid', 'dn', $emailAttr]); if ($users['count'] === 0) return null; $user = $users[0]; @@ -49,7 +50,7 @@ class LdapService 'uid' => (isset($user['uid'])) ? $user['uid'][0] : $user['dn'], 'name' => $user['cn'][0], 'dn' => $user['dn'], - 'email' => (isset($user['mail'])) ? $user['mail'][0] : null + 'email' => (isset($user[$emailAttr])) ? (is_array($user[$emailAttr]) ? $user[$emailAttr][0] : $user[$emailAttr]) : null ]; } diff --git a/config/services.php b/config/services.php index fe58cbb9a..99022e5f2 100644 --- a/config/services.php +++ b/config/services.php @@ -78,7 +78,8 @@ return [ 'pass' => env('LDAP_PASS', false), 'base_dn' => env('LDAP_BASE_DN', false), 'user_filter' => env('LDAP_USER_FILTER', '(&(uid=${user}))'), - 'version' => env('LDAP_VERSION', false) + 'version' => env('LDAP_VERSION', false), + 'email_attribute' => env('LDAP_EMAIL_ATTRIBUTE', 'mail'), ] ];