Add support for multiple ways to bind to the LDAP server. #3541

pull/5379/head
Bruno Almeida 2022-09-28 06:17:56 +01:00 committed by GitHub
parent 5fbb8b6204
commit e3e0e3db19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -645,6 +645,15 @@ LDAP_ANONYMOUS_BIND = False
# OpenLDAP example: CN=Users,dc=example,dc=com
LDAP_BASE_DN = '<Base-DN>'
# Configure the bind format string
# Default: LDAP_BIND_FORMAT="
# {LDAP_USERNAME_ATTRIBUTE}={LDAP_USERNAME},{LDAP_BASE_DN}"
# The current available options are:
# LDAP_USERNAME_ATTRIBUTE, LDAP_USERNAME, LDAP_BASE_DN
# Example: LDAP_BIND_FORMAT="myldapuser@sales.example.com"
# LDAP_BIND_FORMAT="NET\\myldapuser"
LDAP_BIND_FORMAT = '{LDAP_USERNAME_ATTRIBUTE}={LDAP_USERNAME},{LDAP_BASE_DN}'
##########################################################################
# Search ldap for further authentication (REQUIRED)

View File

@ -65,9 +65,12 @@ class LDAPAuthentication(BaseAuthentication):
# username and password
if not self.bind_user and not self.bind_pass and\
self.anonymous_bind is False:
user_dn = "{0}={1},{2}".format(config.LDAP_USERNAME_ATTRIBUTE,
self.username,
config.LDAP_BASE_DN
user_dn = config.LDAP_BIND_FORMAT\
.format(
LDAP_USERNAME=self.username,
LDAP_BASE_DN=config.LDAP_BASE_DN,
LDAP_USERNAME_ATTRIBUTE=config.LDAP_USERNAME_ATTRIBUTE
)
self.bind_user = user_dn