Authenticating With Active Directory

How to make Plone authenticate against Active Directory Using PlonePAS

Get the Files

You will need:

  • In plone3, if you have a simple LDAP setup where you only need one PAS plugin, you might wish to use PloneLDAP and simplon.plone.ldap instead. Use this tutorial instead if you want to understand what is going on behind the scenes, or if your LDAP structure is more complex.
  • The python-ldap module for the python version that's running your zope instance. This must be installed with your zope instance python. There are source downloads as well as binaries for several platforms available from sourceforge. Windows users should note that there are other libraries required to build python-ldap.
  • LDAPMultiPlugin and LDAPUserFolder. These are available separately ( LDAPMultiPlugin and LDAPUserFolder ) There is also a bundle available from plone.org as part of the PloneLDAP product. At the time of this writing, the PloneLDAP product itself is still not released, but the LDAPMultiPlugin and LDAPUserFolder provided in the bundle are released products.

Install Prerequisites

 Note: The following assumes that your plone site is installed in /Plone in the ZMI.

  • Make sure ldap-python is installed and available under $ZOPEBASE. To test this, execute the python in your $ZOPEBASE directory and import the ldap module. No warnings or errors should be returned.

Example:

# /opt/Plone-2.5.3/Python-2.4.4/bin/python
>>> import _ldap>>>

  • Extract LDAPMutiPlugin and LDAPUserFolder from the above packages. Recursively copy the resulting directories into your Products directory. (/opt/Plone-3.0/zeocluster/Products if you were to use the all-in-one installer on linux, for example)
  • Ensure that these directories and all files in them are owned by the same user as your zope instance.
  • Restart zope and ensure that there are no errors.

 

Configure ZMI to allow authenticating of plone users

  • Navigate to "your plone site"/acl_users in ZMI (Do NOT confuse this with the acl_users under the Root Zope Instance)
  • In the upper right, select 'ActiveDirectory Multi Plugin', and click the 'Add' button. Fill out the form with the information below. 

If ActiveDirectory Multi Plugin is not in the list, there may have been an error in the previous steps. You will have to check your server logs to find the cause.


ID
A name for this PlonePAS plugin
Title
Name for this plugin, I use the same as ID
 LDAP Server[:port]
Hostname and port of your LDAP Server. For Active Directory, this is usually a windows domain controller. Normally port 389, but 3268 may be used to access the global directory port. Using port 3268 will allow you to use multiple OUs from a single PlonePAS plugin.
 Login Name Attribute
Attribute to use as a username to authenticate against. sAMAccountName should be correct.
User ID Attribute
This is what shows up as "Full Name" for this user in Plone.  cn is usually correct, as it is the person's full name.
RDN Attribute
'Relative Distinguished Name' attribute cn is usually correct.
Users Base DN
This is the subtree under which your users reside.
Group Storage
Whether or not your groups are stored on your LDAP server, or stored locally. If you have control over the AD,  you may want to store your groups there, otherwise local groups can insulate you from AD changes but mean additional maintenance on the Plone side for changes.
Manager DN
 This is the authentication information used to perform LDAP bind (log into ldap). You can use login information in the form: user@example.com
 User Object Classes
In addition to specifying the tree of your LDAP users, you can use LDAP Object Classes to differentiate them from other objects in your LDAP Schema. The defaults are probably sufficient.
 User Password Encryption
Level of encryption you want to use. SHA should be sufficient to make it operate, check your local security policies.
Default User Roles
This is the zope role a user authenticating with this PlonePAS plugin will be given by default. Anonymous may be sufficient, but Authenticated will give them more access, especially if you choose to lock down your site.  
Scope Boxes
This tells this PlonePAS plugin how much of the tree should be used to authenticate users or set groups. 
Read Only Checkbox
Check this if you do not want to alter LDAP data from Plone. One of the side affects of setting this is that your users will not be able to set their own preferences from the Member preferences page. 
After the form is filled out proplerly, click 'Add'. It should save without errors. To test to make sure you are communicating, click the 'Users' tab and search for a user known to exist under the Active Directory hierarchy you specified. The easiest way at this point is to select sAMAccountName from the dropdown and search for a username. If results are returned properly, zope is able to communicate with your Active Directory.

