SEBWIN-405: Implemented server settings and data mapping.

This commit is contained in:
Damian Büchel 2020-07-01 13:39:17 +02:00
parent 0911e23714
commit 261a331634
12 changed files with 268 additions and 3 deletions

View file

@ -331,7 +331,7 @@ namespace SafeExamBrowser.Configuration.UnitTests
}
/// <summary>
/// Hack required for unit tests to be able to retrieve the <see cref="Assembly.GetEntryAssembly"/> while executing.
/// Required for unit tests to be able to retrieve the <see cref="Assembly.GetEntryAssembly"/> while executing.
/// </summary>
public void SetEntryAssembly()
{

View file

@ -19,6 +19,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
case Keys.ConfigurationFile.ConfigurationPurpose:
MapConfigurationMode(settings, value);
break;
case Keys.ConfigurationFile.SessionMode:
MapSessionMode(settings, value);
break;
}
}
@ -31,5 +34,15 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
settings.ConfigurationMode = mode == CONFIGURE_CLIENT ? ConfigurationMode.ConfigureClient : ConfigurationMode.Exam;
}
}
private void MapSessionMode(AppSettings settings, object value)
{
const int SERVER = 1;
if (value is int mode)
{
settings.SessionMode = mode == SERVER ? SessionMode.Server : SessionMode.Normal;
}
}
}
}

View file

@ -18,7 +18,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
switch (key)
{
case Keys.ConfigurationFile.AdminPasswordHash:
case Keys.Security.AdminPasswordHash:
MapAdminPasswordHash(settings, value);
break;
case Keys.Security.AllowTermination:

View file

@ -0,0 +1,118 @@
/*
* Copyright (c) 2020 ETH Zürich, Educational Development and Technology (LET)
*
* 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/.
*/
using System.Collections.Generic;
using SafeExamBrowser.Settings;
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
internal class ServerDataMapper : BaseDataMapper
{
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Server.Configuration:
MapConfiguration(settings, value);
break;
case Keys.Server.FallbackPasswordHash:
MapFallbackPasswordHash(settings, value);
break;
case Keys.Server.PerformFallback:
MapPerformFallback(settings, value);
break;
case Keys.Server.RequestAttempts:
MapRequestAttempts(settings, value);
break;
case Keys.Server.RequestAttemptInterval:
MapRequestAttemptInterval(settings, value);
break;
case Keys.Server.RequestTimeout:
MapRequestTimeout(settings, value);
break;
case Keys.Server.ServerUrl:
MapServerUrl(settings, value);
break;
}
}
private void MapConfiguration(AppSettings settings, object value)
{
if (value is IDictionary<string, object> configuration)
{
if (configuration.TryGetValue(Keys.Server.ApiUrl, out var v) && v is string url)
{
settings.Server.ApiUrl = url;
}
if (configuration.TryGetValue(Keys.Server.ClientName, out v) && v is string name)
{
settings.Server.ClientName = name;
}
if (configuration.TryGetValue(Keys.Server.ClientSecret, out v) && v is string secret)
{
settings.Server.ClientSecret = secret;
}
if (configuration.TryGetValue(Keys.Server.Institution, out v) && v is string institution)
{
settings.Server.Institution = institution;
}
}
}
private void MapFallbackPasswordHash(AppSettings settings, object value)
{
if (value is string hash)
{
settings.Server.FallbackPasswordHash = hash;
}
}
private void MapPerformFallback(AppSettings settings, object value)
{
if (value is bool perform)
{
settings.Server.PerformFallback = perform;
}
}
private void MapRequestAttempts(AppSettings settings, object value)
{
if (value is int attempts)
{
settings.Server.RequestAttempts = attempts;
}
}
private void MapRequestAttemptInterval(AppSettings settings, object value)
{
if (value is int interval)
{
settings.Server.RequestAttemptInterval = interval;
}
}
private void MapRequestTimeout(AppSettings settings, object value)
{
if (value is int timeout)
{
settings.Server.RequestTimeout = timeout;
}
}
private void MapServerUrl(AppSettings settings, object value)
{
if (value is string url)
{
settings.Server.ServerUrl = url;
}
}
}
}

