Skip to content

Commit 719d2a5

Browse files
authored
[LIMS-1636] Make LDAP server ID field configurable (#934)
* Make LDAP searches more configurable * Include ldap_id_field in globals
1 parent 6745ff1 commit 719d2a5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

api/config_sample.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
# CAS CA Cert (for SSO)
4141
$cacert = '/etc/certs/ca-bundle.crt';
4242

43+
# Field to get user ID from in LDAP
44+
$ldap_id_field = "cn";
4345
# ldap server, used for lookup and authentication (if using, set to null if not)
4446
# Update the ldap(s) prefix, hostname and search settings as required
4547
$ldap_server = 'ldaps://ldap.example.com';

api/src/Page.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ function bcr()
758758
*/
759759
function _get_name($fedid)
760760
{
761-
$src = $this->_ldap_search('uid=' . $fedid);
761+
global $ldap_id_field;
762+
763+
$src = $this->_ldap_search($ldap_id_field . '=' . $fedid);
762764
return array_key_exists($fedid, $src) ? $src[$fedid] : '';
763765
}
764766

@@ -770,7 +772,9 @@ function _get_name($fedid)
770772
*/
771773
function _get_email($fedid)
772774
{
773-
$src = $this->_ldap_search('uid=' . $fedid, True);
775+
global $ldap_id_field;
776+
777+
$src = $this->_ldap_search($ldap_id_field . '=' . $fedid, True);
774778
return array_key_exists($fedid, $src) ? $src[$fedid] : $fedid;
775779
}
776780

@@ -853,12 +857,12 @@ function _get_ispyb_email_fn($name)
853857
* Search LDAP for name or email
854858
*
855859
* @param boolean $email Search for an email adddress if true, search for name if false
856-
* @param string $search ldap query, typically uid=fedid or name search
860+
* @param string $search ldap query, typically cn=fedid or name search
857861
* @return array Returns array of results, either fedid=>emailAddresses or fedid=>"givenname sn" from ldap records
858862
*/
859863
function _ldap_search($search, $email = False)
860864
{
861-
global $ldap_server, $ldap_search;
865+
global $ldap_server, $ldap_search, $ldap_id_field;
862866

863867
$ret = array();
864868
if (is_null($ldap_server)) {
@@ -881,7 +885,7 @@ function _ldap_search($search, $email = False)
881885
{
882886
// Strictly speaking we could set anything as the key here, since only the first record is used in e.g. _get_email_fn
883887
// But as the logic maps fedid=>email, use similar keys here
884-
$fedid = $info[$i]['uid'][0];
888+
$fedid = $info[$i][$ldap_id_field][0];
885889
if ($email)
886890
{
887891
$ret[$fedid] = array_key_exists('mail', $info[$i]) ? $info[$i]['mail'][0] : '';

0 commit comments

Comments
 (0)