diff --git a/shared/auth/backends.py b/shared/auth/backends.py index 9be8c7a..8ad1c4d 100644 --- a/shared/auth/backends.py +++ b/shared/auth/backends.py @@ -2,6 +2,7 @@ from authens.backends import ENSCASBackend from django.contrib.auth import get_user_model from django.contrib.auth.backends import ModelBackend +from django.core.exceptions import PermissionDenied User = get_user_model() @@ -18,6 +19,12 @@ class CASBackend(ENSCASBackend): return User.objects.create_user(username=username, email=email, full_name=name) + def _get_or_create(self, cas_login, attributes): + try: + return super()._get_or_create(cas_login, attributes) + except ValueError: + raise PermissionDenied + class PwdBackend(ModelBackend): """Password authentication"""