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

SQL Error during login (LDAP3ADBackend.authenticate()) #28

Open maikelvallinga opened 5 years ago

maikelvallinga commented 5 years ago

Testing this LDAP/AD module, but after the successful login we get an error.

ProgrammingError at /login/
function upper(text[]) does not exist
LINE 1: ...user" WHERE UPPER("auth_user"."username"::text) = UPPER(ARRA...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Followed the error with the python debugger and it crashes within the authentication() method. This is because the result is a list and not the user itself.

try:
      # try to retrieve user from database and update it
       username_field = getattr(settings, 'LDAP_USER_MODEL_USERNAME_FIELD', 'username') 
       lookup_username = user_attribs[settings.LDAP_ATTRIBUTES_MAP[username_field]]
       usr = user_model.objects.get(**{"{0}__iexact".format(username_field): lookup_username})

Changing lookup_username to lookup_username[0] solves the issue, but is this the solution? Do other people encounter the same issue?

povtux commented 4 years ago

Hi, This is the first time I hear about the problem.

actually lookup_username should be a string, so looking for lookup_username[0] should not work as it should look at the first character of the string only.

Without any further tests, the only way I see for lookup_username to become an array and make it work with the [0] is that the LDAP attribute you parameterized is not unique in users.

As you seem to be able to, could you maybe tell me if your lookup_username has multiple values and which attribute you use and the version of your Windows AD server so that I make tests?

Thanks