View file

@ -172,6 +172,11 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
settings.Security.KioskMode = KioskMode.CreateNewDesktop;
settings.Security.VirtualMachinePolicy = VirtualMachinePolicy.Deny;
settings.Server.RequestAttemptInterval = 2000;
settings.Server.RequestAttempts = 5;
settings.Server.RequestTimeout = 5000;
settings.Server.PerformFallback = false;
settings.Service.DisableChromeNotifications = true;
settings.Service.DisableEaseOfAccessOptions = true;
settings.Service.DisableNetworkOptions = true;
@ -188,6 +193,8 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
settings.Service.Policy = ServicePolicy.Mandatory;
settings.Service.SetVmwareConfiguration = false;
settings.SessionMode = SessionMode.Normal;
settings.Taskbar.EnableTaskbar = true;
settings.Taskbar.ShowApplicationInfo = false;
settings.Taskbar.ShowApplicationLog = false;

View file

@ -156,9 +156,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal static class ConfigurationFile
{
internal const string AdminPasswordHash = "hashedAdminPassword";
internal const string ConfigurationPurpose = "sebConfigPurpose";
internal const string KeepClientConfigEncryption = "clientConfigKeepEncryption";
internal const string SessionMode = "sebMode";
}
internal static class General
@ -207,6 +207,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal static class Security
{
internal const string AdminPasswordHash = "hashedAdminPassword";
internal const string AllowApplicationLog = "allowApplicationLog";
internal const string AllowTermination = "allowQuit";
internal const string AllowVirtualMachine = "allowVirtualMachine";
@ -215,6 +216,21 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal const string QuitPasswordHash = "hashedQuitPassword";
}
internal static class Server
{
internal const string ApiUrl = "apiDiscovery";
internal const string ClientName = "clientName";
internal const string ClientSecret = "clientSecret";
internal const string Configuration = "sebServerConfiguration";
internal const string FallbackPasswordHash = "sebServerFallbackPasswordHash";
internal const string Institution = "institution";
internal const string PerformFallback = "sebServerFallback";
internal const string RequestAttempts = "sebServerFallbackAttempts";
internal const string RequestAttemptInterval = "sebServerFallbackAttemptInterval";
internal const string RequestTimeout = "sebServerFallbackTimeout";
internal const string ServerUrl = "sebServerURL";
}
internal static class Service
{
internal const string EnableChromeNotifications = "enableChromeNotifications";

View file

@ -64,6 +64,7 @@
<Compile Include="ConfigurationData\DataMapping\BaseDataMapper.cs" />
<Compile Include="ConfigurationData\DataMapping\InputDataMapper.cs" />
<Compile Include="ConfigurationData\DataMapping\SecurityDataMapper.cs" />
<Compile Include="ConfigurationData\DataMapping\ServerDataMapper.cs" />
<Compile Include="ConfigurationData\DataMapping\ServiceDataMapper.cs" />
<Compile Include="ConfigurationData\DataMapping\UserInterfaceDataMapper.cs" />
<Compile Include="ConfigurationData\DataProcessor.cs" />

View file

@ -80,6 +80,7 @@ namespace SafeExamBrowser.Runtime
sessionOperations.Enqueue(new SessionInitializationOperation(configuration, logger, runtimeHost, sessionContext));
sessionOperations.Enqueue(new ConfigurationOperation(args, configuration, new FileSystem(), new HashAlgorithm(), logger, sessionContext));
// TODO: sessionOperations.Enqueue(new ServerOperation());
sessionOperations.Enqueue(new VirtualMachineOperation(vmDetector, logger, sessionContext));
sessionOperations.Enqueue(new ServiceOperation(logger, runtimeHost, serviceProxy, sessionContext, THIRTY_SECONDS, userInfo));
sessionOperations.Enqueue(new ClientTerminationOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS));

View file

