Skip to content

Commit aa57347

Browse files
authored
Remove duplicated bind code (#104)
1 parent 2e9d781 commit aa57347

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

ldap_auth_provider.py

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -475,33 +475,13 @@ async def _ldap_authenticated_search(self, server, password, filters):
475475
"""
476476

477477
try:
478-
conn = await threads.deferToThread(
479-
ldap3.Connection,
480-
server,
481-
self.ldap_bind_dn,
482-
self.ldap_bind_password,
483-
raise_exceptions=True,
484-
)
485-
logger.debug(
486-
"Established LDAP connection in search mode: %s",
487-
conn
478+
result, conn = await self._ldap_simple_bind(
479+
server=server,
480+
bind_dn=self.ldap_bind_dn,
481+
password=self.ldap_bind_password,
488482
)
489483

490-
if self.ldap_start_tls:
491-
await threads.deferToThread(conn.open)
492-
await threads.deferToThread(conn.start_tls)
493-
logger.debug(
494-
"Upgraded LDAP connection in search mode through "
495-
"StartTLS: %s",
496-
conn
497-
)
498-
499-
if not await threads.deferToThread(conn.bind):
500-
logger.warning(
501-
"Binding against LDAP with `bind_dn` failed: %s",
502-
conn.result['description']
503-
)
504-
await threads.deferToThread(conn.unbind)
484+
if not result:
505485
return (False, None, None)
506486

507487
# Construct search filter

0 commit comments

Comments
 (0)