|
2 | 2 | from os import environ
|
3 | 3 |
|
4 | 4 | import ldap
|
5 |
| -from django_auth_ldap.config import LDAPSearch |
| 5 | +from django_auth_ldap.config import LDAPGroupQuery, LDAPSearch |
6 | 6 |
|
7 | 7 |
|
8 | 8 | # Read secret from file
|
@@ -86,12 +86,22 @@ def _import_group_type(group_type_name):
|
86 | 86 | # Define a group required to login.
|
87 | 87 | AUTH_LDAP_REQUIRE_GROUP = environ.get('AUTH_LDAP_REQUIRE_GROUP_DN')
|
88 | 88 |
|
| 89 | +# If non-empty string, AUTH_LDAP_REQUIRE_GROUP will be treated as a list delimited by this separator |
| 90 | +AUTH_LDAP_REQUIRE_GROUP_SEPARATOR = environ.get('AUTH_LDAP_REQUIRE_GROUP_DN_SEPARATOR', '') |
| 91 | + |
89 | 92 | # Define special user types using groups. Exercise great caution when assigning superuser status.
|
90 | 93 | AUTH_LDAP_USER_FLAGS_BY_GROUP = {}
|
91 | 94 |
|
92 | 95 | if AUTH_LDAP_REQUIRE_GROUP is not None:
|
| 96 | + # Build an LDAPGroupQuery when AUTH_LDAP_REQUIRE_GROUP should be treated as a list |
| 97 | + if AUTH_LDAP_REQUIRE_GROUP_SEPARATOR: |
| 98 | + _groups = list(filter(None, AUTH_LDAP_REQUIRE_GROUP.split(AUTH_LDAP_REQUIRE_GROUP_SEPARATOR))) |
| 99 | + AUTH_LDAP_REQUIRE_GROUP = LDAPGroupQuery(_groups[0]) |
| 100 | + for i in range(1, len(_groups)): |
| 101 | + AUTH_LDAP_REQUIRE_GROUP |= LDAPGroupQuery(_groups[i]) |
| 102 | + |
93 | 103 | AUTH_LDAP_USER_FLAGS_BY_GROUP = {
|
94 |
| - "is_active": environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', ''), |
| 104 | + "is_active": AUTH_LDAP_REQUIRE_GROUP, |
95 | 105 | "is_staff": environ.get('AUTH_LDAP_IS_ADMIN_DN', ''),
|
96 | 106 | "is_superuser": environ.get('AUTH_LDAP_IS_SUPERUSER_DN', '')
|
97 | 107 | }
|
|
0 commit comments