Skip to content

Commit

Permalink
fix Linux login always invalid because it cannot read Django passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Käser committed Aug 11, 2015
1 parent 4f2ed3c commit e848cd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
8 changes: 6 additions & 2 deletions ipynbsrv/core/auth/authentication_backends.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from hashlib import md5
from ipynbsrv.contract.errors import AuthenticationError, ConnectionError, \
UserNotFoundError
from ipynbsrv.core.helpers import get_user_backend_connected
from ipynbsrv.core.helpers import get_internal_ldap_connected, get_user_backend_connected
from ipynbsrv.core.models import BackendGroup, BackendUser, \
CollaborationGroup
import logging
Expand Down Expand Up @@ -35,11 +36,13 @@ def authenticate(self, username=None, password=None):
return None # not allowed, Django only user

try:
internal_ldap = get_internal_ldap_connected()
user_backend = get_user_backend_connected()
user_backend.auth_user(username, password)
if user is not None: # existing user
if not user.check_password(password):
user.set_password(password)
user.set_password(password) # XXX: not needed. should we leave it empty?
internal_ldap.set_user_password(username, md5(password).hexdigest())
user.save()
else: # new user
uid = BackendUser.generate_internal_uid()
Expand All @@ -61,6 +64,7 @@ def authenticate(self, username=None, password=None):
return None
finally:
try:
internal_ldap.disconnect()
user_backend.disconnect()
except:
pass
Expand Down
18 changes: 0 additions & 18 deletions ipynbsrv/core/signals/backend_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,6 @@ def remove_public_directory(sender, user, **kwargs):
raise ex


@receiver(backend_user_modified)
def update_password_on_internal_ldap(sender, user, fields, **kwargs):
"""
Update the password on the internal LDAP server on change.
"""
if user is not None:
try:
internal_ldap = get_internal_ldap_connected()
internal_ldap.set_user_password(user.backend_pk, user.django_user.password)
except UserNotFoundError:
user.delete() # XXX: cleanup
finally:
try:
internal_ldap.disconnect()
except:
pass


@receiver(post_delete, sender=BackendUser)
def post_delete_handler(sender, instance, **kwargs):
"""
Expand Down

0 comments on commit e848cd0

Please sign in to comment.