Posts Tagged active directory
Using mod_ldap With Apache
Posted by clifgriffin in Technology on December 8th, 2008
I did a small test of mod_ldap today. It wasn’t terribly difficult, but most guides online seemed to overly complicate the matter.
In my test, I chose a directory located off of my website root that I wanted to restrict to only users with an LDAP account. (That’s any user…regardless of OU, Group, or hair color.)In this example, I’ll use http://server/ldaptest as my protected location and some.domain.com as my domain.
- First, I setup a dummy index page in
/var/www/html/ldaptest. (This location will vary obviously depending on your Apache installation) - Next, I opened my
httpd.conffile (mine was in /etc/httpd/conf/httpd.conf) and made sure these two lines were present:
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.soThis indicates that mod_ldap and mod_authnz_ldap (both necessary) are installed.
- Next, I added the following lines to
httpd.conf:
<Directory "/var/www/html/ldaptest">
Order deny,allow
Deny from All
AuthName "Company.com Intranet"
AuthType Basic
AuthBasicProvider ldap
AuthzLDAPAuthoritative off
AuthLDAPUrl ldap://dc1.some.domain.com/dc=some,dc=domain,dc=com?uid
Require valid-user
Satisfy any
AuthLDAPBindDN "CN=PortalReader,OU=Service Accounts,OU=IS,OU=FSA,DC=some,DC=domain,DC=com"
AuthLDAPBindPassword somePa$$W0rd
</Directory> - I then restarted apache by issuing the command:
service httpd restart
Terms explained (as best I can):
/var/www/html/ldaptestis the directory location on the local server you want to set settings for.Order deny,allowspecifies the order permissions are applied in. (This is typical.)Deny from Allprohibits all non-authenticated users from proceeding.AuthName "Company.com Intranet"simply provides a name for your service that the browser will show in its authentication prompt.AuthTypeBasic specifies the type of authentication to be used for the directory.AuthBasicProvider ldapspecifies who is going to handle the basic authentication.AuthzLDAPAuthoritative offis required when using valid-user (see below)AuthLDAPUrlis the location we are searching. This includes your domain controller and your domain.Require valid-usertells mod_ldap to accept all valid domain users regardless of location.AuthLDAPBindDN "CN=PortalReader,OU=Service Accounts..."tells mod_ldap the fully qualified location of the account to use to bind to your domain. This account needs read priviliges on your domain.AuthLDAPBindPasswordis simply the password for your bind account.
That was all there was to it. I did have a couple of issues though:
- I didn’t get the DN (Distinguished Name) for the
AuthLDAPBindDNright the first time. In order to get the correct DN, I usedADSIEditto find the actual object and copy the DN directly, putting it in quotes. (If you fail to use quotes, Apache will not start on the basis that you cannot have more than one value for that setting.) - In order to determine that I was having the above problem, I had to set logging to the debug level. You do this by finding
LogLevelinhttpd.confand setting it todebug. Previously, I had warn set. - Lastly, I didn’t watch the right log for errors at first. I defaulted to trying error_log, but in my particular case I was using SSL so the correct log was ssl_error_log.
This code allows ANY valid user in the specified domain to login. In order to use groups and things of that nature, I recommend you look at this guide.
Simple LDAP Login 1.2 WordPress Plugin
Posted by clifgriffin in Technology on October 28th, 2008
This page contains information about an older version of Simple LDAP Login. While this version is stable and I encourage you to use it if you would like to, please note that the current version is being discussed and supported here.
If you have used this plugin (successfully or unsuccessfully), please leave me some feedback below. Doing so will help me help others who may be experiencing problems I am not aware of! Alternatively, you can e-mail me at webmaster[at]clifgriffin.com.
Official WordPress Link
Having a single login for every service is a must in large organizations. This plugin is a very simple. It authenticates your wordpress username against LDAP using the same username. It does this by redefining the wp_authenticate function and adding a simple hook to adLDAP. The logic goes like this:
- If wordpress login fails, try adLDAP.
- If adLDAP succeeds, login.
- Else, fail.
Your WordPress usernames MUST be the same as your LDAP usernames for this to work!
Background
In times past, our organization used a custom hack of wp-login.php that allowed us to implement adLDAP. This was not an upgrade proof solution. In the recent round of upgrades, I tried several purported LDAP plugins. Some of them didn’t work at all. Some of them worked but didn’t provide the exact functionality I desired.
Version History
Version 1.2.0.1
- Fixed security issue. Now only administrators can access admin pages.
Version 1.2
- Implemented multiple domain controllers.
- Changed field sizes on admin page to be more user friendly.
Version 1.1
- Moved settings to administration pages under settings.
- Upgraded to latest version of adLDAP 2.1.
- Got rid of credentials. (They are not neccessary for the authenticate function in adLDAP!)
- Plugin is now upgrade proof. Settings are stored using WordPress’s setting functions.
Version 1.0
- Original release.
Installation (new instructions 1.1+)
- Upload the directory “simple-ldap-login” to the `/wp-content/plugins/` directory
- Activate the plugin through the ‘Plugins’ menu in WordPress
- Immediately update the settings to those that best match your environment by going to Settings -> Simple LDAP Login
- If you don’t get the settings right the first time…don’t fret! Just use your wordpress credentials…they will always work!

Change the settings under Settings -> Simple LDAP Login
Installation (old instructions)
- Upload the directory “simple-ldap-login” to the `/wp-content/plugins/` directory
- Customize settings by modifying adLDAP.php in /plugins/simple-ldap-login/
- Activate the plugin through the ‘Plugins’ menu in WordPress
Note: You may wish to create a backup of adLDAP.php once you’re done. Automatic plugin updates might overwrite this file and make upgrades more difficult.
Frequently Asked Questions
Will you be moving the settings to the admin panel?Version 1.1 accomplished this.
At some point. These settings are not frequently changed however and a competent system administrator should not have any issues with configuration.I noticed you’re using adLDAP 1.4. Why?Version 1.1 upgraded adLDAP to 2.1
This is the version my organization was using previously and it was very easy to simply copy over. It should work fine. If there are issues with this version that affect you, let me know and I’ll investigate.- It’s not working, what am I doing wrong?
- Make sure PHP is compiled with LDAP. If it is, running phpinfo should reveal a section entitled LDAP and it should indicate that it is enabled.
- Make absolutely sure your setttings are right and that your server can talk to your domain controller.
- Make sure your wordpress user accounts are the same as the LDAP user accounts you wish to use. This plugin does not bypass wordpress user accounts…just wordpress user account passwords! - It’s still not working? How can I get help?
There are two ways. You can post a comment below or you can e-mail me: webmaster[at]clifgriffin.com. I will respond as soon as I can. - Can feature x be added
Probably! E-mail me: webmaster[at]clifgriffin.com
Download it now…
Simple LDAP Login 1.2.0.1 for WordPress 2.7.1
Recent Comments