taiga-contrib-ldap-auth icon indicating copy to clipboard operation
taiga-contrib-ldap-auth copied to clipboard

Login failed at the second time

Open rawbean opened this issue 10 years ago • 12 comments

When i login to taiga successfully(with ldap user/password), then l logout. but when i try to login again, the server returned 500 error code, please find the details below:

api response: {"error": "Server application error"}

the backend log:

MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Django] ERROR (EXTERNAL IP): Internal Server Error: /api/v1/auth From: [email protected] To: [email protected] Date: Tue, 04 Aug 2015 10:48:43 -0000 Message-ID: [email protected]

Internal Server Error: /api/v1/auth Traceback (most recent call last): File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_ldap_auth/services.py", line 41, in ldap_register user = user_model.objects.get(username=username) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method return getattr(self.get_queryset(), name)(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/query.py", line 357, in get self.model._meta.object_name) taiga.users.models.DoesNotExist: User matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) psycopg2.IntegrityError: duplicate key value violates unique constraint "users_user_email_6a1bbd04b7b1e907_uniq" DETAIL: Key (email)=([email protected]) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/core/handlers/base.py", line 111, in get_response response = wrapped_callback(request, _callback_args, *_callback_kwargs) File "/home/taiga/taiga-back/taiga/base/api/viewsets.py", line 81, in view return self.dispatch(request, _args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 57, in wrapped_view return view_func(_args, *_kwargs) File "/home/taiga/taiga-back/taiga/base/api/views.py", line 420, in dispatch response = self.handle_exception(exc) File "/home/taiga/taiga-back/taiga/base/api/views.py", line 417, in dispatch response = handler(request, _args, *_kwargs) File "/home/taiga/taiga-back/taiga/auth/api.py", line 142, in create data = auth_plugins[login_type]'login_func' File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_ldap_auth/services.py", line 58, in ldap_login_func user = ldap_register(username=username, email=email, full_name=full_name) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/transaction.py", line 394, in inner return func(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_ldap_auth/services.py", line 47, in ldap_register full_name=full_name) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method return getattr(self.get_queryset(), name)(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/query.py", line 372, in create obj.save(force_insert=True, using=self.db) File "/home/taiga/taiga-back/taiga/users/models.py", line 162, in save super().save(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 589, in save force_update=force_update, update_fields=update_fields) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 617, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 698, in _save_table result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 731, in _do_insert using=using, raw=raw) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method return getattr(self.get_queryset(), name)(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/query.py", line 921, in _insert return query.get_compiler(using=using).execute_sql(return_id) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 921, in execute_sql cursor.execute(sql, params) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/utils.py", line 94, in exit six.reraise(dj_exc_type, dj_exc_value, traceback) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise raise value.with_traceback(tb) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) django.db.utils.IntegrityError: duplicate key value violates unique constraint "users_user_email_6a1bbd04b7b1e907_uniq" DETAIL: Key (email)=([email protected]) already exists.

Request repr(): <WSGIRequest path:/api/v1/auth, GET:<QueryDict: {}>, POST:, COOKIES:{'csrftoken': '3lPmB5k8FEParGCoAyb8YzbjPAjF8Wju', 'sessionid': 'jlr85w8fdry564kkuv8oh9dlcg2quf17'}, META:{'CONTENT_LENGTH': '65', 'CONTENT_TYPE': 'application/json', 'HTTP_ACCEPT': 'application/json, text/plain, /', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate', 'HTTP_ACCEPT_LANGUAGE': 'en', 'HTTP_CONNECTION': 'close', 'HTTP_COOKIE': 'sessionid=jlr85w8fdry564kkuv8oh9dlcg2quf17; ' 'csrftoken=3lPmB5k8FEParGCoAyb8YzbjPAjF8Wju', 'HTTP_HOST': '172.17.26.30', 'HTTP_ORIGIN': 'http://172.17.26.30', 'HTTP_REFERER': 'http://172.17.26.30/login', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) ' 'AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/44.0.2403.125 Safari/537.36', 'HTTP_X_FORWARDED_FOR': '172.17.11.141', 'HTTP_X_FORWARDED_PROTO': 'http', 'HTTP_X_REAL_IP': '172.17.11.141', 'HTTP_X_SCHEME': 'http', 'HTTP_X_SESSION_ID': 'b52ac488437f6fcf3038073e80e915414452e9ef', 'PATH_INFO': '/api/v1/auth', 'QUERY_STRING': '', 'RAW_URI': '/api/v1/auth', 'REMOTE_ADDR': '127.0.0.1', 'REMOTE_PORT': '37738', 'REQUEST_METHOD': 'POST', 'SCRIPT_NAME': '', 'SERVER_NAME': '127.0.0.1', 'SERVER_PORT': '8001', 'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_SOFTWARE': 'gunicorn/19.3.0', 'gunicorn.socket': <socket.socket fd=10, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 8001), raddr=('127.0.0.1', 37738)>, 'wsgi.errors': <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7fb1afad0e48>, 'wsgi.file_wrapper': <class 'gunicorn.http.wsgi.FileWrapper'>, 'wsgi.input': <gunicorn.http.body.Body object at 0x7fb1afad0278>, 'wsgi.multiprocess': True, 'wsgi.multithread': False, 'wsgi.run_once': False, 'wsgi.url_scheme': 'http',

'wsgi.version': (1, 0)}>

rawbean avatar Aug 04 '15 10:08 rawbean

i found why the error occurred. because the prefix of email address contain a '.' character, but when the first login succeed the saved username in the database lost the '.' character, for example :

[email protected]

the saved user info:

email username [email protected] xxyy

but i don't known how to fix it, any one can help me?

rawbean avatar Aug 04 '15 11:08 rawbean

may be this is a bug of taiga?

rawbean avatar Aug 13 '15 00:08 rawbean

I have the same issue.

A quick fix is to correct the username from the taiga db.

SELECT id,username FROM users_user;
update users_user set username='user.with.dot' where id=XX;

Tetelu avatar Sep 24 '15 11:09 Tetelu

@Tetelu yes, this is what i do. but we need to do this for every user. Thanks for your share!

rawbean avatar Oct 20 '15 11:10 rawbean

@rawbean Well I took some time and made some local fixes in ./.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_ldap_auth/services.py

        # Create a new user
        # emails in AD have upper and lower case and it didn't match with what was in DB. I made it lower case
        email=email.lower()
        # slugify_uniquely - deleted the dot, so I didn't use it anymore, just replaced it with username
        username_unique = slugify_uniquely(username, user_model, slugfield="username")
        user = user_model.objects.create(email=email,
                                         username=username,
                                         full_name=full_name)

Tetelu avatar Oct 22 '15 16:10 Tetelu

I had to do the same @Tetelu did. @Tetelu why don't you create a Pull Request on this. I could create it if you like. :)

pjcuadra avatar Jan 19 '16 21:01 pjcuadra

@pjcuadra @Tetelu please create a pull request if you guys already have a solution. Thanks~ :)

ensky avatar Feb 23 '16 14:02 ensky

Thanks @Tetelu ! It helps a lot. Don't forget to drop the oraginal DB "taiga" and recreate it. Follow this or simply excute ./ regenerate.sh in /home/taiga/taiga-back.

jolinx avatar Mar 01 '16 11:03 jolinx

Hi,

I had the same problem, the first login is ok but failed after a logout. This is because my login in ldap contain a character "." and the fucntion slugify_uniquely delete the dot when the user is registred. To fix this, I change in file services.py the line : user = user_model.objects.get(username=username)

by : user = user_model.objects.get(username=username.replace('.', ''))

It works fine for me.

omauger avatar Apr 22 '16 14:04 omauger

Same issue here, our AD login look like [email protected], hence first connection & user creation OK, next one KO.

Went with @omauger solution.

rgarrigue avatar Jan 10 '17 16:01 rgarrigue

This issue could be closed in favour to issue #45, and PR #43.

filhocf avatar Mar 29 '17 23:03 filhocf

Hi! Welcome to 2019. This is still a bug.

@filhocf #45 is a duplication of this one -- so if anything, close #45

hdave avatar Feb 27 '19 21:02 hdave