Lucterios2 / django_auth_ldap3_ad

Simple LDAP/AD auth module for django
https://pypi.python.org/pypi/django-auth-ldap3-ad
GNU General Public License v3.0
45 stars 25 forks source link

When registering new users from AD, only the first character of any field is saved #8

Closed wells01440 closed 7 years ago

wells01440 commented 8 years ago

When creating new users, only the first character of the field gets saved in auth_users. For instance: In LDAP when givenName=Andrew, only 'A' gets saved.

The line of code causing it is 309 in auth.py: setattr(user, attr, attributes[settings.LDAP_ATTRIBUTES_MAP[attr]][0])

From my settings.py

LDAP_ATTRIBUTES_MAP = {
    'username': 'sAMAccountName',
    'first_name': 'givenName',
    'last_name': 'sn',
    'email': 'mail',
}

Changing line 309 to this fixes it for me setattr(user, attr, attributes[settings.LDAP_ATTRIBUTES_MAP[attr]])

Thx, Andy

povtux commented 8 years ago

Hi, Thanks for the info. Could you please tel me about your version of python, your version of ldap3 module and your version of Windows Server? I run Windows Server 2012 R2 with Python 3.4 and Python 3.5 and ldap3 1.4.0 and my ldap search results are not simple str ex:

{'sn': ['VERSCHOORE'], 'sAMAccountName': ['po.verschoore'], 'givenName': ['Pierre-Olivier'], 'mail': ['po.verschoore@xxx.com']}

Could you maybe try to replace line 309 by:

if isinstance(attributes[settings.LDAP_ATTRIBUTES_MAP[attr]], str): attribute_value = attributes[settings.LDAP_ATTRIBUTES_MAP[attr]] else: attribute_value = attributes[settings.LDAP_ATTRIBUTES_MAP[attr]][0] setattr(user, attr, attribute_value)

and tell me if it works for you?

Regards,

FacundoAcevedo commented 8 years ago

I'm getting the same issue

povtux commented 7 years ago

Hi, Could one or both of you tell me about his config? As I previously told, I don't experience the problem. Having a starting point to reproduce it would be nice.

Thanks.

nickers commented 7 years ago

I had the same problem. Obvious solution (removing index from last line) worked for me. Here someone did the same thing: https://github.com/wells01440/django_auth_ldap3_ad/commit/6e7efde696691b559acd81e3474b631c54113e33

There is pull request with your proposed solution (tested in my environment) - #10

Versions on client: