Skip to content

Commit

Permalink
ldap fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Arcuri committed May 16, 2024
1 parent 5c4b00a commit b2f77ea
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,12 @@
"guardian.backends.ObjectPermissionBackend",
]


if use_ldap := env.bool("USE_LDAP", False):
AUTHENTICATION_BACKENDS = [
"django_auth_ldap.backend.LDAPBackend"
"django.contrib.auth.backends.ModelBackend",
"guardian.backends.ObjectPermissionBackend",
]
else:
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
"guardian.backends.ObjectPermissionBackend",
]
AUTHENTICATION_BACKENDS = [
"django_auth_ldap.backend.LDAPBackend",
"django.contrib.auth.backends.ModelBackend",
"guardian.backends.ObjectPermissionBackend",
"allauth.account.auth_backends.AuthenticationBackend",
]

AUTH_USER_MODEL = "users.User"
LOGIN_REDIRECT_URL = "users:redirect"
Expand Down Expand Up @@ -248,15 +241,16 @@
"root": {"level": DEBUG_LEVEL, "handlers": ["console"]},
"loggers": {
"distributed": {"level": DEBUG_LEVEL, "handlers": ["console"]},
"django_auth_ldap": {"level": DEBUG_LEVEL, "handlers": ["console"]},
},
}

# django-allauth
# ------------------------------------------------------------------------------
ACCOUNT_ALLOW_REGISTRATION = env.bool("DJANGO_ACCOUNT_ALLOW_REGISTRATION", True)
ACCOUNT_AUTHENTICATION_METHOD = "username"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = "optional"
ACCOUNT_ADAPTER = "orochi.users.adapters.AccountAdapter"
SOCIALACCOUNT_ADAPTER = "orochi.users.adapters.SocialAccountAdapter"

Expand Down Expand Up @@ -285,16 +279,15 @@

# LDAP
# ------------------------------------------------------------------------------
if use_ldap:
AUTH_LDAP_SERVER_URI = env("AUTH_LDAP_SERVER_URI")
AUTH_LDAP_BIND_DN = env("AUTH_LDAP_BIND_DN")
AUTH_LDAP_BIND_PASSWORD = env("AUTH_LDAP_BIND_PASSWORD")
AUTH_LDAP_USER_SEARCH = LDAPSearch(
env("AUTH_LDAP_USER_SEARCH_DN"),
ldap.SCOPE_SUBTREE,
env("AUTH_LDAP_USER_SEARCH_ALIAS"),
)
AUTH_LDAP_USER_ATTR_MAP = env.dict("AUTH_LDAP_USER_ATTR_MAP")
AUTH_LDAP_SERVER_URI = env("AUTH_LDAP_SERVER_URI")
AUTH_LDAP_BIND_DN = env("AUTH_LDAP_BIND_DN")
AUTH_LDAP_BIND_PASSWORD = env("AUTH_LDAP_BIND_PASSWORD")
AUTH_LDAP_USER_SEARCH = LDAPSearch(
env("AUTH_LDAP_USER_SEARCH_DN"),
ldap.SCOPE_SUBTREE,
env("AUTH_LDAP_USER_SEARCH_ALIAS"),
)
AUTH_LDAP_USER_ATTR_MAP = env.dict("AUTH_LDAP_USER_ATTR_MAP")

# REST FRAMEWORK
# -------------------------------------------------------------------------------
Expand Down

0 comments on commit b2f77ea

Please sign in to comment.