Browse Source

Added mapping of LDAP userID: 12345678 to OS user: a2345678 using python PWD module (#2276)

PR: 2276
Ref: CDPD-21262
Mahesh Balakrishnan 4 years ago
parent
commit
9286bcd834
2 changed files with 10 additions and 2 deletions
  1. 9 1
      desktop/core/src/desktop/auth/backend.py
  2. 1 1
      desktop/core/src/desktop/conf.py

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

@@ -422,7 +422,7 @@ class PamBackend(DesktopBackendBase):
     username = force_username_case(username)
 
     if AUTH.PAM_USE_PWD_MODULE.get():
-      LOG.debug('setting username to %s using pam pwd module for user %s' % (getpwnam(username).pw_name, username))
+      LOG.debug('Setting username to %s using PAM pwd module for user %s' % (getpwnam(username).pw_name, username))
       username = getpwnam(username).pw_name
 
     if pam.authenticate(username, password, AUTH.PAM_SERVICE.get()):
@@ -594,6 +594,14 @@ class LdapBackend(object):
       LOG.warning("LDAP was not properly configured: %s", detail)
       return None
 
+    if AUTH.PAM_USE_PWD_MODULE.get():
+      LOG.debug('Setting LDAP username to %s using PAM pwd module for user %s' % (getpwnam(username).pw_name, username))
+      pam_user = getpwnam(username).pw_name
+      try:
+        user = User.objects.get(username__iexact=pam_user)
+      except User.DoesNotExist:
+        user = find_or_create_user(pam_user, None)
+
     if user is not None and user.is_active:
       profile = get_profile(user)
       profile.creation_method = UserProfile.CreationMethod.EXTERNAL.name

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

@@ -1086,7 +1086,7 @@ AUTH = ConfigSection(
                   help=_("The service to use when querying PAM. "
                          "The service usually corresponds to a single filename in /etc/pam.d")),
     PAM_USE_PWD_MODULE=Config("pam_use_pwd_module",
-                       help=_("To use python unix pwd module to get the username from the entered credentials in hue if Centrify like pam service is in use. "
+                       help=_("To use Python unix pwd module to get the username from the entered credentials in hue if Centrify like PAM service is in use. "
                               "This will set the username to what is being returned by the pwd module."),
                        type=coerce_bool,
                        default=False),