From b5f4f61308a5e54428e453b97f0b4d02bfa5f413 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 10 Dec 2024 16:32:54 +0100 Subject: [PATCH] logging for Moodle autologin --- ...InstitutionalAuthenticationEntryPoint.java | 20 +--- .../seb/sebserver/gui/ProctoringServlet.java | 103 ------------------ .../seb/sebserver/gui/RAPConfiguration.java | 67 +++++------- .../seb/sebserver/gui/RAPSpringConfig.java | 12 -- .../monitoring/MonitoringRunningExam.java | 7 ++ src/main/resources/messages.properties | 2 +- 6 files changed, 41 insertions(+), 170 deletions(-) delete mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/ProctoringServlet.java diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/InstitutionalAuthenticationEntryPoint.java b/src/main/java/ch/ethz/seb/sebserver/gui/InstitutionalAuthenticationEntryPoint.java index 48a3e53a3..2ce0463f4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/InstitutionalAuthenticationEntryPoint.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/InstitutionalAuthenticationEntryPoint.java @@ -21,7 +21,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.AuthorizationContextHolder; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.SEBServerAuthorizationContext; @@ -67,21 +66,19 @@ public final class InstitutionalAuthenticationEntryPoint implements Authenticati private final String guiEntryPoint; - private final String remoteProctoringEndpoint; + private final String defaultLogo; private final WebserviceURIService webserviceURIService; private final ClientHttpRequestFactoryService clientHttpRequestFactoryService; - protected InstitutionalAuthenticationEntryPoint( + public InstitutionalAuthenticationEntryPoint( @Value("${sebserver.gui.entrypoint}") final String guiEntryPoint, - @Value("${sebserver.gui.remote.proctoring.entrypoint:/remote-proctoring}") final String remoteProctoringEndpoint, @Value("${sebserver.gui.defaultLogo:" + Constants.NO_NAME + "}") final String defaultLogoFileName, final WebserviceURIService webserviceURIService, final ClientHttpRequestFactoryService clientHttpRequestFactoryService, final ResourceLoader resourceLoader) { this.guiEntryPoint = guiEntryPoint; - this.remoteProctoringEndpoint = remoteProctoringEndpoint; this.webserviceURIService = webserviceURIService; this.clientHttpRequestFactoryService = clientHttpRequestFactoryService; @@ -139,7 +136,7 @@ public void commence( if (authorizationContext.autoLogin(jwt)) { log.info("Autologin successful, redirect to: {}", this.guiEntryPoint); - forwardToEntryPoint(request, response, this.guiEntryPoint, true); + forwardToEntryPoint(request, response, /* this.guiEntryPoint */ "/", true); return; } } @@ -209,17 +206,6 @@ private void forwardToEntryPoint( final String entryPoint, final boolean redirect) throws ServletException, IOException { - final String requestURI = request.getRequestURI(); - if (requestURI.startsWith(this.remoteProctoringEndpoint)) { - - final RequestDispatcher dispatcher = request - .getServletContext() - .getRequestDispatcher(this.remoteProctoringEndpoint); - - dispatcher.forward(request, response); - return; - } - if (redirect) { response.sendRedirect(entryPoint); } else { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/ProctoringServlet.java b/src/main/java/ch/ethz/seb/sebserver/gui/ProctoringServlet.java deleted file mode 100644 index 2725013fc..000000000 --- a/src/main/java/ch/ethz/seb/sebserver/gui/ProctoringServlet.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2020 ETH Zürich, IT Services - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package ch.ethz.seb.sebserver.gui; - -import java.io.IOException; -import java.util.Collection; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; - -import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.AuthorizationContextHolder; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.SEBServerAuthorizationContext; -import ch.ethz.seb.sebserver.gui.service.session.proctoring.ProctoringGUIService; -import ch.ethz.seb.sebserver.gui.service.session.proctoring.ProctoringGUIService.ProctoringWindowData; -import ch.ethz.seb.sebserver.gui.service.session.proctoring.ProctoringWindowScriptResolver; - -@Component -@GuiProfile -public class ProctoringServlet extends HttpServlet { - - private static final long serialVersionUID = 3475978419653411800L; - private static final Logger log = LoggerFactory.getLogger(ProctoringServlet.class); - - private final Collection proctoringWindowScriptResolver; - - public ProctoringServlet( - final Collection proctoringWindowScriptResolver) { - - this.proctoringWindowScriptResolver = proctoringWindowScriptResolver; - } - - @Override - protected void doGet( - final HttpServletRequest req, - final HttpServletResponse resp) - throws ServletException, IOException { - - final HttpSession httpSession = req.getSession(); - final ServletContext servletContext = httpSession.getServletContext(); - final WebApplicationContext webApplicationContext = WebApplicationContextUtils - .getRequiredWebApplicationContext(servletContext); - - final boolean authenticated = isAuthenticated(httpSession, webApplicationContext); - if (!authenticated) { - resp.setStatus(HttpStatus.FORBIDDEN.value()); - return; - } - - final ProctoringWindowData proctoringData = - (ProctoringWindowData) httpSession - .getAttribute(ProctoringGUIService.SESSION_ATTR_PROCTORING_DATA); - - final String script = this.proctoringWindowScriptResolver.stream() - .filter(resolver -> resolver.applies(proctoringData)) - .findFirst() - .map(resolver -> resolver.getProctoringWindowScript(proctoringData)) - .orElse(null); - - if (script == null) { - log.error("Failed to get proctoring window script for data: {}", proctoringData); - resp.getOutputStream().println("Failed to get proctoring window script"); - } else { - resp.getOutputStream().println(script); - } - } - - @Override - protected void doOptions(final HttpServletRequest req, final HttpServletResponse resp) - throws ServletException, IOException { - - resp.setStatus(HttpServletResponse.SC_OK); - } - - private boolean isAuthenticated( - final HttpSession httpSession, - final WebApplicationContext webApplicationContext) { - - final AuthorizationContextHolder authorizationContextHolder = webApplicationContext - .getBean(AuthorizationContextHolder.class); - final SEBServerAuthorizationContext authorizationContext = authorizationContextHolder - .getAuthorizationContext(httpSession); - return authorizationContext.isValid() && authorizationContext.isLoggedIn(); - } - -} \ No newline at end of file diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java b/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java index f04967ce8..dfd6c5da2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java @@ -79,13 +79,6 @@ public InputStream getResourceAsStream(final String resourceName) throws IOExcep application.addEntryPoint(guiEntrypoint, new RAPSpringEntryPointFactory(), properties); - properties.put(WebClient.PAGE_TITLE, "SEB Server Proctoring"); - properties.put(WebClient.BODY_HTML, "Loading Application"); - properties.put(WebClient.THEME_ID, DEFAULT_THEME_NAME); - properties.put(WebClient.FAVICON, "fav_icon"); - - application.addEntryPoint(proctoringEntrypoint, new RAPRemoteProcotringEntryPointFactory(), properties); - } catch (final RuntimeException re) { throw re; } catch (final Exception e) { @@ -103,36 +96,36 @@ public interface EntryPointService { } - public static final class RAPRemoteProcotringEntryPointFactory implements EntryPointFactory { - - @Override - public EntryPoint create() { - return new AbstractEntryPoint() { - - private static final long serialVersionUID = -1299125117752916270L; - - @Override - protected void createContents(final Composite parent) { - - final HttpSession httpSession = RWT - .getUISession(parent.getDisplay()) - .getHttpSession(); - - final WebApplicationContext webApplicationContext = getWebApplicationContext(httpSession); - final boolean authenticated = isAuthenticated(httpSession, webApplicationContext); - if (authenticated) { - - final EntryPointService entryPointService = webApplicationContext - .getBean(EntryPointService.class); - entryPointService.loadProctoringView(parent); - } else { - final HttpServletResponse response = RWT.getResponse(); - response.setStatus(HttpStatus.FORBIDDEN.value()); - } - } - }; - } - } +// public static final class RAPRemoteProcotringEntryPointFactory implements EntryPointFactory { +// +// @Override +// public EntryPoint create() { +// return new AbstractEntryPoint() { +// +// private static final long serialVersionUID = -1299125117752916270L; +// +// @Override +// protected void createContents(final Composite parent) { +// +// final HttpSession httpSession = RWT +// .getUISession(parent.getDisplay()) +// .getHttpSession(); +// +// final WebApplicationContext webApplicationContext = getWebApplicationContext(httpSession); +// final boolean authenticated = isAuthenticated(httpSession, webApplicationContext); +// if (authenticated) { +// +// final EntryPointService entryPointService = webApplicationContext +// .getBean(EntryPointService.class); +// entryPointService.loadProctoringView(parent); +// } else { +// final HttpServletResponse response = RWT.getResponse(); +// response.setStatus(HttpStatus.FORBIDDEN.value()); +// } +// } +// }; +// } +// } public static final class RAPSpringEntryPointFactory implements EntryPointFactory { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/RAPSpringConfig.java b/src/main/java/ch/ethz/seb/sebserver/gui/RAPSpringConfig.java index 295dc5d1e..d868a42c9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/RAPSpringConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/RAPSpringConfig.java @@ -19,7 +19,6 @@ import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; -import org.springframework.context.ApplicationContext; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -72,17 +71,6 @@ public ServletRegistrationBean servletRegistrationBean() { this.remoteProctoringEndpoint + "/*"); } - @Bean - public ServletRegistrationBean servletProctoringRegistrationBean( - final ApplicationContext applicationContext) { - - final ProctoringServlet proctoringServlet = applicationContext - .getBean(ProctoringServlet.class); - return new ServletRegistrationBean<>( - proctoringServlet, - this.remoteProctoringEndpoint + this.remoteProctoringViewServletEndpoint + "/*"); - } - @Bean public MessageSource messageSource() { final ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource = diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/MonitoringRunningExam.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/MonitoringRunningExam.java index 784419b2e..0b2b2535f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/MonitoringRunningExam.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/MonitoringRunningExam.java @@ -104,6 +104,8 @@ public class MonitoringRunningExam implements TemplateComposer { new LocTextKey("sebserver.monitoring.exam.connection.action.closeTownhall.confirm"); private static final LocTextKey CONFIRM_DISABLE_SELECTED = new LocTextKey("sebserver.monitoring.exam.connection.action.instruction.disable.selected.confirm"); + private static final LocTextKey NOT_RUNNING_MESSAGE = + new LocTextKey("sebserver.monitoring.exam.notrunning.message"); private final ServerPushService serverPushService; private final PageService pageService; @@ -174,6 +176,11 @@ public void compose(final PageContext pageContext) { new LocTextKey( "sebserver.monitoring.exam", StringEscapeUtils.escapeXml11(exam.name))); + + if (exam.status != Exam.ExamStatus.RUNNING) { + pageContext.publishInfo(NOT_RUNNING_MESSAGE); + return; + } final Composite tablePane = new Composite(content, SWT.NONE); tablePane.setLayout(new GridLayout()); diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index d82ae7409..1ea2c0901 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -2281,7 +2281,7 @@ sebserver.exam.overall.action.category.proctoring=Live Proctoring sebserver.monitoring.exam.action.proctoring.openTownhall=Open Townhall sebserver.monitoring.exam.action.proctoring.showTownhall=Show Townhall sebserver.monitoring.exam.action.proctoring.closeTownhall=Close Townhall - +sebserver.monitoring.exam.notrunning.message=This Exam is not running (anymore)! sebserver.exam.overall.action.category.screenproctoring=Screen Proctoring sebserver.monitoring.exam.proctoring.room.all.name=Townhall Room