Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 15, 2024
1 parent e1703bb commit f05a98f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions ldapauthenticator/ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
import ldap3
from jupyterhub.auth import Authenticator
from ldap3.utils.conv import escape_filter_chars
from traitlets import Bool, Int, List, Unicode, Union, UseEnum, validate, observe
from traitlets import Bool, Int, List, Unicode, Union, UseEnum, observe, validate


class TlsStrategy(enum.Enum):
"""
Represents a SSL/TLS strategy for LDAPAuthenticator to use when interacting
with the LDAP server.
"""

before_bind = 1
on_connect = 2
insecure = 3


class LDAPAuthenticator(Authenticator):
server_address = Unicode(
config=True,
Expand Down Expand Up @@ -56,13 +59,13 @@ def _observe_use_ssl(self, change):
if change.new:
self.tls_strategy = TlsStrategy.on_connect
self.log.warning(
'LDAPAuthenticator.use_ssl is deprecated in 2.0 in favor of LDAPAuthenticator.tls_strategy, '
"LDAPAuthenticator.use_ssl is deprecated in 2.0 in favor of LDAPAuthenticator.tls_strategy, "
'instead of configuring use_ssl=True, configure use tls_strategy="on_connect" from now on.'
)
else:
self.log.warning(
'LDAPAuthenticator.use_ssl is deprecated in 2.0 in favor of LDAPAuthenticator.tls_strategy, '
'you can stop configuring use_ssl=False from now on as doing so has no effect.'
"LDAPAuthenticator.use_ssl is deprecated in 2.0 in favor of LDAPAuthenticator.tls_strategy, "
"you can stop configuring use_ssl=False from now on as doing so has no effect."
)

tls_strategy = UseEnum(
Expand Down Expand Up @@ -350,15 +353,20 @@ def get_connection(self, userdn, password):
elif self.tls_strategy == TlsStrategy.before_bind:
use_ssl = False
auto_bind = ldap3.AUTO_BIND_TLS_BEFORE_BIND
else: # TlsStrategy.insecure
else: # TlsStrategy.insecure
use_ssl = False
auto_bind = ldap3.AUTO_BIND_NO_TLS

server = ldap3.Server(
self.server_address, port=self.server_port, use_ssl=use_ssl,
self.server_address,
port=self.server_port,
use_ssl=use_ssl,
)
conn = ldap3.Connection(
server, user=userdn, password=password, auto_bind=auto_bind,
server,
user=userdn,
password=password,
auto_bind=auto_bind,
)
return conn

Expand Down

0 comments on commit f05a98f

Please sign in to comment.