From e4e4cff9e69454a377a62c1334591a161824d4e3 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Tue, 22 Feb 2022 17:26:21 +0100 Subject: [PATCH] Return Http403 if the home directory is not parsable instead of creating an error 500 --- shared/auth/backends.py | 7 +++++++ 1 file changed, 7 insertions(+) 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"""