Enable Authentication for Plone Users

In ZMI, Navigate to Plone/acl_users/ADNAMEADNAME is what you specified for Title and ID above. On the Activate tab, you should see a number of checkboxes. To enable user authentication in Plone, you should select:

Authentication(authenticateCredentials)

Properties(getPropertiesForUser)

User Enumeration(enumerateUsers)

Then click 'Update' to save the changes. At this point, you should be able to log in using Active Directory credentials.

You may need additional boxes checked if you are using Active Directory to manage plone groups as well. There is documentation for each field if you navigate to Plone/acl_users/plugins in the ZMI.

Mapping Additional Attributes

You may have noticed at this point that you are able to authenticate, but other Active Directory properties, such as full name or email address are not visible in plone. To get these to show up, you need to perform additional mappings from plone user properties to LDAP user properties.

In ZMI, navigate to Plone/acl_users/ADNAME. ADNAME is what you specified for Title and ID above. Navigate to the LDAP Schema tab.

To map email address in plone to the user's Active Directory email, add an LDAP schema item.

Ldap Attribute Name: mail
Friendly Name: e-mail address
Don't check Multi-valued
Map to Name: email


This will set the plone users' email to their email from LDAP automatically.

Also common is to map fullname to the CN attribute.
To do this. delete the cn mapping from the top of the screen. Add a new LDAP Schema Item withe the following attributes.

Ldap Attribute Name: cn
Friendly Name: Full Name
Don't check Multi-valued
Map to Name: fullname

To make these properties take effect, you must set your plugin order so that PAS looks at the LDAP values first. To do so:

In ZMI, navigate to Plone/acl_users/plugins. Click 'Properties Plugins'. On the right you should see your Active Directory Multiplugin. Highlight it and move it to the top.

Notes

  • You can add several Active Directory plugins as described above, if you need multiple trees from your Active Directory schema. You should make sure that usernames won't be duplicated, however. There is some dicussion of the topic in this howto. Also see the note on port 3268 above.
  • simplon.plone.ldap and PloneLDAP together provide a simple interface and configlet if you only have one LDAP source
  • There is a patch for LDAPMultiPlugins needed to enable certain interfaces. You may need it depending on what you ultimately want to do with your LDAP integration.
  • If you are sourcing your groups from LDAP, be certain that you are not using ObjectGUID as your group identifier in the properties tab for your
    ADMultiPLugin object in zmi. ObjectGUID is a binary value and will cause an error where groups are used.

 

once a user is authenticated...

Posted by Ronaldo Nascimento at Sep 27, 2007 12:43 PM
i would like to have specific domain users to have specific priviledges on specific sub sections
in other words
authenticate everyone via AD, and the companies division supervisors own a subsection under the site
/root
----/sales (owned by joe smith)
----/r&d (onwed by fred johnson)
so joe smith can admin just the sales subsection, not the root or the r&d section
i hope this make sense

the question is how hard is this to do, or should i just make a plone instance for each division (bc there are about 20 some division each with a supervisor responsible for that sections content)

Subsections

Posted by Brian Johnson at Sep 27, 2007 05:43 PM
This is easy to do, you should ask this sort of question on the mailing list or IRC.

However, the quick explanation is that if you are using Plone3, you give that user full sharing permissions to that directory. It is unrelated to AD authentication, so you could do it with any authentication method.

Use a unique username in Plone setup

Posted by Gary Taylor at Feb 27, 2008 11:03 PM
   If you are planning to connect to AD, choose a username in the Zope/Plone installation that does not exist in your AD. You will get VERY strange behavior in the ZMI and the plone site if you don't.
This may seems obvious to most, but I banged my head on the keyboard for a couple of day before getting it.

good point

