From 41752ac34496983ffd31525588fc211a7992131b Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Wed, 12 May 2021 01:36:24 +0200 Subject: [PATCH] =?UTF-8?q?Rajoute=20un=20param=C3=A8tre=20pour=20d=C3=A9s?= =?UTF-8?q?activer=20le=20LDAP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- authens/conf.py | 1 + authens/shortcuts.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/authens/conf.py b/authens/conf.py index 732b984..46867b8 100644 --- a/authens/conf.py +++ b/authens/conf.py @@ -1,4 +1,5 @@ LDAP_SERVER_URL = "ldaps://ldap.spi.ens.fr:636" AUTHENS_USE_OLDCAS = True AUTHENS_USE_PASSWORD = True +USE_LDAP = True # TODO: CAS_SERVER_URL diff --git a/authens/shortcuts.py b/authens/shortcuts.py index 2bed72b..cd544ba 100644 --- a/authens/shortcuts.py +++ b/authens/shortcuts.py @@ -1,7 +1,10 @@ """Helper functions to get CAS metadata and create CAS accounts.""" +import warnings + # TODO: make the python-ldap dependency optional import ldap + from django.conf import settings from django.contrib.auth import get_user_model @@ -24,6 +27,10 @@ def fetch_cas_account(cas_login): if not cas_login.isalnum(): raise ValueError("Illegal CAS login: {}".format(cas_login)) + if not getattr(settings, "USE_LDAP", default_conf.USE_LDAP): + warnings.warn("Use of LDAP is disabled", RuntimeWarning) + return None + ldap_url = getattr(settings, "LDAP_SERVER_URL", default_conf.LDAP_SERVER_URL) ldap_obj = ldap.initialize(ldap_url) res = ldap_obj.search_s(