From 9e70b39400f8724871ef7326e05fde7c5fe57b39 Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 26 Aug 2024 13:54:13 +0200 Subject: [PATCH] SEBSERV-574 --- .../MonitoringProctoringService.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/proctoring/MonitoringProctoringService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/proctoring/MonitoringProctoringService.java index 199dd158..37e36625 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/proctoring/MonitoringProctoringService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/proctoring/MonitoringProctoringService.java @@ -30,6 +30,7 @@ import org.springframework.context.annotation.Lazy; import org.springframework.core.io.Resource; import org.springframework.http.*; import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.core.type.TypeReference; @@ -351,12 +352,7 @@ public class MonitoringProctoringService { if (tokenRequest.getStatusCode() == HttpStatus.UNAUTHORIZED && currentUser.get().hasAnyRole(UserRole.EXAM_SUPPORTER, UserRole.INSTITUTIONAL_ADMIN)) { - log.warn("No Access to Screen Proctoring for user: {}", currentUser.get().username); - _action - .pageContext() - .notifyError( - new LocTextKey("sebserver.monitoring.sps.noaccess"), - new RuntimeException("Please make sure you are assigned as supporter for this Exam")); + notifyUnauthorized(_action, currentUser); return _action; } @@ -369,6 +365,12 @@ public class MonitoringProctoringService { // .getService(JavaScriptExecutor.class) // .execute(script); } catch (final Exception e) { + if (e instanceof HttpClientErrorException) { + if (((HttpClientErrorException) e).getRawStatusCode() == HttpStatus.UNAUTHORIZED.value()) { + notifyUnauthorized(_action, this.pageService.getCurrentUser()); + return _action; + } + } log.error("Failed to open screen proctoring service group gallery view: ", e); _action.pageContext() .notifyError(new LocTextKey("sebserver.monitoring.sps.opengallery.fail"), e); @@ -376,6 +378,15 @@ public class MonitoringProctoringService { return _action; } + private static void notifyUnauthorized(final PageAction _action, final CurrentUser currentUser) { + log.warn("No Access to Screen Proctoring for user: {}", currentUser.get().username); + _action + .pageContext() + .notifyError( + new LocTextKey("sebserver.monitoring.sps.noaccess"), + new RuntimeException("Please make sure you are assigned as supporter for this Exam")); + } + private PageAction openExamProctoringRoom( final ProctoringGUIService proctoringGUIService, final ProctoringServiceSettings proctoringSettings,