Fix #7751 - LDAP: Only get API user from ldap when FIND_GROUP_PERMS is enabled

This commit is contained in:
kkthxbye 2021-11-25 08:09:50 +01:00
parent 86ada33577
commit 8bb0cba949

View File

@ -29,10 +29,13 @@ class TokenAuthentication(authentication.TokenAuthentication):
if settings.REMOTE_AUTH_BACKEND == 'netbox.authentication.LDAPBackend': if settings.REMOTE_AUTH_BACKEND == 'netbox.authentication.LDAPBackend':
from netbox.authentication import LDAPBackend from netbox.authentication import LDAPBackend
ldap_backend = LDAPBackend() ldap_backend = LDAPBackend()
user = ldap_backend.populate_user(token.user.username)
# If the user is found in the LDAP directory use it, if not fallback to the local user # Load from LDAP if FIND_GROUP_PERMS is active
if user: if ldap_backend.settings.FIND_GROUP_PERMS:
return user, token user = ldap_backend.populate_user(token.user.username)
# If the user is found in the LDAP directory use it, if not fallback to the local user
if user:
return user, token
return token.user, token return token.user, token