Project

General

Profile

Actions

Patch #4755

open

Create and maintain groups from LDAP attributes

Added by Marcel Waldvogel about 14 years ago. Updated over 12 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
LDAP
Target version:
-
Start date:
2010-02-08
Due date:
% Done:

80%

Estimated time:

Description

We do have group information in LDAP which we would like to use. These are essentially
  • ou (the organisational unit(s) the person is associated with)
  • businessCategory (the type of user: employee, guest, …)

I decided to write the following patch to automatically create and update group information for every user whenever she logs in, in order to avoid having to extract all the information regularly from LDAP, keeping in the spirit of on-the-fy creation of user accounts.

Challenges

During the implementation, I was facing the following problems:
  • I wanted to have both attributes available for group creation, both independently and as a cross product (i.e., being able to add all employees or everyone from orgUnit1 to the project, but also have the option to add only the employees of orgUnit1 to some project)
  • Our ou names are very long (some approaching 60 characters), but the lastname field of the User (which is where the group names are stored for the Group subclass/subtype of User) is limited to 30 characters. I did not want to change that part of the model, so I am shortening LDAP group names on import.

Functionality implemented

There are 5 additional fields in auth_source:
  1. attr_groups: The name of the attribute containing group information (in our case: ou)
  2. attr_groups2: The name of an optional second attribute containing other group information (in our case: businessCategory)
    • None, either, or both of the above can be empty, if they are not required
  3. group_prefix: A character sequence you might want to prefix to the group names which are thus automatically generated (default: "_")
  4. cross_product: When this is false, only the group names based on attr_groups and attr_groups2 are included. When this is set to true, additionally the concatenation of group names derived from attr_groups and attr_groups2 (separated by group_separator) are included
  5. group_separator: The separator to use if cross-products should be created

Groups created like that will have their auth_source set accordingly. Groups with their auth_source set will have an appropriate note attached in the list and edit views, and their name is not editable. LDAP-maintained groups are automatically deleted when they are no longer necessary (triggered on login).

The group list view provides a "Refresh groups" button for each LDAP source with group update activated. It is not strictly necessary, as membership will be updated on the next login of that user anyway, but it might be helpful to see what effect your changes have or make membership updates visible immediately (as opposed to waiting for the next login of this user/these users).

The messages are available in English and German. Feel free to provide other languages as well :-).

Code overview

Here is a short run-down of what the code provides:
  1. Two migration files to add the required attributes
  2. auth_source_ldap.rb has the following new features
    • a method get_attributes which fetches LDAP attributes for a user specified (does not test for authentication)
    • a method build_names to construct the names of the groups that should be associated with
    • Two classes, FakeLdapCon and FakeLdapEntry which are helpful when trying to experiment with LDAP attributes (do not require an LDAP server)
  3. user.rb has the following new features:
    • Can store group_names temporarily (needed to get things working with a consistent implementation for normal login, auto-relogin, and on-the-fly creation of users and to save a few round-trips to LDAP)
    • a method refresh_group_memberships to update the group membership information based on what was returned by LDAP
  4. group.rb was changed as follows:
    • Contains a new class method, shorten_lastname, to (nicely, IMHO) shorten group names when the names in LDAP exceed the length limit
    • Two new methods, size_and_updated_by_string and updated_by_string to simplify the form rendering routines
  5. auth_sources_controller.rb now includes a method for the "refresh groups" button described above
  6. auth_sources/list.rhtml and auth_sources/_form.rhtml do provide UI for this button and the new group fields
  7. groups/index.html.erb and groups/_form.html.erb do provide the UI changes for the automatic groups
  8. locales/en.yml and locales/de.yml have the text elements for the new UI
  9. migrate/20100207220329_extend_ldap_groups.rb and migrate/20100204211355_add_ldap_group_support.rb are the two new migrations (I did the implementation in two stages)

The patch

The patch includes a better version of #4643 (Allow on-the-fly creation on member addition), as I was unhappy with the way I originally hacked auth_source_ldap.rb (too much code duplication in my original version). If you do not want that feature, back out the change to members_controller.rb after applying the patch. Also, the change to auth_source.rb (new class methods import and get_data) is only strictly required when on-the-fly project member addition is needed.

The patch does not include #4732 (Make login case-insensitive also for PostgreSQL), although line numbers might reflect that change.

The patch is against 0.9.0rc.

Trunk integration?

Jean-Philippe et al.: What is required to get this code integrated into trunk? I think that LDAP integration without something like this is severely limited and thus this should be included.


Files

ldap-auto-groups.patch (24.6 KB) ldap-auto-groups.patch Marcel Waldvogel, 2010-02-08 01:35
ldap-auto-groups2.patch (24.6 KB) ldap-auto-groups2.patch Marcel Waldvogel, 2010-02-09 06:37
ldap-auto-groups3.patch (25.4 KB) ldap-auto-groups3.patch Cyril Lamy, 2010-09-17 16:47

Related issues

Related to Redmine - Feature #5742: Association of an LDAP group to a Redmine groupNew2010-06-23

Actions
Related to Redmine - Feature #5702: Please add ldap filters for authenticationClosed2010-06-16

Actions
Related to Redmine - Patch #4643: Allow on-the-fly creation on member additionClosed2010-01-24

Actions
Related to Redmine - Feature #6202: On-the-fly group addition based on LDAP sourcesNew

Actions
Actions

Also available in: Atom PDF