remove search_base + fixed issue pointed out by mravi that results in different username in db and ldap

This commit is contained in:
ahmadbilalkhalid 2019-12-18 15:19:47 +05:00
parent 75b08cfbf8
commit 6c3f01003f
2 changed files with 2 additions and 7 deletions

View file

@ -737,7 +737,6 @@ LDAP_MAX_UID_FILE_PATH = os.environ.get('LDAP_MAX_UID_FILE_PATH',
LDAP_DEFAULT_START_UID = int(env('LDAP_DEFAULT_START_UID'))
# Search union over OUs
search_base = env('LDAPSEARCH').split()
AUTH_LDAP_START_TLS = bool(os.environ.get('LDAP_USE_TLS', False))
ENTIRE_SEARCH_BASE = env("ENTIRE_SEARCH_BASE")

View file

@ -100,6 +100,7 @@ def assign_username(user):
except IntegrityError:
# If username exists in database then come up with a new username
user.username = user.username + str(random.randint(0, 2 ** 10))
exist = True
def validate_name(value):
@ -221,12 +222,7 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
assign_username(self)
ldap_manager = LdapManager()
try:
user_exists_in_ldap, entries = ldap_manager.check_user_exists(
uid=self.username,
attributes=['uid', 'givenName', 'sn', 'mail', 'userPassword'],
search_base=settings.ENTIRE_SEARCH_BASE,
search_attr='uid'
)
user_exists_in_ldap, entries = ldap_manager.check_user_exists(self.username)
except Exception:
logger.exception("Exception occur while searching for user in LDAP")
else: