ldap auth: avoid creation of duplicated identities.

This commit is contained in:
Antoine Nguyen
2020-03-30 11:41:39 +02:00
parent 6f2bca12f1
commit 56a9c44b93
+11 -12
View File
@@ -84,18 +84,17 @@ try:
if grp.strip() in ldap_user.group_names:
group = "DomainAdmins"
break
if group == "SimpleUsers":
lpart, domain = split_mailbox(username)
if domain is None:
# Try to find associated email
email = None
for attr in ['mail', 'userPrincipalName']:
if attr in ldap_user.attrs:
email = ldap_user.attrs[attr][0]
break
if email is None:
return None
username = email
lpart, domain = split_mailbox(username)
if domain is None:
# Try to find associated email
email = None
for attr in ['mail', 'userPrincipalName']:
if attr in ldap_user.attrs:
email = ldap_user.attrs[attr][0]
break
if email is None and group == "SimpleUsers":
return None
username = email
user, created = User.objects.get_or_create(
username__iexact=username,
defaults={