From a33c7c0ff9a14db4f9cc9684ad5d365c1588768c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Wed, 21 Apr 2021 19:53:52 +0200 Subject: [PATCH] SEBWIN-483: Implemented generic method to retrieve LMS session identifier. --- .../Handlers/ResourceHandler.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/SafeExamBrowser.Browser/Handlers/ResourceHandler.cs b/SafeExamBrowser.Browser/Handlers/ResourceHandler.cs index 48f3475e..930a71c1 100644 --- a/SafeExamBrowser.Browser/Handlers/ResourceHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/ResourceHandler.cs @@ -246,8 +246,33 @@ namespace SafeExamBrowser.Browser.Handlers private void SearchSessionIdentifiers(IRequest request, IResponse response) { - SearchEdxIdentifier(response); - SearchMoodleIdentifier(request, response); + var success = TrySearchGenericSessionIdentifier(response); + + if (!success) + { + SearchEdxIdentifier(response); + SearchMoodleIdentifier(request, response); + } + } + + private bool TrySearchGenericSessionIdentifier(IResponse response) + { + var ids = response.Headers.GetValues("X-LMS-USER-ID"); + + if (ids != default(string[])) + { + var userId = ids.FirstOrDefault(); + + if (userId != default(string)) + { + Task.Run(() => SessionIdentifierDetected?.Invoke(userId)); + logger.Info("Generic LMS session detected."); + + return true; + } + } + + return false; } private void SearchEdxIdentifier(IResponse response)