Sfoglia il codice sorgente

[core] Enable ignore_username_case and force_username_lowercase for SpnegoDjangoBackend

Jenny Kim 9 anni fa
parent
commit
005ea870b2

+ 2 - 2
desktop/conf.dist/hue.ini

@@ -257,11 +257,11 @@
     ## remote_user_header=HTTP_REMOTE_USER
 
     # Ignore the case of usernames when searching for existing users.
-    # Only supported in remoteUserDjangoBackend.
+    # Supported in remoteUserDjangoBackend and SpnegoDjangoBackend
     ## ignore_username_case=true
 
     # Ignore the case of usernames when searching for existing users to authenticate with.
-    # Only supported in remoteUserDjangoBackend.
+    # Supported in remoteUserDjangoBackend and SpnegoDjangoBackend
     ## force_username_lowercase=true
 
     # Users will expire after they have not logged in for 'n' amount of seconds.

+ 2 - 2
desktop/conf/pseudo-distributed.ini.tmpl

@@ -261,11 +261,11 @@
     ## remote_user_header=HTTP_REMOTE_USER
 
     # Ignore the case of usernames when searching for existing users.
-    # Only supported in remoteUserDjangoBackend.
+    # Supported in remoteUserDjangoBackend and SpnegoDjangoBackend
     ## ignore_username_case=true
 
     # Ignore the case of usernames when searching for existing users to authenticate with.
-    # Only supported in remoteUserDjangoBackend.
+    # Supported in remoteUserDjangoBackend and SpnegoDjangoBackend
     ## force_username_lowercase=true
 
     # Users will expire after they have not logged in for 'n' amount of seconds.

+ 5 - 1
desktop/core/src/desktop/auth/backend.py

@@ -480,12 +480,16 @@ class SpnegoDjangoBackend(django.contrib.auth.backends.ModelBackend):
   @metrics.spnego_authentication_time
   def authenticate(self, username=None):
     username = self.clean_username(username)
+    username = desktop.conf.AUTH.FORCE_USERNAME_LOWERCASE.get() and username.lower() or username
     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:

+ 1 - 1
desktop/core/src/desktop/conf.py

@@ -668,7 +668,7 @@ AUTH = ConfigSection(
                                   type=coerce_bool,
                                   default=True),
     FORCE_USERNAME_LOWERCASE = Config("force_username_lowercase",
-                                      help=_("Force usernames to lowercase when creating new users from LDAP."),
+                                      help=_("Force usernames to lowercase when creating new users."),
                                       type=coerce_bool,
                                       default=True),
     EXPIRES_AFTER = Config("expires_after",