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(