Posted by Brian Johnson at Feb 27, 2008 11:16 PM
We had this with a user named 'admin' on our network, which had some strange behavior and could give the AD user more privileges to your site than you expected.

'latin-1' codec can't encode ...

Posted by Watanabe, Katsutoshi at Apr 22, 2008 01:57 PM
I tried this how-to. but, when I tried to search a user with DN that includes some chinese characters at "User" tab of LDAPUserFolder, I've got an error like as follows:

>> 'latin-1' codec can't encode characters in position 3-4: ordinal not in range(256)

It didn't occur when I tried with another user with DN that doesn't include any chinese characters.

Are there any workaround? or it has already been fixed?



'latin-1' codec can't encode ...

Posted by Watanabe, Katsutoshi at Apr 22, 2008 01:57 PM
I tried this how-to. but, when I tried to search a user with DN that includes some chinese characters at "User" tab of LDAPUserFolder, I've got an error like as follows:

>> 'latin-1' codec can't encode characters in position 3-4: ordinal not in range(256)

It didn't occur when I tried with another user with DN that doesn't include any chinese characters.

Are there any workaround? or it has already been fixed?



environment

Posted by Watanabe, Katsutoshi at Apr 22, 2008 02:01 PM
I've forgotten to post my environment.
I'm using Plone3.0.6(Windows Installer version)

  Zope Version (Zope 2.10.5-final, python 2.4.4, win32)
  Python Version 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
  System Platform win32


 

solved

Posted by Watanabe, Katsutoshi at Apr 25, 2008 07:41 AM
i changed 53th line of Products/LDAPUserFolder/utils.py, and it worked. Thanks, anyway.

  original : encoding = 'latin1'
  changed to: encoding = 'utf-8'



Role Mapping doesn't work

Posted by Ian Young at Apr 22, 2008 08:00 PM
Having followed this, using the latest 3.0.6 installer for windows and linux, I'm unable to get my AD Group-> Zope Role mappings to show up or work in Plone. (And groups are right out). Members of the group assigned 'Member' Role are logged in only at the level marked in 'default user roles'. When I turn off group/role mapping and manually add an AD user to the 'manager' role logged in as the zope admin, that user can't view the groups, getting "'NoneType' object has no attribute 'getRoles'" in group.getRoles()

-Ian

New to Plone 3?

Posted by Brian Johnson at Apr 25, 2008 09:41 PM
The current best practice is to map AD Groups to Plone Groups. This is different from zope roles. Email the plone users list and I will respond if you need clarification.

User Authentication

Posted by Escola Americana at May 15, 2008 03:10 PM
Some users work out to log in, some not, after this installation.
Any new tip?
Plone: 3.0.5

GOT SOLVED!!

Posted by Escola Americana at May 16, 2008 02:15 PM
I set the User ID Attribute as the Login Name (sAMAccountName) and all users now are authenticating!!!!
So, "cn" for me did not work! Only SAMAccountName.
It always can be a particularity of my environment but still, this information can help many people that faced the problem that only some users could log!

Teers,

Formatting of add'l attributes

Posted by Richard Tango-Lowy at Mar 25, 2009 08:38 PM
Thanks for a great tutorial. I was able to get Plone connected to our Active Directory and synching very quickly. I have a question about adding Additional Attributes, though. I've mapped fullname and email, but both display misformatted in the Site Manager.

E.g. Full Name

Should display: (Richard Tango-Lowy)
Actually displays: ((Richard Tango-Lowy,))

and Email

Should display: rich@foobar.com
Actually displays: (rich@foobar.com,)

Is there a place I can fix this?

Rich

Formatting of add'l attributes

Posted by Brian Johnson at Mar 25, 2009 08:54 PM
Can you verify that these are actually set without the extra parenthesis in Active Directory? Also make sure neither of those are marked as Multi-valued in the 'LDAP Schema' tab in the ZMI.

Formatting of add'l attributes

Posted by Richard Tango-Lowy at Mar 26, 2009 01:27 PM
It was the "Multi-valued" checkbox. Unchecking it fixed the problem.

Thanks Brian!

Rich