LDAP Auth data mapping custom user fields

LDAP Auth data mapping custom user fields

by Oliver Jackson -
Number of replies: 6

I've been using LDAP auth from Active Directory successfully for a a while now with several Data Mapping relationships set on standard user profile fields.

I've just decided to try using Data Mapping for a custom user profile field and it's generating errors from auth/ldap/cli/sync_users.php (using Moodle 2.6.1).

My custom field has a shortname of LUI and I'm mapping it to an AD attribute which will map successfully to a standard profile field like "Phone 1".

The PHP Notice generated is:

Undefined property: stdClass::$profile_field_LUI in /var/www/auth/ldap/auth.php on line 1022

All standard profile fields possess a sensible value of $key on line 1022 (such as firstname or lastname or idnumber as found in the $user object) but the custom LUI field in not present in the $user object being used here.

Is there some documentation I have overlooked on using Data Mapping for custom profile fields with LDAP auth?

Average of ratings: -
In reply to Oliver Jackson

Re: LDAP Auth data mapping custom user fields

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
Hi Oliver,

unfortunately the code dealing with mapping custom profile fields doesn't work if you use upper case (or mixed case) in your custom profile fields shortnames, as it expects they are all lowercase (see https://tracker.moodle.org/browse/MDL-16982?focusedCommentId=229468&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-229468). So if you rename your LUI custom profile field to lui, it should work.

Saludos.
Iñaki.
Average of ratings: Useful (1)
In reply to Iñaki Arenaza

Re: LDAP Auth data mapping custom user fields

by Oliver Jackson -

Thanks Iñaki.

I'm still having no success.

The lower case shortname change didn't fix it.

Deleting the custom field and creating a new one with lower case shortname didn't fix it.

Using the default "Other fields" category rather than a user added category didn't fix it.

Using a new unique shortname (in case caching was causing something) didn't fix it.

If I set the Data Mapping for this custom field to "On creation" rather than "On every login" then the auth/ldap/cli/sync_users.php runs auth/ldap/auth.php without error but no data sync occurs.

 

If I set the Data Mapping to "On every login" and just let users log in then the data gets created correctly in mdl_user_info_data on login. I just have to cope with thousands of "PHP Notice" lines in my sync_users.php output.

 

I also discovered that deleting a custom user profile field doesn't clean the Data Mapping record from LDAP auth settings. It just hides it from the configuration page but still tries to perform the mapping during sync_users.php. I had to recreate the custom field with the correct shortname, then unmap it from the ldap auth settings page, then delete the custom field again. I didn't test if purging caches might have resolved this for me.

 

So it's working for me as users log in now but it will be a while before I have all the data in there.

In reply to Oliver Jackson

Re: LDAP Auth data mapping custom user fields

by Lael ... -

I'm also trying to make this work and having trouble with it. The latest issue is that the mappings simply don't 'stick' on the LDAP page - they just vanish after putting in the required AD field name.

Has anyone got this working reliably?

In reply to Lael ...

Re: LDAP Auth data mapping custom user fields

by Michael O'Brien -

While it might be too early to say if they will stick around but in Moodle 2.7 I was able to get custom user profile fields to sync from ldap and use a custom category after they initially didn't work for me.


To undo (as mentioned above) existing non-working customer user fields

  1. remove any data mapping in place in the ldap settings for your custom profile field
  2. remove the fields from users -> accounts - User Profile Fields
  3. remove the custom category (if you had them)
  4. Purge all cache (just to be sure)
  5. Go back to the ldap data mapping page in Plugins -> Auth ->Ldap server -> data mapping and confirm your old fields are gone
  6. Add your custom category
  7. Add your custom fields in users -> accounts - User Profile Fields but remember
    1. Use lowercase values for the shortname and probably best to avoid spaces etc.
    2. I used the text input field type so can't comment on anything else working
  8. Go back to the ldap server settings and re-map your ldap field to your custom field, I used an extra field to sync with a value I already knew worked in the non-custom fields to rule out any possible issue of my ldap not sending the right field or an issue with using a custom category
  9. Set the field to update at login and logout and back in again to verify it worked (if your account is set to use ldap of course)


In reply to Michael O'Brien

Re: LDAP Auth data mapping custom user fields

by Michael O'Brien -

Also not sure but assume if a data mapping field generates too many errors it gets removed from the ldap mapping as 1 mapping was removed while another survived an execution of ldap sync users

In reply to Michael O'Brien

Re: LDAP Auth data mapping custom user fields

by Olumuyiwa Taiwo -
Picture of Plugin developers

This doesn't work for me when I run sync_users.php from the command line or as a cron job, but seems to work when users login.

I have two custom profile fields -- text format, lowercase shortnames. LDAP server setting "Update local" is set to "On every login" for the custom fields.

I had a look at the sync_users() function in auth.php but can't locate where it actually updates the custom profile fields. There's  a call to update_user_record() which in turn calls user_update_user() which updates only the user table. I can't find where it updates the user_info_data and user_info_field tables.

What am I missing?