Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit e912da7

Browse files
author
Charles Marion
committed
BUG: Added bind and backup property to the ldap module
1 parent b766d8a commit e912da7

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

modules/ldap/Notification.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,28 @@ private function ldapLogin($params)
3939
$useActiveDirectory = $config['ldap']->ldap->useActiveDirectory;
4040
$proxybasedn = $config['ldap']->ldap->proxyBasedn;
4141
$proxyPassword = $config['ldap']->ldap->proxyPassword;
42+
$backup = $config['ldap']->ldap->backup;
43+
$bindn = $config['ldap']->ldap->bindn;
44+
$bindpw = $config['ldap']->ldap->bindpw;
45+
$proxyPassword = $config['ldap']->ldap->proxyPassword;
4246
$passwordPrefix=Zend_Registry::get('configGlobal')->password->prefix;
4347

44-
$ldapsearch = $searchTerm.'='.$email;
45-
48+
if($searchTerm == 'uid')
49+
{
50+
$ldapsearch = 'uid='.substr($email,0,strpos($email,'@'));
51+
}
52+
else
53+
{
54+
$ldapsearch = $searchTerm.'='.$email;
55+
}
56+
4657
$ldap = ldap_connect($hostname);
4758
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $protocolVersion);
4859
if($useActiveDirectory)
4960
{
5061
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
5162
}
63+
5264

5365
if(isset($ldap) && $ldap != '')
5466
{
@@ -60,13 +72,21 @@ private function ldapLogin($params)
6072
throw new Zend_Exception('Cannot bind proxy');
6173
}
6274
}
75+
76+
$ldapbind = ldap_bind($ldap, $bindn, $bindpw);
77+
if(!$ldapbind)
78+
{
79+
$ldap = ldap_connect($backup);
80+
$ldapbind = ldap_bind($ldap, $bindn, $bindpw);
81+
}
6382

6483
/* search for pid dn */
65-
$result = ldap_search($ldap, $baseDn, $ldapsearch, array('dn','cn'));
84+
$result = ldap_search($ldap, $baseDn, $ldapsearch, array("uid",'cn'));
6685
$someone = false;
6786
if($result != 0)
6887
{
6988
$entries = ldap_get_entries($ldap, $result);
89+
7090
if($entries['count']!=0)
7191
{
7292
$principal = $entries[0]['dn'];
@@ -75,7 +95,7 @@ private function ldapLogin($params)
7595
{
7696
/* bind as this user */
7797
if(@ldap_bind($ldap, $principal, $credential))
78-
{
98+
{
7999
// Try to find the user in the MIDAS database
80100
$someone = $this->User->getByEmail($email);
81101
// If the user doesn't exist we add it, but without email
@@ -89,6 +109,7 @@ private function ldapLogin($params)
89109
}
90110

91111
$names = explode(" ", $givenname);
112+
$firstname = ' ';
92113
if(count($names)>1)
93114
{
94115
$firstname = $names[0];

modules/ldap/configs/module.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ system = true
1010

1111

1212
ldap.hostname = localhost
13+
ldap.backup =
1314
ldap.basedn = "ou=people,dc=myorganization,dc=com"
15+
ldap.bindn = "cn=user,ou=people,dc=myorganization,dc=com"
16+
ldap.bindpw = "set_your_password"
1417
ldap.protocolVersion = 3
1518
ldap.autoAddUnknownUser = true
1619
ldap.search = uid

modules/ldap/controllers/ConfigController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ function indexAction()
3030
$formArray['proxyBasedn']->setValue($applicationConfig['global']['ldap.proxyBasedn']);
3131
$formArray['proxyPassword']->setValue($applicationConfig['global']['ldap.proxyPassword']);
3232
$formArray['autoAddUnknownUser']->setValue($applicationConfig['global']['ldap.autoAddUnknownUser']);
33-
$formArray['useActiveDirectory']->setValue($applicationConfig['global']['ldap.useActiveDirectory']);
33+
$formArray['bindn']->setValue($applicationConfig['global']['ldap.bindn']);
34+
$formArray['bindpw']->setValue($applicationConfig['global']['ldap.bindpw']);
35+
$formArray['backup']->setValue($applicationConfig['global']['ldap.backup']);
3436
$this->view->configForm = $formArray;
3537

3638
if($this->_request->isPost())
@@ -55,6 +57,9 @@ function indexAction()
5557
$applicationConfig['global']['ldap.proxyBasedn'] = $this->_getParam('proxyBasedn');
5658
$applicationConfig['global']['ldap.autoAddUnknownUser'] = $this->_getParam('autoAddUnknownUser');
5759
$applicationConfig['global']['ldap.useActiveDirectory'] = $this->_getParam('useActiveDirectory');
60+
$applicationConfig['global']['ldap.bindn'] = '"'.$this->_getParam('bindn').'"';
61+
$applicationConfig['global']['ldap.bindpw'] = $this->_getParam('bindpw');
62+
$applicationConfig['global']['ldap.backup'] = $this->_getParam('backup');
5863
$this->Component->Utility->createInitFile(BASE_PATH."/core/configs/ldap.local.ini", $applicationConfig);
5964
echo JsonComponent::encode(array(true, 'Changed saved'));
6065
}

modules/ldap/controllers/forms/ConfigForm.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public function createConfigForm()
2323
$search ->setRequired(true)
2424
->addValidator('NotEmpty', true);
2525
$proxyBasedn = new Zend_Form_Element_Text('proxyBasedn');
26+
$backup = new Zend_Form_Element_Text('backup');
27+
$bindn = new Zend_Form_Element_Text('bindn');
28+
$bindpw = new Zend_Form_Element_Password('bindpw');
2629
$proxyPassword = new Zend_Form_Element_Password('proxyPassword');
2730

2831
$autoAddUnknownUser = new Zend_Form_Element_Select('autoAddUnknownUser');
@@ -36,12 +39,10 @@ public function createConfigForm()
3639
'false' => 'false'
3740
));
3841

39-
40-
4142
$submit = new Zend_Form_Element_Submit('submitConfig');
4243
$submit ->setLabel('Save configuration');
4344

44-
$form->addElements(array($proxyPassword,$hostname,$basedn,$protocolVersion,$search,$proxyBasedn,$autoAddUnknownUser,$useActiveDirectory,$submit));
45+
$form->addElements(array($backup,$bindpw,$bindn,$proxyPassword,$hostname,$basedn,$protocolVersion,$search,$proxyBasedn,$autoAddUnknownUser,$useActiveDirectory,$submit));
4546
return $form;
4647
}
4748
} // end class

modules/ldap/views/config/index.phtml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ $this->headScript()->appendFile($this->moduleWebroot . '/public/js/config/config
1616
<label for='hostname'>Ldap Hostname</label>
1717
{$this->configForm['hostname']}
1818
</div>
19+
<div >
20+
<label for='hostname'>Backup Server</label>
21+
{$this->configForm['backup']}
22+
</div>
23+
<div >
24+
<label for='hostname'>Bind Dn</label>
25+
{$this->configForm['bindn']}
26+
</div>
27+
<div >
28+
<label for='hostname'>Bind Password</label>
29+
{$this->configForm['bindpw']}
30+
</div>
1931
<div >
2032
<label for='basedn'>Base Dn</label>
2133
{$this->configForm['basedn']}

0 commit comments

Comments
 (0)