Skip to content

Commit

Permalink
Add connect_timeout option for LDAP connection
Browse files Browse the repository at this point in the history
That option will enable the LDAP client to give up
to connect to the server in the specific seconds.
  • Loading branch information
Kota Tsuyuzaki committed Apr 20, 2021
1 parent 99dad8c commit 1f1eda8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ldapauthenticator/ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ def _server_port_default(self):
primary LDAP server is unavailable.
""",
)
connect_timeout = Int(
config=True,
default=15,
help="""
LDAP client connect timeout (seconds)
""",
)

def resolve_username(self, username_supplied_by_user):
search_dn = self.lookup_dn_search_user
Expand Down Expand Up @@ -337,7 +344,10 @@ def get_connection(self, userdn, password):

def _get_real_connection(self, userdn, password, server_address, server_port):
server = ldap3.Server(
server_address, port=server_port, use_ssl=self.use_ssl
server_address,
port=server_port,
use_ssl=self.use_ssl,
connect_timeout=self.connect_timeout,
)
auto_bind = (
ldap3.AUTO_BIND_NO_TLS if self.use_ssl else ldap3.AUTO_BIND_TLS_BEFORE_BIND
Expand Down

0 comments on commit 1f1eda8

Please sign in to comment.