I just worked on a login application that connects to Active Directory using Zend_Auth and Zend_Auth_Adapter_Ldap. The application uses the Zend Framework and components of Zend_Form.

Server Settings

First of all, the web server has to have the ability to connect with LDAP. To do this, it has to be enabled in the php.ini file. The following line should be uncommented:

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
...
extension=php_ldap.so (if Windows, extension=php_ldap.dll)
...

The httpd.conf file needs to have some LDAP modules loaded as well. If you want the ability to connect to LDAP over a secure connection, you’ll need a few additional modules on top of the standard LDAP module. Plus, at the bottom of the httpd.conf file, or anywhere after the modules have been included, there are a few ifModule statements to add.

#
# Dynamic Shared Object (DSO) Support
#
...
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule ldap_module modules/mod_ldap.so
...
<IfModule ldap_module>
LDAPSharedCacheSize 200000
LDAPCacheEntries 1024
LDAPCacheTTL 600
LDAPOpCacheEntries 1024
LDAPOpCacheTTL 600
</IfModule>
<IfModule mod_authnz_ldap>
LDAPTrustedCA /etc/ssl/certificate/my_public_cert.cer
LDAPTrustedCAType BASE64_FILE
</IfModule>

If the case of the LDAPTrustedCA, I just entered the path to the public certificate of a certificate authority. I’m not completely sure if that has any bearing on the functionality of the LDAP connections over SSL, but included it just in case.

Zend Framework

Once the server is ready to go, you need to setup the Zend Framework to handle LDAP connections to an Active Directory (AD) server. A lot of these steps would probably apply to an OpenLDAP server as well, but I’m focusing on AD right now.
First thing is to setup the configuration file (config.ini). I found that the following settings work well with Active Directory; you’ll have to substitute values based on what your settings are:

[dev]
ldap.server1.host = adserver.mydomain.com
ladp.server1.port = 636
ldap.server1.useStartTls = true
ldap.server1.accountDomainName = adserver.mydomain.com
ldap.server1.accountDomainNameShort = adserver ;abbreviated name for server
ldap.server1.accountCanonicalForm = 3
ldap.server1.baseDn = "dc=adserver,dc=mydomain,dc=com"
ldap.server1.bindRequiresDn = 0

Explanation
Here’s a few, brief explanations of the settings above:

The config.ini file can be used with the Zend_Config_Ini class in the bootstrap file.

//...
require_once('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Registry');
//...
$config = new Zend_Config_Ini(/config/config.ini', 'dev');
Zend_Registry::set('config',$config);
//...

Leave a Reply

Your email address will not be published. Required fields are marked *