@ -12,6 +12,7 @@ using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Logging;
using SafeExamBrowser.Settings.Monitoring;
using SafeExamBrowser.Settings.Security;
using SafeExamBrowser.Settings.Server;
using SafeExamBrowser.Settings.Service;
using SafeExamBrowser.Settings.SystemComponents;
using SafeExamBrowser.Settings.UserInterface;
@ -69,11 +70,21 @@ namespace SafeExamBrowser.Settings
/// </summary>
public SecuritySettings Security { get; set; }
/// <summary>
/// All server-related settings.
/// </summary>
public ServerSettings Server { get; set; }
/// <summary>
/// All service-related settings.
/// </summary>
public ServiceSettings Service { get; set; }
/// <summary>
/// The mode which determines the session behaviour.
/// </summary>
public SessionMode SessionMode { get; set; }
/// <summary>
/// All taskbar-related settings.
/// </summary>
@ -93,6 +104,7 @@ namespace SafeExamBrowser.Settings
Keyboard = new KeyboardSettings();
Mouse = new MouseSettings();
Security = new SecuritySettings();
Server = new ServerSettings();
Service = new ServiceSettings();
Taskbar = new TaskbarSettings();
}

View file

@ -70,6 +70,7 @@
<Compile Include="Browser\Proxy\ProxyProtocol.cs" />
<Compile Include="Browser\Proxy\ProxyConfiguration.cs" />
<Compile Include="ConfigurationMode.cs" />
<Compile Include="SessionMode.cs" />
<Compile Include="Security\KioskMode.cs" />
<Compile Include="Logging\LogLevel.cs" />
<Compile Include="Monitoring\KeyboardSettings.cs" />
@ -77,6 +78,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Security\SecuritySettings.cs" />
<Compile Include="Security\VirtualMachinePolicy.cs" />
<Compile Include="Server\ServerSettings.cs" />
<Compile Include="Service\ServicePolicy.cs" />
<Compile Include="Service\ServiceSettings.cs" />
<Compile Include="AppSettings.cs" />

View file

@ -0,0 +1,69 @@
/*
* Copyright (c) 2020 ETH Zürich, Educational Development and Technology (LET)
*
* 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/.
*/
using System;
namespace SafeExamBrowser.Settings.Server
{
/// <summary>
/// Defines all settings for a SEB server.
/// </summary>
[Serializable]
public class ServerSettings
{
/// <summary>
/// The discovery URL for the API of the server.
/// </summary>
public string ApiUrl { get; set; }
/// <summary>
/// The client name for initial authentication with the server.
/// </summary>
public string ClientName { get; set; }
/// <summary>
/// The client secret for initial authentication with the server.
/// </summary>
public string ClientSecret { get; set; }
/// <summary>
/// The hash code of the password required to perform a fallback.
/// </summary>
public string FallbackPasswordHash { get; set; }
/// <summary>
/// The institution to be used for identification with the server.
/// </summary>
public string Institution { get; set; }
/// <summary>
/// Indicates whether SEB will fallback to the start URL in case no connection could be established with the server.
/// </summary>
public bool PerformFallback { get; set; }
/// <summary>
/// The number of attempts (e.g. when receiving an invalid server response) before performing a fallback or failing.
/// </summary>
public int RequestAttempts { get; set; }
/// <summary>
/// The time interval in milliseconds to be waited in between attempts.
/// </summary>
public int RequestAttemptInterval { get; set; }
/// <summary>
/// The timeout in milliseconds (e.g. to wait for a server response) before performing a fallback or failing.
/// </summary>
public int RequestTimeout { get; set; }
/// <summary>
/// The URL of the server.
/// </summary>
public string ServerUrl { get; set; }
}
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2020 ETH Zürich, Educational Development and Technology (LET)
*
* 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/.
*/
namespace SafeExamBrowser.Settings
{
/// <summary>
/// Defines all possible session modes.
/// </summary>
public enum SessionMode
{
/// <summary>
/// SEB will start a normal session without SEB server.
/// </summary>
Normal,
/// <summary>
/// SEB will start a session with SEB server.
/// </summary>
Server
}
}