SEBWIN-782, #703: Ensured browser session remains active after reconfiguration by browser resource.

This commit is contained in:
Damian Büchel 2024-05-24 15:46:01 +02:00
parent 3b099688f7
commit b3228aedef
2 changed files with 26 additions and 9 deletions

View file

@ -26,6 +26,11 @@ namespace SafeExamBrowser.Configuration.Contracts
/// </summary> /// </summary>
public Guid ClientAuthenticationToken { get; set; } public Guid ClientAuthenticationToken { get; set; }
/// <summary>
/// Indicates whether a configuration resource needs to be loaded in the browser because it requires authentication or is a webpage.
/// </summary>
public bool IsBrowserResource { get; set; }
/// <summary> /// <summary>
/// The unique session identifier. /// The unique session identifier.
/// </summary> /// </summary>

View file

@ -164,13 +164,18 @@ namespace SafeExamBrowser.Runtime.Operations
result = OperationResult.Aborted; result = OperationResult.Aborted;
} }
if (result == OperationResult.Success && Context.Current.IsBrowserResource)
{
HandleReconfigurationByBrowserResource();
}
fileSystem.Delete(uri.LocalPath); fileSystem.Delete(uri.LocalPath);
logger.Info($"Deleted temporary configuration file '{uri}'."); logger.Info($"Deleted temporary configuration file '{uri}'.");
return result; return result;
} }
private OperationResult DetermineLoadResult(Uri uri, UriSource source, AppSettings settings, LoadStatus status, PasswordParameters passwordParams, string currentPassword = default(string)) private OperationResult DetermineLoadResult(Uri uri, UriSource source, AppSettings settings, LoadStatus status, PasswordParameters passwordParams, string currentPassword = default)
{ {
var result = OperationResult.Failed; var result = OperationResult.Failed;
@ -205,6 +210,7 @@ namespace SafeExamBrowser.Runtime.Operations
private OperationResult HandleBrowserResource(Uri uri) private OperationResult HandleBrowserResource(Uri uri)
{ {
Context.Next.IsBrowserResource = true;
Context.Next.Settings.Applications.Blacklist.Clear(); Context.Next.Settings.Applications.Blacklist.Clear();
Context.Next.Settings.Applications.Whitelist.Clear(); Context.Next.Settings.Applications.Whitelist.Clear();
Context.Next.Settings.Display.AllowedDisplays = 10; Context.Next.Settings.Display.AllowedDisplays = 10;
@ -222,7 +228,7 @@ namespace SafeExamBrowser.Runtime.Operations
return OperationResult.Success; return OperationResult.Success;
} }
private OperationResult HandleClientConfiguration(Uri uri, PasswordParameters passwordParams, string currentPassword = default(string)) private OperationResult HandleClientConfiguration(Uri uri, PasswordParameters passwordParams, string currentPassword = default)
{ {
var isFirstSession = Context.Current == null; var isFirstSession = Context.Current == null;
var success = TryConfigureClient(uri, passwordParams, currentPassword); var success = TryConfigureClient(uri, passwordParams, currentPassword);
@ -240,6 +246,12 @@ namespace SafeExamBrowser.Runtime.Operations
return result; return result;
} }
private void HandleReconfigurationByBrowserResource()
{
Context.Next.Settings.Browser.DeleteCookiesOnStartup = false;
logger.Info("Some browser settings were overridden in order to retain a potential LMS / web application session.");
}
private void HandleStartUrlQuery(Uri uri, UriSource source) private void HandleStartUrlQuery(Uri uri, UriSource source)
{ {
if (source == UriSource.Reconfiguration && Uri.TryCreate(Context.ReconfigurationUrl, UriKind.Absolute, out var reconfigurationUri)) if (source == UriSource.Reconfiguration && Uri.TryCreate(Context.ReconfigurationUrl, UriKind.Absolute, out var reconfigurationUri))
@ -247,13 +259,13 @@ namespace SafeExamBrowser.Runtime.Operations
uri = reconfigurationUri; uri = reconfigurationUri;
} }
if (uri != default(Uri) && uri.Query.LastIndexOf('?') > 0) if (uri != default && uri.Query.LastIndexOf('?') > 0)
{ {
Context.Next.Settings.Browser.StartUrlQuery = uri.Query.Substring(uri.Query.LastIndexOf('?')); Context.Next.Settings.Browser.StartUrlQuery = uri.Query.Substring(uri.Query.LastIndexOf('?'));
} }
} }
private bool? TryConfigureClient(Uri uri, PasswordParameters passwordParams, string currentPassword = default(string)) private bool? TryConfigureClient(Uri uri, PasswordParameters passwordParams, string currentPassword = default)
{ {
var mustAuthenticate = IsRequiredToAuthenticateForClientConfiguration(passwordParams, currentPassword); var mustAuthenticate = IsRequiredToAuthenticateForClientConfiguration(passwordParams, currentPassword);
@ -304,9 +316,9 @@ namespace SafeExamBrowser.Runtime.Operations
return success; return success;
} }
private bool IsRequiredToAuthenticateForClientConfiguration(PasswordParameters passwordParams, string currentPassword = default(string)) private bool IsRequiredToAuthenticateForClientConfiguration(PasswordParameters passwordParams, string currentPassword = default)
{ {
var mustAuthenticate = currentPassword != default(string); var mustAuthenticate = currentPassword != default;
if (mustAuthenticate) if (mustAuthenticate)
{ {
@ -334,7 +346,7 @@ namespace SafeExamBrowser.Runtime.Operations
{ {
var authenticated = false; var authenticated = false;
for (int attempts = 0; attempts < 5 && !authenticated; attempts++) for (var attempts = 0; attempts < 5 && !authenticated; attempts++)
{ {
var success = TryGetPassword(PasswordRequestPurpose.LocalAdministrator, out var password); var success = TryGetPassword(PasswordRequestPurpose.LocalAdministrator, out var password);
@ -384,8 +396,8 @@ namespace SafeExamBrowser.Runtime.Operations
{ {
var isValidUri = false; var isValidUri = false;
uri = null; uri = default;
source = default(UriSource); source = default;
if (commandLineArgs?.Length > 1) if (commandLineArgs?.Length > 1)
{ {