etianen/django-python3-ldap

Stop updating username on login

jcanning opened this issue · 4 comments

Hi All,

I have a need where I am syncing users from AD but the First Name Attribute is not the name i want to use. So with the Sync i update the user name to be the correct username (think something like 'Leonardus' to 'Leo').

This update works fine as i am doing a key/value pair loop to update from a list like so: User.objects.filter(first_name=k).update(first_name=v). However, the issue i am running into is when that user actually logs in, it re-updates the first name to the AD name.

Is there any way to turn that off or specify which attributes to sync upon login?

Here is my configuration:

LDAP_AUTH_URL = 'ldap://server.domain.com'
LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_active_directory"
LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = "domain"
LDAP_AUTH_CONNECTION_USERNAME = USER
LDAP_AUTH_CONNECTION_PASSWORD = PASSWORD
LDAP_AUTH_USE_TLS = False
LDAP_AUTH_SEARCH_BASE = "DC=domain,DC=com"

LDAP_AUTH_FORMAT_SEARCH_FILTERS = "appname.utils.custom_format_search_filters"
# nothing special here as this is just specifying groups

LDAP_AUTH_OBJECT_CLASS = "user"
LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)
LDAP_AUTH_USER_FIELDS = {
    "username": "sAMAccountName",
    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail",
}

Thanks,
jAC

Hi Dave,

That part makes sense but what i was wondering is if there was a way to not overwrite the user name after the first time it is synced? I only have 5 users out of 100 that need their name updated. So removing the first_name field would cause more work in the end.

So for example, just allow the ldap_sync_users command to set the first name and last name when not set anything if they are not synced.

Is something like that possible?

Thanks,
jAC

Ahh that's a good idea. Thanks Dave!