seb-win-refactoring/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/SecurityDataMapper.cs

87 lines
2.5 KiB
C#
Raw Normal View History

/*
* Copyright (c) 2019 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;
using SafeExamBrowser.Settings.Service;
2019-12-20 10:03:47 +01:00
namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
{
2019-12-20 10:03:47 +01:00
internal class SecurityDataMapper : BaseDataMapper
{
2019-12-20 10:03:47 +01:00
internal override void Map(string key, object value, AppSettings settings)
{
switch (key)
{
case Keys.Security.AllowVirtualMachine:
MapVirtualMachinePolicy(settings, value);
break;
case Keys.Security.QuitPasswordHash:
MapQuitPasswordHash(settings, value);
break;
case Keys.Security.ServicePolicy:
MapServicePolicy(settings, value);
break;
}
}
internal override void MapGlobal(IDictionary<string, object> rawData, AppSettings settings)
{
MapKioskMode(rawData, settings);
}
private void MapKioskMode(IDictionary<string, object> rawData, AppSettings settings)
{
var hasCreateNewDesktop = rawData.TryGetValue(Keys.Security.KioskModeCreateNewDesktop, out var createNewDesktop);
var hasDisableExplorerShell = rawData.TryGetValue(Keys.Security.KioskModeDisableExplorerShell, out var disableExplorerShell);
if (hasDisableExplorerShell && disableExplorerShell as bool? == true)
{
settings.KioskMode = KioskMode.DisableExplorerShell;
}
if (hasCreateNewDesktop && createNewDesktop as bool? == true)
{
settings.KioskMode = KioskMode.CreateNewDesktop;
}
if (hasCreateNewDesktop && hasDisableExplorerShell && createNewDesktop as bool? == false && disableExplorerShell as bool? == false)
{
settings.KioskMode = KioskMode.None;
}
}
2019-12-20 10:03:47 +01:00
private void MapQuitPasswordHash(AppSettings settings, object value)
{
if (value is string hash)
{
settings.QuitPasswordHash = hash;
}
}
private void MapServicePolicy(AppSettings settings, object value)
{
const int WARN = 1;
const int FORCE = 2;
if (value is int policy)
{
settings.Service.Policy = policy == FORCE ? ServicePolicy.Mandatory : (policy == WARN ? ServicePolicy.Warn : ServicePolicy.Optional);
}
}
2019-12-20 10:03:47 +01:00
private void MapVirtualMachinePolicy(AppSettings settings, object value)
{
if (value is bool allow)
{
// TODO NEXT: settings.Security.VirtualMachinePolicy = ;
}
}
}
}