[PATCH] LDAP enrolment enhancements (specially for MS Active Directory users)

[PATCH] LDAP enrolment enhancements (specially for MS Active Directory users)

by Iñaki Arenaza -
Number of replies: 11
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I've just finished a small patch that 'fixes' a long standing issue with LDAP enrolment for those who use MS Active Directory: the need to use 'distinguishedName' as the ID Number for the user.

I needed to fix it as part of the real enhancement I was after: the ability to use nested groups with LDAP enrolment. There have been several requests in the past: here, here, here and here for example, and this time I needed it too, so I've gone ahead and done it wink. The patch offers both features, and each one of them can be enabled independently.

In order to keep the patch restricted to the LDAP enrolment plugin I've had to duplicate a bit of code from the LDAP authentication plugin (namely ldap_find_userdn() and filter_addslashes()), that should ideally be refactored in a common LDAP library (that is part of a longer term effort I'm tackling separately wink)

The first feature (not needing to use distinguishedName) is based on a couple of premises:

  1. that you may not be using LDAP authentication (quite improbable, but certainly possible).

  2. that having a peek at the LDAP authentication settings (to use them) might not be a good idea. This introduces dependencies on the authentication plugin that can make the enrolment plugin morefragile.

So the patch adds a new few settings for this feature to work (that are basically a replica of the ones in the authentication plugin) to specify:

  1. if the group member attribute contains distinguished names or not (we need to set it to 'Yes' with MS Active Directory). The default value is 'No', which is the current behaviour.

  2. the LDAP attribute we'll use to resolve the Moodle username to the LDAP distinguished name (e.g, 'sAMAccountName', 'cn', etc.). The default value is empty.

  3. the LDAP contexts where we are going to search for the users, as will need to resolve the Moodle username to the LDAP distinguished name. The default value is empty

  4. if we want to search the users in sub-contexts of the specified contexts or not. The default value is 'No'.

The default values make the enrolment plugin behave exactly like now, so it should be safe to use it in existing setups.

Regarding the second feature (nested groups), due to the way the current enrolment code works, it depends on having an LDAP attribute that tells us what groups a given object belongs to (e.g., 'memberOf' in the case of MS Active Directory), and we need to specify that attribute in the settings page.

The code then recursively finds all the groups a given object (initially the user object) belongs to, keeping track of already 'seen' groups (as MS Active Directory allows you to make circular references between groups!!!). And then the course search filter is modified to include not only the user but all the groups found, specifying that any of them can be the member of the course group.

I have tested the patch with both MS Active Directory (which does use distinguished names in group membership and allows nested groups) and OpenLDAP (which neither uses distinguished names nor allows nested groups -as far as I know-) and everything works as expected.

The patch is available for 1.8, 1.9 and HEAD (and could backport it to 1.7 if there is demand for it).

Do you think this could/should go into core?

Saluduos. Iñaki.

P.S. You can get the patches from http://orodruin.escomposlinux.org/~iarenaza/moodle/enrol_ldap_groups/

Average of ratings: -
In reply to Iñaki Arenaza

Re: [PATCH] LDAP enrolment enhancements (specially for MS Active Directory users)

by Matt Gibson -
I don't use LDAP enrolment, but would be keen to get site-wide groups working with this in 2.0.

Votes please smile

MDL-15416
In reply to Matt Gibson

Re: [PATCH] LDAP enrolment enhancements (specially for MS Active Directory users)

by Christoph Ruda -

1 vote here.

Regards,

Christoph

In reply to Matt Gibson

Re: [PATCH] LDAP enrolment enhancements (specially for MS Active Directory users)

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

While what you propose has (almnost) nothing to do with this patch, I'de like to point out that we (as a community) should decide, once and for all, if we are going to base LDAP enrolment either on groups or on organizational units. But I think we can't/shouldn't have it both ways.

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: [PATCH] LDAP enrolment enhancements

by Neil S -
We use ldap authentication but to date have stuck with database enrollment. I've looked at the possibility of using ldap for the purpose of enrollment but we have more work to do with our directory first...

If I had to choose between groups or OU's -- I would say groups as that seems to be the most widely used mechanism.

Why would having both be such a bad option assuming the resources are available to make it so?

Thanks!
Neil S
In reply to Neil S

Re: [PATCH] LDAP enrolment enhancements

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Why would having both be such a bad option assuming the resources are available to make it so?

More settings to set correctly (which means more room to make mistakes, and possibly harder to troubleshoot) and code complexity (groups and organizational units are treated differently at the code level).

Not to mention the possible headaches for the newbies: which one should I use? why? which one is better? can I use both at the same time? etc.

While it could be done, I'm not sure it's really worth it.

Saludos. Iñaki.
In reply to Iñaki Arenaza

Re: [PATCH] LDAP enrolment enhancements

by Matt Gibson -
Hi Iñaki,

sorry for slightly hijacking the thread blush. I should have pointed out, of course, that I think the patch is great and should certainly go in core. Regarding the groups/OUs, I would strongly vote for supporting both as it would seem a bit odd to say that Moodle supports LDAP groups, but then for it to only work with certain configurations.

I have just set up a drupal instance using the LDAP-integration module and found the option to use either groups or OUs was a godsend, as we use OUs and from what Dan says below, we may be in a minority. Interestingly, Drupal links LDAP to role creation, so now, people have roles are generated automatically from OUs, which would be a very useful Moodle feature.

Although it may be a little more work, I think it would be imporant to ofer both options, or else some people would be excluded. Setting up LDAP is not really newbie territory anyway, so some complexity can be expected and I think the docs can set people straight if they are confused.


In reply to Matt Gibson

Re: [PATCH] LDAP enrolment enhancements

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
IMO - it's not worth a developer spending their spare time working on. - but if a client wanted to pay for the work to be done, and the use of OU's was a requirement - then I think it would be "useful" for it to go into core but still not a high priority....

smile

Dan
In reply to Iñaki Arenaza

Re: [PATCH] LDAP enrolment enhancements (specially for MS Active Directory users)

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
+1 - great work Iñaki!!

my +1 for groups instead of OU's - a user normally sits within a single OU (in the various Ldap structures I've seen in production anyway) and they normally have multiple groups.

smile

Dan
In reply to Iñaki Arenaza

Re: [PATCH] LDAP enrolment enhancements (specially for MS Active Directory users)

by Martín Langhoff -
First - thanks I~naki for looking after enrol/ldap!

Second - I think we should try our best to support it both ways. Moodle does not get to force the hand of the LDAP admin, if it did moodle would tell the LDAP admin to stay home and not bother smile. Moodle+LDAP is usually found in places where LDAP pre-dates Moodle or at least is used by other systems too. By being flexible and not forcing the LDAP tree arrangement, we can be everybody's friend smile

It is - of course - more work mixed
In reply to Martín Langhoff

Re: [PATCH] LDAP enrolment enhancements (specially for MS Active Directory users)

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think we should try our best to support it both ways

Both ways as in 'one or the other, but not both at the same time' (boolean xor) or as in 'one or the other, even at the same time' (boolean or)?

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: [PATCH] LDAP enrolment enhancements (specially for MS Active Directory users)

by Martín Langhoff -
One _or_ the other, not both at the same time. smile

I'm not *that* crazy yet. I think...