Bläddra i källkod

HUE-3437 [core] PamBackend does not honor ignore_username_case

Allow PamBackend to override authenticate method entirely, and avoid twice calling find_or_create for user
Jenny Kim 9 år sedan
förälder
incheckning
50dda74
1 ändrade filer med 22 tillägg och 12 borttagningar
  1. 22 12
      desktop/core/src/desktop/auth/backend.py

+ 22 - 12
desktop/core/src/desktop/auth/backend.py

@@ -27,26 +27,31 @@ In addition, the User classes they return must support:
 Because Django's models are sometimes unfriendly, you'll want
 User to remain a django.contrib.auth.models.User object.
 """
-from django.contrib.auth.models import User
-import django.contrib.auth.backends
+
+import ldap
 import logging
-import desktop.conf
-from desktop import metrics
-from django.utils.importlib import import_module
+import pam
+
+import django.contrib.auth.backends
+from django.contrib.auth.models import User
 from django.core.exceptions import ImproperlyConfigured
-from useradmin.models import get_profile, get_default_user_group, UserProfile
-from useradmin.views import import_ldap_users
-from useradmin import ldap_access
+from django.utils.importlib import import_module
 
-import pam
 from django_auth_ldap.backend import LDAPBackend
-import ldap
 from django_auth_ldap.config import LDAPSearch
+
+import desktop.conf
+from desktop import metrics
 from liboauth.metrics import oauth_authentication_time
 
+from useradmin import ldap_access
+from useradmin.models import get_profile, get_default_user_group, UserProfile
+from useradmin.views import import_ldap_users
+
 
 LOG = logging.getLogger(__name__)
 
+
 def load_augmentation_class():
   """
   Loads the user augmentation class.
@@ -294,14 +299,19 @@ class PamBackend(DesktopBackendBase):
   """
 
   @metrics.pam_authentication_time
-  def check_auth(self, username, password):
+  def authenticate(self, username, password):
+    username = desktop.conf.AUTH.FORCE_USERNAME_LOWERCASE.get() and username.lower() or username
+
     if pam.authenticate(username, password, desktop.conf.AUTH.PAM_SERVICE.get()):
       is_super = False
       if User.objects.count() == 0:
         is_super = True
 
       try:
-        user = User.objects.get(username=username)
+        if desktop.conf.AUTH.IGNORE_USERNAME_CASE.get():
+          user = User.objects.get(username__iexact=username)
+        else:
+          user = User.objects.get(username=username)
       except User.DoesNotExist:
         user = find_or_create_user(username, None)
         if user is not None and user.is_active: