I am using django-auth-ldap to connect to an LDAP server for authentication. django-auth-ldap provides the setting AUTH_LDAP_REQUIRE_GROUP
, which can be used to allow access only for users placed in a specific group. This works fine, but the option only allows to check one group; I want to check if a users is placed in either one or another group.
In the module django_auth_ldap/backend.py
I could modify the method _check_required_groups
of the class LDAPUser(object)
to implement this behaviour. Modifying it directly works fine, but since changing the source would endup in a maintenance hell, I am searching for a solution to change this method without touching the source. Two ideas I had:
1) Monkey Patching
Change the _check_required_groups
method of an instance of the LDAPUser
class. The problem is that I have no idea where it is beeing instantiated. I am just using LDAPSearch
and GroupOfNamesType
imported from django_auth_ldap.config
in the settings file, and passing the string django_auth_ldap.backend.LDAPBackend
into the AUTHENTICATION_BACKENDS
tuple.
2) Extending the module
Create an own module, extending the original django_auth_ldap
and using this instead of the original. I tried to create a new directory, adding an __init__.py
with the line:
from django_auth_ldap import *
But using this module does not work, since it can't import custom_auth.config
.
Any other suggestions or hints how to make one of those attempts to work?