ldap: Tweak AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL behavior.

The original behavior of this setting was to disable LDAP
authentication for any realms not configured to use it. This was an
arbitrary choice, and its only value was to potentially help catch
typos for users who are lazy about testing their configuration.

Since it makes it a very inconvenient to potentially host multiple
organizations with different LDAP configurations, remove that
behavior.
This commit is contained in:
Mateusz Mandera
2023-10-08 22:53:54 +02:00
committed by Tim Abbott
parent cc934429fe
commit 1800b2c797
4 changed files with 22 additions and 14 deletions

View File

@@ -843,17 +843,18 @@ class ZulipLDAPAuthBackendBase(ZulipAuthMixin, LDAPBackend):
# If neither setting is configured, allow access.
if realm_access_control is None:
return False
if realm.subdomain not in realm_access_control:
# If a realm is not configured in this setting, it shouldn't
# be affected by it - therefore, allow access.
return False
# With settings.AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL, we
# allow access if and only if one of the entries for the
# target subdomain matches the user's LDAP attributes.
if not (
realm.subdomain in realm_access_control
and isinstance(realm_access_control[realm.subdomain], list)
and len(realm_access_control[realm.subdomain]) > 0
):
# If configuration is wrong, do not allow access
return True
# Make sure the format of the setting makes sense.
assert isinstance(realm_access_control[realm.subdomain], list)
assert len(realm_access_control[realm.subdomain]) > 0
# Go through every "or" check
for attribute_group in realm_access_control[realm.subdomain]: