SEBWIN-821: Implemented configuration value for lock screen on user session change.

This commit is contained in:
Damian Büchel 2024-01-11 19:01:56 +01:00
parent 79dedf12b5
commit 27155a057d
11 changed files with 44 additions and 22 deletions

View file

@ -1228,7 +1228,7 @@ namespace SafeExamBrowser.Client.UnitTests
uiFactory.Setup(f => f.CreateLockScreen(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IEnumerable<LockScreenOption>>())).Returns(lockScreen.Object);
sut.TryStart();
systemMonitor.Raise(m => m.SessionSwitched += null);
systemMonitor.Raise(m => m.SessionChanged += null);
lockScreen.Verify(l => l.Show(), Times.Once);
}
@ -1248,7 +1248,7 @@ namespace SafeExamBrowser.Client.UnitTests
.Returns(lockScreen.Object);
sut.TryStart();
systemMonitor.Raise(m => m.SessionSwitched += null);
systemMonitor.Raise(m => m.SessionChanged += null);
lockScreen.Verify(l => l.Show(), Times.Once);
runtimeProxy.Verify(p => p.RequestShutdown(), Times.Once);
@ -1266,7 +1266,7 @@ namespace SafeExamBrowser.Client.UnitTests
uiFactory.Setup(f => f.CreateLockScreen(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IEnumerable<LockScreenOption>>())).Returns(lockScreen.Object);
sut.TryStart();
systemMonitor.Raise(m => m.SessionSwitched += null);
systemMonitor.Raise(m => m.SessionChanged += null);
lockScreen.Verify(l => l.Show(), Times.Never);
}

View file

@ -213,7 +213,7 @@ namespace SafeExamBrowser.Client
displayMonitor.DisplayChanged += DisplayMonitor_DisplaySettingsChanged;
registry.ValueChanged += Registry_ValueChanged;
runtime.ConnectionLost += Runtime_ConnectionLost;
systemMonitor.SessionSwitched += SystemMonitor_SessionSwitched;
systemMonitor.SessionChanged += SystemMonitor_SessionChanged;
taskbar.LoseFocusRequested += Taskbar_LoseFocusRequested;
taskbar.QuitButtonClicked += Shell_QuitButtonClicked;
@ -248,7 +248,7 @@ namespace SafeExamBrowser.Client
displayMonitor.DisplayChanged -= DisplayMonitor_DisplaySettingsChanged;
registry.ValueChanged -= Registry_ValueChanged;
runtime.ConnectionLost -= Runtime_ConnectionLost;
systemMonitor.SessionSwitched -= SystemMonitor_SessionSwitched;
systemMonitor.SessionChanged -= SystemMonitor_SessionChanged;
taskbar.QuitButtonClicked -= Shell_QuitButtonClicked;
if (Browser != null)
@ -838,21 +838,22 @@ namespace SafeExamBrowser.Client
ResumeActivators();
}
private void SystemMonitor_SessionSwitched()
private void SystemMonitor_SessionChanged()
{
var allow = !Settings.Service.IgnoreService && (!Settings.Service.DisableUserLock || !Settings.Service.DisableUserSwitch);
var disable = Settings.Security.DisableSessionChangeLockScreen;
var message = text.Get(TextKey.LockScreen_UserSessionMessage);
var title = text.Get(TextKey.LockScreen_Title);
var continueOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_UserSessionContinueOption) };
var terminateOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_UserSessionTerminateOption) };
if (allow)
if (allow || disable)
{
logger.Info("Detected user session switch, but user lock and/or user switch are allowed.");
logger.Info($"Detected user session change, but {(allow ? "session locking and/or switching is allowed" : "lock screen is deactivated")}.");
}
else
{
logger.Warn("Detected user session switch!");
logger.Warn("Detected user session change!");
if (!sessionLocked)
{

View file

@ -35,6 +35,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
case Keys.Security.ClipboardPolicy:
MapClipboardPolicy(settings, value);
break;
case Keys.Security.DisableSessionChangeLockScreen:
MapDisableSessionChangeLockScreen(settings, value);
break;
case Keys.Security.QuitPasswordHash:
MapQuitPasswordHash(settings, value);
break;
@ -137,6 +140,14 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
}
}
private void MapDisableSessionChangeLockScreen(AppSettings settings, object value)
{
if (value is bool disable)
{
settings.Security.DisableSessionChangeLockScreen = disable;
}
}
private void MapVirtualMachinePolicy(AppSettings settings, object value)
{
if (value is bool allow)

View file

@ -272,6 +272,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
settings.Security.AllowTermination = true;
settings.Security.AllowReconfiguration = false;
settings.Security.ClipboardPolicy = ClipboardPolicy.Isolated;
settings.Security.DisableSessionChangeLockScreen = false;
settings.Security.KioskMode = KioskMode.CreateNewDesktop;
settings.Security.VirtualMachinePolicy = VirtualMachinePolicy.Deny;

View file

@ -283,6 +283,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal const string AllowTermination = "allowQuit";
internal const string AllowVirtualMachine = "allowVirtualMachine";
internal const string ClipboardPolicy = "clipboardPolicy";
internal const string DisableSessionChangeLockScreen = "disableSessionChangeLockScreen";
internal const string KioskModeCreateNewDesktop = "createNewDesktop";
internal const string KioskModeDisableExplorerShell = "killExplorerShell";
internal const string QuitPasswordHash = "hashedQuitPassword";

View file

@ -68,7 +68,7 @@
<Compile Include="Applications\InitializationResult.cs" />
<Compile Include="Applications\IApplicationMonitor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="System\Events\SessionSwitchedEventHandler.cs" />
<Compile Include="System\Events\SessionChangedEventHandler.cs" />
<Compile Include="System\ISystemMonitor.cs" />
</ItemGroup>
<ItemGroup>

View file

@ -11,5 +11,5 @@ namespace SafeExamBrowser.Monitoring.Contracts.System.Events
/// <summary>
/// Indicates that the active user session of the operating system has changed.
/// </summary>
public delegate void SessionSwitchedEventHandler();
public delegate void SessionChangedEventHandler();
}

View file

@ -18,7 +18,7 @@ namespace SafeExamBrowser.Monitoring.Contracts.System
/// <summary>
/// Event fired when the active user session has changed.
/// </summary>
event SessionSwitchedEventHandler SessionSwitched;
event SessionChangedEventHandler SessionChanged;
/// <summary>
/// Starts the monitoring.

View file

@ -19,7 +19,7 @@ namespace SafeExamBrowser.Monitoring.System
{
private readonly ILogger logger;
public event SessionSwitchedEventHandler SessionSwitched;
public event SessionChangedEventHandler SessionChanged;
public SystemMonitor(ILogger logger)
{
@ -33,7 +33,7 @@ namespace SafeExamBrowser.Monitoring.System
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
SystemEvents.SessionEnded += SystemEvents_SessionEnded;
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
SystemEvents.SessionSwitch += SystemEvents_SessionChanged;
SystemEvents.TimeChanged += SystemEvents_TimeChanged;
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
logger.Info("Started monitoring the operating system.");
@ -46,7 +46,7 @@ namespace SafeExamBrowser.Monitoring.System
SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
SystemEvents.SessionEnded -= SystemEvents_SessionEnded;
SystemEvents.SessionEnding -= SystemEvents_SessionEnding;
SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch;
SystemEvents.SessionSwitch -= SystemEvents_SessionChanged;
SystemEvents.TimeChanged -= SystemEvents_TimeChanged;
SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;
logger.Info("Stopped monitoring the operating system.");
@ -64,23 +64,23 @@ namespace SafeExamBrowser.Monitoring.System
private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
logger.Info($"Power mode changed: {e.Mode}");
logger.Info($"Power mode changed: {e.Mode}.");
}
private void SystemEvents_SessionEnded(object sender, SessionEndedEventArgs e)
{
logger.Warn($"User session ended! Reason: {e.Reason}");
logger.Warn($"User session ended! Reason: {e.Reason}.");
}
private void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
logger.Warn($"User session is ending! Reason: {e.Reason}");
logger.Warn($"User session is ending! Reason: {e.Reason}.");
}
private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
private void SystemEvents_SessionChanged(object sender, SessionSwitchEventArgs e)
{
logger.Info($"User session switch detected! Reason: {e.Reason}");
Task.Run(() => SessionSwitched?.Invoke());
logger.Info($"User session change detected: {e.Reason}.");
Task.Run(() => SessionChanged?.Invoke());
}
private void SystemEvents_TimeChanged(object sender, EventArgs e)
@ -90,7 +90,7 @@ namespace SafeExamBrowser.Monitoring.System
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
logger.Info($"User preference changed. Category: {e.Category}");
logger.Info($"User preference changed. Category: {e.Category}.");
}
}
}

View file

@ -42,6 +42,12 @@ namespace SafeExamBrowser.Settings.Security
/// </summary>
public ClipboardPolicy ClipboardPolicy { get; set; }
/// <summary>
/// Determines whether the lock screen is disabled in case of a user session change. This setting overrides the activation based on
/// <see cref="Service.ServiceSettings.IgnoreService"/> and <see cref="Service.ServiceSettings.DisableUserLock"/> or <see cref="Service.ServiceSettings.DisableUserSwitch"/>.
/// </summary>
public bool DisableSessionChangeLockScreen { get; set; }
/// <summary>
/// The kiosk mode which determines how the computer is locked down.
/// </summary>

View file

@ -379,6 +379,7 @@ namespace SebWindowsConfig
public const String KeyAllowWindowsUpdate = "enableWindowsUpdate";
public const String KeyVersionRestrictions = "sebAllowedVersions";
public const String KeyClipboardPolicy = "clipboardPolicy";
public const String KeyDisableSessionChangeLockScreen = "disableSessionChangeLockScreen";
// Group "macOS specific settings"
public const String KeyMinMacOSVersion = "minMacOSVersion";
@ -1013,6 +1014,7 @@ namespace SebWindowsConfig
SEBSettings.settingsDefault.Add(SEBSettings.KeyAllowChromeNotifications, false);
SEBSettings.settingsDefault.Add(SEBSettings.KeyAllowWindowsUpdate, false);
SEBSettings.settingsDefault.Add(SEBSettings.KeyClipboardPolicy, 2);
SEBSettings.settingsDefault.Add(SEBSettings.KeyDisableSessionChangeLockScreen, false);
// Default selected index and string in combo box for minMacOSVersion
SEBSettings.intArrayDefault[SEBSettings.ValMinMacOSVersion] = 4;