Support LDAP servers where one doesn't first have to bind to the LDAP server with a username/password (#3002)

* Support LDAP servers where one doesn't first have to bind to the LDAP server with a username/password

* Address code climate things
This commit is contained in:
Jakdaw
2019-04-14 08:36:41 +01:00
committed by Arik Fraimovich
parent 563e34a816
commit 63e052c3a3

View File

@@ -62,7 +62,16 @@ def login(org_slug=None):
def auth_ldap_user(username, password):
server = Server(settings.LDAP_HOST_URL, use_ssl=settings.LDAP_SSL)
conn = Connection(server, settings.LDAP_BIND_DN, password=settings.LDAP_BIND_DN_PASSWORD, authentication=settings.LDAP_AUTH_METHOD, auto_bind=True)
if settings.LDAP_BIND_DN is not None:
conn = Connection(
server,
settings.LDAP_BIND_DN,
password=settings.LDAP_BIND_DN_PASSWORD,
authentication=settings.LDAP_AUTH_METHOD,
auto_bind=True
)
else:
conn = Connection(server, auto_bind=True)
conn.search(settings.LDAP_SEARCH_DN, settings.LDAP_SEARCH_TEMPLATE % {"username": username}, attributes=[settings.LDAP_DISPLAY_NAME_KEY, settings.LDAP_EMAIL_KEY])