From b1727f7e07c399990602ee52051cc72ff8890531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Sat, 14 Oct 2017 16:57:59 +0200 Subject: [PATCH] Clean a CAS-returned username cas.eleves.ens.fr allows users such as ' FooBAr ' or 'foobar' in indifferently --- bocal/settings_base.py | 2 +- mainsite/cas_backend.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 mainsite/cas_backend.py diff --git a/bocal/settings_base.py b/bocal/settings_base.py index a5f217c..22ff30a 100644 --- a/bocal/settings_base.py +++ b/bocal/settings_base.py @@ -87,7 +87,7 @@ AUTH_PASSWORD_VALIDATORS = [ AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.ModelBackend', - 'django_cas_ng.backends.CASBackend', + 'mainsite.cas_backend.BOcalCASBackend', ] CAS_ADMIN_PREFIX = '/yaes5eiS' # we don't want CAS to take over /admin auth diff --git a/mainsite/cas_backend.py b/mainsite/cas_backend.py new file mode 100644 index 0000000..a9abe05 --- /dev/null +++ b/mainsite/cas_backend.py @@ -0,0 +1,7 @@ +from django_cas_ng.backends import CASBackend + + +class BOcalCASBackend(CASBackend): + # Partly from Robin Champenois's "ExperiENS". Thanks! + def clean_username(self, username): + return username.lower().strip()