Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2023-12-07 10:34:32 +01:00
parent 1cbe87c077
commit cf393f9334
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
1 changed files with 13 additions and 13 deletions

View File

@ -170,7 +170,7 @@ class LDAPSource(Source):
connection_kwargs.setdefault("user", self.bind_cn) connection_kwargs.setdefault("user", self.bind_cn)
if self.bind_password is not None: if self.bind_password is not None:
connection_kwargs.setdefault("password", self.bind_password) connection_kwargs.setdefault("password", self.bind_password)
connection = Connection( conn = Connection(
server or self.server(**server_kwargs), server or self.server(**server_kwargs),
raise_exceptions=True, raise_exceptions=True,
receive_timeout=LDAP_TIMEOUT, receive_timeout=LDAP_TIMEOUT,
@ -178,11 +178,11 @@ class LDAPSource(Source):
) )
if self.start_tls: if self.start_tls:
connection.start_tls(read_server_info=False) conn.start_tls(read_server_info=False)
try: try:
successful = connection.bind() successful = conn.bind()
if successful: if successful:
return connection return conn
except (LDAPSchemaError, LDAPInsufficientAccessRightsResult) as exc: except (LDAPSchemaError, LDAPInsufficientAccessRightsResult) as exc:
# Schema error, so try connecting without schema info # Schema error, so try connecting without schema info
# See https://github.com/goauthentik/authentik/issues/4590 # See https://github.com/goauthentik/authentik/issues/4590
@ -192,10 +192,10 @@ class LDAPSource(Source):
server_kwargs["get_info"] = NONE server_kwargs["get_info"] = NONE
return self.connection(server, server_kwargs, connection_kwargs) return self.connection(server, server_kwargs, connection_kwargs)
finally: finally:
if connection.server.tls.certificate_file is not None and exists( if conn.server.tls.certificate_file is not None and exists(
connection.server.tls.certificate_file conn.server.tls.certificate_file
): ):
rmtree(dirname(connection.server.tls.certificate_file)) rmtree(dirname(conn.server.tls.certificate_file))
return RuntimeError("Failed to bind") return RuntimeError("Failed to bind")
@property @property
@ -220,10 +220,10 @@ class LDAPSource(Source):
for server in servers.servers: for server in servers.servers:
server: Server server: Server
try: try:
connection = self.connection(server=server) conn = self.connection(server=server)
server_info[server.host] = { server_info[server.host] = {
"vendor": str(flatten(connection.server.info.vendor_name)), "vendor": str(flatten(conn.server.info.vendor_name)),
"version": str(flatten(connection.server.info.vendor_version)), "version": str(flatten(conn.server.info.vendor_version)),
"status": "ok", "status": "ok",
} }
except LDAPException as exc: except LDAPException as exc:
@ -232,10 +232,10 @@ class LDAPSource(Source):
} }
# Check server pool # Check server pool
try: try:
connection = self.connection() conn = self.connection()
server_info["__all__"] = { server_info["__all__"] = {
"vendor": str(flatten(connection.server.info.vendor_name)), "vendor": str(flatten(conn.server.info.vendor_name)),
"version": str(flatten(connection.server.info.vendor_version)), "version": str(flatten(conn.server.info.vendor_version)),
"status": "ok", "status": "ok",
} }
except LDAPException as exc: except LDAPException as exc: