From 08dfaeb436834b2c8338328a8344fbd8629c9f70 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 24 Jun 2024 01:15:40 +0200 Subject: [PATCH] =?UTF-8?q?Evite=20de=20rediriger=20vers=20login=20si=20us?= =?UTF-8?q?er=20CAS=20d=C3=A9j=C3=A0=20reconnu=20et=20CAS=20forc=C3=A9:=20?= =?UTF-8?q?fix=20#757?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/auth/cas.py | 19 +++++++++++++------ sco_version.py | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/auth/cas.py b/app/auth/cas.py index 3b9f14e47..268611469 100644 --- a/app/auth/cas.py +++ b/app/auth/cas.py @@ -35,9 +35,9 @@ def after_cas_login(): if user.cas_allow_login: current_app.logger.info(f"CAS: login {user.user_name}") if login_user(user): - flask.session[ - "scodoc_cas_login_date" - ] = datetime.datetime.now().isoformat() + flask.session["scodoc_cas_login_date"] = ( + datetime.datetime.now().isoformat() + ) user.cas_last_login = datetime.datetime.utcnow() if flask.session.get("CAS_EDT_ID"): # essaie de récupérer l'edt_id s'il est présent @@ -45,8 +45,10 @@ def after_cas_login(): # via l'expression `cas_edt_id_from_xml_regexp` # voir flask_cas.routing edt_id = flask.session.get("CAS_EDT_ID") - current_app.logger.info(f"""after_cas_login: storing edt_id for { - user.user_name}: '{edt_id}'""") + current_app.logger.info( + f"""after_cas_login: storing edt_id for { + user.user_name}: '{edt_id}'""" + ) user.edt_id = edt_id db.session.add(user) db.session.commit() @@ -55,12 +57,17 @@ def after_cas_login(): current_app.logger.info( f"CAS login denied for {user.user_name} (not allowed to use CAS)" ) - else: + else: # pas d'utilisateur ScoDoc ou bien compte inactif current_app.logger.info( f"""CAS login denied for { user.user_name if user else "" } cas_id={cas_id} (unknown or inactive)""" ) + if ScoDocSiteConfig.is_cas_forced(): + # Dans ce cas, pas de redirect vers la page de login pour éviter de boucler + raise ScoValueError( + "compte ScoDoc inexistant ou inactif pour cet utilisateur CAS" + ) else: current_app.logger.info( f"""CAS attribute '{ScoDocSiteConfig.get("cas_attribute_id")}' not found ! diff --git a/sco_version.py b/sco_version.py index 336790981..0b5fefee9 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.6.980" +SCOVERSION = "9.6.981" SCONAME = "ScoDoc"