diff --git a/SafeExamBrowser.Contracts/Lockdown/IFeatureConfigurationFactory.cs b/SafeExamBrowser.Contracts/Lockdown/IFeatureConfigurationFactory.cs index 2bb11693..0e2dfb7c 100644 --- a/SafeExamBrowser.Contracts/Lockdown/IFeatureConfigurationFactory.cs +++ b/SafeExamBrowser.Contracts/Lockdown/IFeatureConfigurationFactory.cs @@ -15,6 +15,11 @@ namespace SafeExamBrowser.Contracts.Lockdown /// public interface IFeatureConfigurationFactory { + /// + /// Creates an to control the option to change the password of a user account via the security screen. + /// + IFeatureConfiguration CreateChangePasswordConfiguration(Guid groupId, string sid, string userName); + /// /// Creates an to control notifications of the Google Chrome browser. /// @@ -25,16 +30,16 @@ namespace SafeExamBrowser.Contracts.Lockdown /// IFeatureConfiguration CreateEaseOfAccessConfiguration(Guid groupId); + /// + /// Creates an to control the option to lock the computer via the security screen. + /// + IFeatureConfiguration CreateLockWorkstationConfiguration(Guid groupId, string sid, string userName); + /// /// Creates an to control the network options on the security screen. /// IFeatureConfiguration CreateNetworkOptionsConfiguration(Guid groupId); - /// - /// Creates an to control the option to change the password of a user account via the security screen. - /// - IFeatureConfiguration CreatePasswordChangeConfiguration(Guid groupId); - /// /// Creates an to control the power options on the security screen. /// @@ -48,27 +53,22 @@ namespace SafeExamBrowser.Contracts.Lockdown /// /// Creates an to control the option to sign out out via security screen. /// - IFeatureConfiguration CreateSignoutConfiguration(Guid groupId); - - /// - /// Creates an to control the task manager of Windows. - /// - IFeatureConfiguration CreateTaskManagerConfiguration(Guid groupId); - - /// - /// Creates an to control the option to lock the computer via the security screen. - /// - IFeatureConfiguration CreateUserLockConfiguration(Guid groupId); + IFeatureConfiguration CreateSignoutConfiguration(Guid groupId, string sid, string userName); /// /// Creates an to control the option to switch to another user account via the security screen. /// - IFeatureConfiguration CreateUserSwitchConfiguration(Guid groupId); + IFeatureConfiguration CreateSwitchUserConfiguration(Guid groupId); + + /// + /// Creates an to control the task manager of Windows. + /// + IFeatureConfiguration CreateTaskManagerConfiguration(Guid groupId, string sid, string userName); /// /// Creates an to control the user interface overlay for VMware clients. /// - IFeatureConfiguration CreateVmwareOverlayConfiguration(Guid groupId); + IFeatureConfiguration CreateVmwareOverlayConfiguration(Guid groupId, string sid, string userName); /// /// Creates an to control Windows Update. diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurationFactory.cs b/SafeExamBrowser.Lockdown/FeatureConfigurationFactory.cs index b6fa7811..6c8590ac 100644 --- a/SafeExamBrowser.Lockdown/FeatureConfigurationFactory.cs +++ b/SafeExamBrowser.Lockdown/FeatureConfigurationFactory.cs @@ -10,6 +10,7 @@ using System; using SafeExamBrowser.Contracts.Lockdown; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Lockdown.FeatureConfigurations; +using SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.MachineHive; using SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.UserHive; namespace SafeExamBrowser.Lockdown @@ -23,6 +24,11 @@ namespace SafeExamBrowser.Lockdown this.logger = logger; } + public IFeatureConfiguration CreateChangePasswordConfiguration(Guid groupId, string sid, string userName) + { + return new ChangePasswordConfiguration(groupId, logger.CloneFor(nameof(ChangePasswordConfiguration)), sid, userName); + } + public IFeatureConfiguration CreateChromeNotificationConfiguration(Guid groupId, string sid, string userName) { return new ChromeNotificationConfiguration(groupId, logger.CloneFor(nameof(ChromeNotificationConfiguration)), sid, userName); @@ -33,16 +39,16 @@ namespace SafeExamBrowser.Lockdown return new EaseOfAccessConfiguration(groupId, logger.CloneFor(nameof(EaseOfAccessConfiguration))); } + public IFeatureConfiguration CreateLockWorkstationConfiguration(Guid groupId, string sid, string userName) + { + return new LockWorkstationConfiguration(groupId, logger.CloneFor(nameof(LockWorkstationConfiguration)), sid, userName); + } + public IFeatureConfiguration CreateNetworkOptionsConfiguration(Guid groupId) { return new NetworkOptionsConfiguration(groupId, logger.CloneFor(nameof(NetworkOptionsConfiguration))); } - public IFeatureConfiguration CreatePasswordChangeConfiguration(Guid groupId) - { - return new PasswordChangeConfiguration(groupId, logger.CloneFor(nameof(PasswordChangeConfiguration))); - } - public IFeatureConfiguration CreatePowerOptionsConfiguration(Guid groupId) { return new PowerOptionsConfiguration(groupId, logger.CloneFor(nameof(PowerOptionsConfiguration))); @@ -53,29 +59,24 @@ namespace SafeExamBrowser.Lockdown return new RemoteConnectionConfiguration(groupId, logger.CloneFor(nameof(RemoteConnectionConfiguration))); } - public IFeatureConfiguration CreateSignoutConfiguration(Guid groupId) + public IFeatureConfiguration CreateSignoutConfiguration(Guid groupId, string sid, string userName) { - return new SignoutConfiguration(groupId, logger.CloneFor(nameof(SignoutConfiguration))); + return new SignoutConfiguration(groupId, logger.CloneFor(nameof(SignoutConfiguration)), sid, userName); } - public IFeatureConfiguration CreateTaskManagerConfiguration(Guid groupId) + public IFeatureConfiguration CreateSwitchUserConfiguration(Guid groupId) { - return new TaskManagerConfiguration(groupId, logger.CloneFor(nameof(TaskManagerConfiguration))); + return new SwitchUserConfiguration(groupId, logger.CloneFor(nameof(SwitchUserConfiguration))); } - public IFeatureConfiguration CreateUserLockConfiguration(Guid groupId) + public IFeatureConfiguration CreateTaskManagerConfiguration(Guid groupId, string sid, string userName) { - return new UserLockConfiguration(groupId, logger.CloneFor(nameof(UserLockConfiguration))); + return new TaskManagerConfiguration(groupId, logger.CloneFor(nameof(TaskManagerConfiguration)), sid, userName); } - public IFeatureConfiguration CreateUserSwitchConfiguration(Guid groupId) + public IFeatureConfiguration CreateVmwareOverlayConfiguration(Guid groupId, string sid, string userName) { - return new UserSwitchConfiguration(groupId, logger.CloneFor(nameof(UserSwitchConfiguration))); - } - - public IFeatureConfiguration CreateVmwareOverlayConfiguration(Guid groupId) - { - return new VmwareOverlayConfiguration(groupId, logger.CloneFor(nameof(VmwareOverlayConfiguration))); + return new VmwareOverlayConfiguration(groupId, logger.CloneFor(nameof(VmwareOverlayConfiguration)), sid, userName); } public IFeatureConfiguration CreateWindowsUpdateConfiguration(Guid groupId) diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/PasswordChangeConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/PasswordChangeConfiguration.cs deleted file mode 100644 index dc938be2..00000000 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/PasswordChangeConfiguration.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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; -using SafeExamBrowser.Contracts.Logging; - -namespace SafeExamBrowser.Lockdown.FeatureConfigurations -{ - [Serializable] - internal class PasswordChangeConfiguration : FeatureConfiguration - { - public PasswordChangeConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) - { - } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } - } -} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/EaseOfAccessConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/EaseOfAccessConfiguration.cs similarity index 51% rename from SafeExamBrowser.Lockdown/FeatureConfigurations/EaseOfAccessConfiguration.cs rename to SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/EaseOfAccessConfiguration.cs index ccac2bca..376b4590 100644 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/EaseOfAccessConfiguration.cs +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/EaseOfAccessConfiguration.cs @@ -7,40 +7,21 @@ */ using System; +using System.Collections.Generic; using SafeExamBrowser.Contracts.Logging; -namespace SafeExamBrowser.Lockdown.FeatureConfigurations +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.MachineHive { [Serializable] - internal class EaseOfAccessConfiguration : FeatureConfiguration + internal class EaseOfAccessConfiguration : MachineHiveConfiguration { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\Utilman.exe", "Debugger", "SebDummy.exe", "") + }; + public EaseOfAccessConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) { } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } } } diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHiveConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/MachineHiveConfiguration.cs similarity index 96% rename from SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHiveConfiguration.cs rename to SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/MachineHiveConfiguration.cs index 0b41fa70..7016a1f7 100644 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHiveConfiguration.cs +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/MachineHiveConfiguration.cs @@ -10,7 +10,7 @@ using System; using Microsoft.Win32; using SafeExamBrowser.Contracts.Logging; -namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.MachineHive { [Serializable] internal abstract class MachineHiveConfiguration : RegistryConfiguration diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/NetworkOptionsConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/NetworkOptionsConfiguration.cs similarity index 53% rename from SafeExamBrowser.Lockdown/FeatureConfigurations/NetworkOptionsConfiguration.cs rename to SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/NetworkOptionsConfiguration.cs index 2278bfcb..8cdcc163 100644 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/NetworkOptionsConfiguration.cs +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/NetworkOptionsConfiguration.cs @@ -7,40 +7,21 @@ */ using System; +using System.Collections.Generic; using SafeExamBrowser.Contracts.Logging; -namespace SafeExamBrowser.Lockdown.FeatureConfigurations +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.MachineHive { [Serializable] - internal class NetworkOptionsConfiguration : FeatureConfiguration + internal class NetworkOptionsConfiguration : MachineHiveConfiguration { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem(@"HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\System", "DontDisplayNetworkSelectionUI", 1, 0) + }; + public NetworkOptionsConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) { } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } } } diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/PowerOptionsConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/PowerOptionsConfiguration.cs similarity index 53% rename from SafeExamBrowser.Lockdown/FeatureConfigurations/PowerOptionsConfiguration.cs rename to SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/PowerOptionsConfiguration.cs index 84e8acf1..042fcb6a 100644 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/PowerOptionsConfiguration.cs +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/PowerOptionsConfiguration.cs @@ -7,40 +7,21 @@ */ using System; +using System.Collections.Generic; using SafeExamBrowser.Contracts.Logging; -namespace SafeExamBrowser.Lockdown.FeatureConfigurations +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.MachineHive { [Serializable] - internal class PowerOptionsConfiguration : FeatureConfiguration + internal class PowerOptionsConfiguration : MachineHiveConfiguration { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoClose", 1, 0) + }; + public PowerOptionsConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) { } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } } } diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/RemoteConnectionConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/RemoteConnectionConfiguration.cs similarity index 53% rename from SafeExamBrowser.Lockdown/FeatureConfigurations/RemoteConnectionConfiguration.cs rename to SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/RemoteConnectionConfiguration.cs index c39649da..df20dd4e 100644 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/RemoteConnectionConfiguration.cs +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/RemoteConnectionConfiguration.cs @@ -7,40 +7,21 @@ */ using System; +using System.Collections.Generic; using SafeExamBrowser.Contracts.Logging; -namespace SafeExamBrowser.Lockdown.FeatureConfigurations +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.MachineHive { [Serializable] - internal class RemoteConnectionConfiguration : FeatureConfiguration + internal class RemoteConnectionConfiguration : MachineHiveConfiguration { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server", "fDenyTSConnections", 1, 0) + }; + public RemoteConnectionConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) { } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } } } diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/SwitchUserConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/SwitchUserConfiguration.cs new file mode 100644 index 00000000..1a35010a --- /dev/null +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/MachineHive/SwitchUserConfiguration.cs @@ -0,0 +1,27 @@ +/* + * 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; +using System.Collections.Generic; +using SafeExamBrowser.Contracts.Logging; + +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.MachineHive +{ + [Serializable] + internal class SwitchUserConfiguration : MachineHiveConfiguration + { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System", "HideFastUserSwitching", 1, 0) + }; + + public SwitchUserConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) + { + } + } +} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/ChangePasswordConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/ChangePasswordConfiguration.cs new file mode 100644 index 00000000..68ef2b67 --- /dev/null +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/ChangePasswordConfiguration.cs @@ -0,0 +1,27 @@ +/* + * 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; +using System.Collections.Generic; +using SafeExamBrowser.Contracts.Logging; + +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.UserHive +{ + [Serializable] + internal class ChangePasswordConfiguration : UserHiveConfiguration + { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem($@"HKEY_USERS\{SID}\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableChangePassword", 1, 0) + }; + + public ChangePasswordConfiguration(Guid groupId, ILogger logger, string sid, string userName) : base(groupId, logger, sid, userName) + { + } + } +} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/LockWorkstationConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/LockWorkstationConfiguration.cs new file mode 100644 index 00000000..d597294b --- /dev/null +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/LockWorkstationConfiguration.cs @@ -0,0 +1,27 @@ +/* + * 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; +using System.Collections.Generic; +using SafeExamBrowser.Contracts.Logging; + +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.UserHive +{ + [Serializable] + internal class LockWorkstationConfiguration : UserHiveConfiguration + { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem($@"HKEY_USERS\{SID}\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableLockWorkstation", 1, 0) + }; + + public LockWorkstationConfiguration(Guid groupId, ILogger logger, string sid, string userName) : base(groupId, logger, sid, userName) + { + } + } +} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/SignoutConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/SignoutConfiguration.cs new file mode 100644 index 00000000..ad027e19 --- /dev/null +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/SignoutConfiguration.cs @@ -0,0 +1,27 @@ +/* + * 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; +using System.Collections.Generic; +using SafeExamBrowser.Contracts.Logging; + +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.UserHive +{ + [Serializable] + internal class SignoutConfiguration : UserHiveConfiguration + { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem($@"HKEY_USERS\{SID}\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoLogoff", 1, 0) + }; + + public SignoutConfiguration(Guid groupId, ILogger logger, string sid, string userName) : base(groupId, logger, sid, userName) + { + } + } +} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/TaskManagerConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/TaskManagerConfiguration.cs new file mode 100644 index 00000000..b1ca350f --- /dev/null +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/TaskManagerConfiguration.cs @@ -0,0 +1,27 @@ +/* + * 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; +using System.Collections.Generic; +using SafeExamBrowser.Contracts.Logging; + +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.UserHive +{ + [Serializable] + internal class TaskManagerConfiguration : UserHiveConfiguration + { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem($@"HKEY_USERS\{SID}\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", 1, 0) + }; + + public TaskManagerConfiguration(Guid groupId, ILogger logger, string sid, string userName) : base(groupId, logger, sid, userName) + { + } + } +} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHiveConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/UserHiveConfiguration.cs similarity index 98% rename from SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHiveConfiguration.cs rename to SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/UserHiveConfiguration.cs index a8343ae5..7d7a4183 100644 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHiveConfiguration.cs +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/UserHiveConfiguration.cs @@ -10,7 +10,7 @@ using System; using Microsoft.Win32; using SafeExamBrowser.Contracts.Logging; -namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.UserHive { [Serializable] internal abstract class UserHiveConfiguration : RegistryConfiguration diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/VmwareOverlayConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/VmwareOverlayConfiguration.cs new file mode 100644 index 00000000..fd834736 --- /dev/null +++ b/SafeExamBrowser.Lockdown/FeatureConfigurations/RegistryConfigurations/UserHive/VmwareOverlayConfiguration.cs @@ -0,0 +1,28 @@ +/* + * 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; +using System.Collections.Generic; +using SafeExamBrowser.Contracts.Logging; + +namespace SafeExamBrowser.Lockdown.FeatureConfigurations.RegistryConfigurations.UserHive +{ + [Serializable] + internal class VmwareOverlayConfiguration : UserHiveConfiguration + { + protected override IEnumerable Items => new [] + { + new RegistryConfigurationItem($@"HKEY_USERS\{SID}\Software\VMware, Inc.\VMware VDM\Client", "EnableShade", 0, 1), + new RegistryConfigurationItem($@"HKEY_USERS\{SID}\Software\Policies\VMware, Inc.\VMware VDM\Client", "EnableShade", "False", "True") + }; + + public VmwareOverlayConfiguration(Guid groupId, ILogger logger, string sid, string userName) : base(groupId, logger, sid, userName) + { + } + } +} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/SignoutConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/SignoutConfiguration.cs deleted file mode 100644 index 4fb49060..00000000 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/SignoutConfiguration.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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; -using SafeExamBrowser.Contracts.Logging; - -namespace SafeExamBrowser.Lockdown.FeatureConfigurations -{ - [Serializable] - internal class SignoutConfiguration : FeatureConfiguration - { - public SignoutConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) - { - } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } - } -} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/TaskManagerConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/TaskManagerConfiguration.cs deleted file mode 100644 index 25a27eb9..00000000 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/TaskManagerConfiguration.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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; -using SafeExamBrowser.Contracts.Logging; - -namespace SafeExamBrowser.Lockdown.FeatureConfigurations -{ - [Serializable] - internal class TaskManagerConfiguration : FeatureConfiguration - { - public TaskManagerConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) - { - } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } - } -} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/UserLockConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/UserLockConfiguration.cs deleted file mode 100644 index 6d148e45..00000000 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/UserLockConfiguration.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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; -using SafeExamBrowser.Contracts.Logging; - -namespace SafeExamBrowser.Lockdown.FeatureConfigurations -{ - [Serializable] - internal class UserLockConfiguration : FeatureConfiguration - { - public UserLockConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) - { - } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } - } -} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/UserSwitchConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/UserSwitchConfiguration.cs deleted file mode 100644 index 3ea5a17c..00000000 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/UserSwitchConfiguration.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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; -using SafeExamBrowser.Contracts.Logging; - -namespace SafeExamBrowser.Lockdown.FeatureConfigurations -{ - [Serializable] - internal class UserSwitchConfiguration : FeatureConfiguration - { - public UserSwitchConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) - { - } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } - } -} diff --git a/SafeExamBrowser.Lockdown/FeatureConfigurations/VmwareOverlayConfiguration.cs b/SafeExamBrowser.Lockdown/FeatureConfigurations/VmwareOverlayConfiguration.cs deleted file mode 100644 index 86673861..00000000 --- a/SafeExamBrowser.Lockdown/FeatureConfigurations/VmwareOverlayConfiguration.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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; -using SafeExamBrowser.Contracts.Logging; - -namespace SafeExamBrowser.Lockdown.FeatureConfigurations -{ - [Serializable] - internal class VmwareOverlayConfiguration : FeatureConfiguration - { - public VmwareOverlayConfiguration(Guid groupId, ILogger logger) : base(groupId, logger) - { - } - - public override bool DisableFeature() - { - return true; - } - - public override bool EnableFeature() - { - return true; - } - - public override void Initialize() - { - - } - - public override void Monitor() - { - - } - - public override bool Restore() - { - return true; - } - } -} diff --git a/SafeExamBrowser.Lockdown/SafeExamBrowser.Lockdown.csproj b/SafeExamBrowser.Lockdown/SafeExamBrowser.Lockdown.csproj index 625c3272..50e185f8 100644 --- a/SafeExamBrowser.Lockdown/SafeExamBrowser.Lockdown.csproj +++ b/SafeExamBrowser.Lockdown/SafeExamBrowser.Lockdown.csproj @@ -60,19 +60,19 @@ - + - - - - - - - - - - - + + + + + + + + + + + @@ -82,8 +82,6 @@ SafeExamBrowser.Contracts - - - + \ No newline at end of file diff --git a/SafeExamBrowser.Service.UnitTests/Operations/LockdownOperationTests.cs b/SafeExamBrowser.Service.UnitTests/Operations/LockdownOperationTests.cs index ae83405f..aed98b29 100644 --- a/SafeExamBrowser.Service.UnitTests/Operations/LockdownOperationTests.cs +++ b/SafeExamBrowser.Service.UnitTests/Operations/LockdownOperationTests.cs @@ -83,17 +83,17 @@ namespace SafeExamBrowser.Service.UnitTests.Operations sut.Perform(); + factory.Verify(f => f.CreateChangePasswordConfiguration(It.Is(id => id == groupId), It.IsAny(), It.IsAny()), Times.Once); factory.Verify(f => f.CreateChromeNotificationConfiguration(It.Is(id => id == groupId), It.IsAny(), It.IsAny()), Times.Once); factory.Verify(f => f.CreateEaseOfAccessConfiguration(It.Is(id => id == groupId)), Times.Once); + factory.Verify(f => f.CreateLockWorkstationConfiguration(It.Is(id => id == groupId), It.IsAny(), It.IsAny()), Times.Once); factory.Verify(f => f.CreateNetworkOptionsConfiguration(It.Is(id => id == groupId)), Times.Once); - factory.Verify(f => f.CreatePasswordChangeConfiguration(It.Is(id => id == groupId)), Times.Once); factory.Verify(f => f.CreatePowerOptionsConfiguration(It.Is(id => id == groupId)), Times.Once); factory.Verify(f => f.CreateRemoteConnectionConfiguration(It.Is(id => id == groupId)), Times.Once); - factory.Verify(f => f.CreateSignoutConfiguration(It.Is(id => id == groupId)), Times.Once); - factory.Verify(f => f.CreateTaskManagerConfiguration(It.Is(id => id == groupId)), Times.Once); - factory.Verify(f => f.CreateUserLockConfiguration(It.Is(id => id == groupId)), Times.Once); - factory.Verify(f => f.CreateUserSwitchConfiguration(It.Is(id => id == groupId)), Times.Once); - factory.Verify(f => f.CreateVmwareOverlayConfiguration(It.Is(id => id == groupId)), Times.Once); + factory.Verify(f => f.CreateSignoutConfiguration(It.Is(id => id == groupId), It.IsAny(), It.IsAny()), Times.Once); + factory.Verify(f => f.CreateSwitchUserConfiguration(It.Is(id => id == groupId)), Times.Once); + factory.Verify(f => f.CreateTaskManagerConfiguration(It.Is(id => id == groupId), It.IsAny(), It.IsAny()), Times.Once); + factory.Verify(f => f.CreateVmwareOverlayConfiguration(It.Is(id => id == groupId), It.IsAny(), It.IsAny()), Times.Once); factory.Verify(f => f.CreateWindowsUpdateConfiguration(It.Is(id => id == groupId)), Times.Once); } diff --git a/SafeExamBrowser.Service.UnitTests/Operations/SessionInitializationOperationTests.cs b/SafeExamBrowser.Service.UnitTests/Operations/SessionInitializationOperationTests.cs index abe19126..85c2d1d1 100644 --- a/SafeExamBrowser.Service.UnitTests/Operations/SessionInitializationOperationTests.cs +++ b/SafeExamBrowser.Service.UnitTests/Operations/SessionInitializationOperationTests.cs @@ -13,6 +13,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Contracts.Communication.Hosts; using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Lockdown; using SafeExamBrowser.Contracts.Logging; @@ -25,7 +26,6 @@ namespace SafeExamBrowser.Service.UnitTests.Operations { private Mock autoRestoreMechanism; private Mock logger; - private Mock> logWriterFactory; private Mock serviceHost; private Mock> serviceEventFactory; private SessionContext sessionContext; @@ -36,20 +36,19 @@ namespace SafeExamBrowser.Service.UnitTests.Operations { autoRestoreMechanism = new Mock(); logger = new Mock(); - logWriterFactory = new Mock>(); serviceHost = new Mock(); serviceEventFactory = new Mock>(); sessionContext = new SessionContext(); - logWriterFactory.Setup(f => f.Invoke(It.IsAny())).Returns(new Mock().Object); serviceEventFactory.Setup(f => f.Invoke(It.IsAny())).Returns(new EventStub()); sessionContext.AutoRestoreMechanism = autoRestoreMechanism.Object; sessionContext.Configuration = new ServiceConfiguration { - AppConfig = new AppConfig { ServiceEventName = $"{nameof(SafeExamBrowser)}-{nameof(SessionInitializationOperationTests)}" } + AppConfig = new AppConfig { ServiceEventName = $"{nameof(SafeExamBrowser)}-{nameof(SessionInitializationOperationTests)}" }, + Settings = new Settings() }; - sut = new SessionInitializationOperation(logger.Object, logWriterFactory.Object, serviceEventFactory.Object, serviceHost.Object, sessionContext); + sut = new SessionInitializationOperation(logger.Object, serviceEventFactory.Object, serviceHost.Object, sessionContext); } [TestMethod] diff --git a/SafeExamBrowser.Service.UnitTests/ServiceControllerTests.cs b/SafeExamBrowser.Service.UnitTests/ServiceControllerTests.cs index c5560ed0..50fb6f94 100644 --- a/SafeExamBrowser.Service.UnitTests/ServiceControllerTests.cs +++ b/SafeExamBrowser.Service.UnitTests/ServiceControllerTests.cs @@ -12,6 +12,7 @@ using Moq; using SafeExamBrowser.Contracts.Communication.Events; using SafeExamBrowser.Contracts.Communication.Hosts; using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Logging; @@ -21,6 +22,7 @@ namespace SafeExamBrowser.Service.UnitTests public class ServiceControllerTests { private Mock logger; + private Mock> logWriterFactory; private Mock bootstrapSequence; private SessionContext sessionContext; private Mock sessionSequence; @@ -31,12 +33,15 @@ namespace SafeExamBrowser.Service.UnitTests public void Initialize() { logger = new Mock(); + logWriterFactory = new Mock>(); bootstrapSequence = new Mock(); sessionContext = new SessionContext(); sessionSequence = new Mock(); serviceHost = new Mock(); - sut = new ServiceController(logger.Object, bootstrapSequence.Object, sessionSequence.Object, serviceHost.Object, sessionContext); + logWriterFactory.Setup(f => f.Invoke(It.IsAny())).Returns(new Mock().Object); + + sut = new ServiceController(logger.Object, logWriterFactory.Object, bootstrapSequence.Object, sessionSequence.Object, serviceHost.Object, sessionContext); } [TestMethod] @@ -56,6 +61,28 @@ namespace SafeExamBrowser.Service.UnitTests Assert.AreEqual(args.Configuration.SessionId, sessionContext.Configuration.SessionId); } + [TestMethod] + public void Communication_MustInitializeSessionLogging() + { + var args = new SessionStartEventArgs + { + Configuration = new ServiceConfiguration + { + AppConfig = new AppConfig { ServiceLogFilePath = "Test.log" }, + SessionId = Guid.NewGuid(), + Settings = new Settings { LogLevel = LogLevel.Warning } + } + }; + + bootstrapSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success); + sessionSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success); + + sut.TryStart(); + serviceHost.Raise(h => h.SessionStartRequested += null, args); + + logger.VerifySet(l => l.LogLevel = It.Is(ll => ll == args.Configuration.Settings.LogLevel), Times.Once); + } + [TestMethod] public void Communication_MustNotAllowNewSessionDuringActiveSession() { @@ -73,6 +100,22 @@ namespace SafeExamBrowser.Service.UnitTests Assert.AreNotEqual(args.Configuration.SessionId, sessionContext.Configuration.SessionId); } + [TestMethod] + public void Communication_MustNotFailIfNoValidSessionData() + { + var args = new SessionStartEventArgs { Configuration = null }; + + bootstrapSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success); + sessionSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success); + + sut.TryStart(); + serviceHost.Raise(h => h.SessionStartRequested += null, args); + + sessionSequence.Verify(s => s.TryPerform(), Times.Once); + + Assert.IsNull(sessionContext.Configuration); + } + [TestMethod] public void Communication_MustStopActiveSessionUponRequest() { diff --git a/SafeExamBrowser.Service/CompositionRoot.cs b/SafeExamBrowser.Service/CompositionRoot.cs index 6d48b41c..144373d5 100644 --- a/SafeExamBrowser.Service/CompositionRoot.cs +++ b/SafeExamBrowser.Service/CompositionRoot.cs @@ -56,14 +56,14 @@ namespace SafeExamBrowser.Service bootstrapOperations.Enqueue(new CommunicationHostOperation(serviceHost, logger)); bootstrapOperations.Enqueue(new ServiceEventCleanupOperation(logger, sessionContext)); - sessionOperations.Enqueue(new SessionInitializationOperation(logger, LogWriterFactory, ServiceEventFactory, serviceHost, sessionContext)); + sessionOperations.Enqueue(new SessionInitializationOperation(logger, ServiceEventFactory, serviceHost, sessionContext)); sessionOperations.Enqueue(new LockdownOperation(featureBackup, featureFactory, logger, sessionContext)); sessionOperations.Enqueue(new SessionActivationOperation(logger, sessionContext)); var bootstrapSequence = new OperationSequence(logger, bootstrapOperations); var sessionSequence = new OperationSequence(logger, sessionOperations); - ServiceController = new ServiceController(logger, bootstrapSequence, sessionSequence, serviceHost, sessionContext); + ServiceController = new ServiceController(logger, LogWriterFactory, bootstrapSequence, sessionSequence, serviceHost, sessionContext); } private string BuildBackupFilePath() diff --git a/SafeExamBrowser.Service/Operations/LockdownOperation.cs b/SafeExamBrowser.Service/Operations/LockdownOperation.cs index db17b757..382a8750 100644 --- a/SafeExamBrowser.Service/Operations/LockdownOperation.cs +++ b/SafeExamBrowser.Service/Operations/LockdownOperation.cs @@ -40,17 +40,17 @@ namespace SafeExamBrowser.Service.Operations var userName = Context.Configuration.UserName; var configurations = new [] { + (factory.CreateChangePasswordConfiguration(groupId, sid, userName), Context.Configuration.Settings.Service.DisablePasswordChange), (factory.CreateChromeNotificationConfiguration(groupId, sid, userName), Context.Configuration.Settings.Service.DisableChromeNotifications), (factory.CreateEaseOfAccessConfiguration(groupId), Context.Configuration.Settings.Service.DisableEaseOfAccessOptions), + (factory.CreateLockWorkstationConfiguration(groupId, sid, userName), Context.Configuration.Settings.Service.DisableUserLock), (factory.CreateNetworkOptionsConfiguration(groupId), Context.Configuration.Settings.Service.DisableNetworkOptions), - (factory.CreatePasswordChangeConfiguration(groupId), Context.Configuration.Settings.Service.DisablePasswordChange), (factory.CreatePowerOptionsConfiguration(groupId), Context.Configuration.Settings.Service.DisablePowerOptions), (factory.CreateRemoteConnectionConfiguration(groupId), Context.Configuration.Settings.Service.DisableRemoteConnections), - (factory.CreateSignoutConfiguration(groupId), Context.Configuration.Settings.Service.DisableSignout), - (factory.CreateTaskManagerConfiguration(groupId), Context.Configuration.Settings.Service.DisableTaskManager), - (factory.CreateUserLockConfiguration(groupId), Context.Configuration.Settings.Service.DisableUserLock), - (factory.CreateUserSwitchConfiguration(groupId), Context.Configuration.Settings.Service.DisableUserSwitch), - (factory.CreateVmwareOverlayConfiguration(groupId), Context.Configuration.Settings.Service.DisableVmwareOverlay), + (factory.CreateSignoutConfiguration(groupId, sid, userName), Context.Configuration.Settings.Service.DisableSignout), + (factory.CreateSwitchUserConfiguration(groupId), Context.Configuration.Settings.Service.DisableUserSwitch), + (factory.CreateTaskManagerConfiguration(groupId, sid, userName), Context.Configuration.Settings.Service.DisableTaskManager), + (factory.CreateVmwareOverlayConfiguration(groupId, sid, userName), Context.Configuration.Settings.Service.DisableVmwareOverlay), (factory.CreateWindowsUpdateConfiguration(groupId), Context.Configuration.Settings.Service.DisableWindowsUpdate) }; diff --git a/SafeExamBrowser.Service/Operations/SessionInitializationOperation.cs b/SafeExamBrowser.Service/Operations/SessionInitializationOperation.cs index 096c7ae9..268a9df8 100644 --- a/SafeExamBrowser.Service/Operations/SessionInitializationOperation.cs +++ b/SafeExamBrowser.Service/Operations/SessionInitializationOperation.cs @@ -17,28 +17,22 @@ namespace SafeExamBrowser.Service.Operations internal class SessionInitializationOperation : SessionOperation { private ILogger logger; - private Func logWriterFactory; private Func serviceEventFactory; private IServiceHost serviceHost; - private ILogObserver sessionWriter; public SessionInitializationOperation( ILogger logger, - Func logWriterFactory, Func serviceEventFactory, IServiceHost serviceHost, SessionContext sessionContext) : base(sessionContext) { this.logger = logger; - this.logWriterFactory = logWriterFactory; this.serviceEventFactory = serviceEventFactory; this.serviceHost = serviceHost; } public override OperationResult Perform() { - InitializeSessionWriter(); - logger.Info("Initializing new session..."); logger.Info($" -> Client-ID: {Context.Configuration.AppConfig.ClientId}"); logger.Info($" -> Runtime-ID: {Context.Configuration.AppConfig.RuntimeId}"); @@ -85,8 +79,6 @@ namespace SafeExamBrowser.Service.Operations Context.Configuration = null; Context.IsRunning = false; - FinalizeSessionWriter(); - return success ? OperationResult.Success : OperationResult.Failed; } @@ -103,19 +95,5 @@ namespace SafeExamBrowser.Service.Operations Context.ServiceEvent = serviceEventFactory.Invoke(Context.Configuration.AppConfig.ServiceEventName); logger.Info("Service event successfully created."); } - - private void InitializeSessionWriter() - { - sessionWriter = logWriterFactory.Invoke(Context.Configuration.AppConfig.ServiceLogFilePath); - logger.Subscribe(sessionWriter); - logger.Debug($"Created session log file '{Context.Configuration.AppConfig.ServiceLogFilePath}'."); - } - - private void FinalizeSessionWriter() - { - logger.Debug("Closed session log file."); - logger.Unsubscribe(sessionWriter); - sessionWriter = null; - } } } diff --git a/SafeExamBrowser.Service/ServiceController.cs b/SafeExamBrowser.Service/ServiceController.cs index 21fba95d..d8f31d08 100644 --- a/SafeExamBrowser.Service/ServiceController.cs +++ b/SafeExamBrowser.Service/ServiceController.cs @@ -18,11 +18,13 @@ namespace SafeExamBrowser.Service { internal class ServiceController : IServiceController { - private readonly ILogger logger; + private ILogger logger; + private Func logWriterFactory; private IOperationSequence bootstrapSequence; private IOperationSequence sessionSequence; private IServiceHost serviceHost; private SessionContext sessionContext; + private ILogObserver sessionWriter; private ServiceConfiguration Session { @@ -36,12 +38,14 @@ namespace SafeExamBrowser.Service public ServiceController( ILogger logger, + Func logWriterFactory, IOperationSequence bootstrapSequence, IOperationSequence sessionSequence, IServiceHost serviceHost, SessionContext sessionContext) { this.logger = logger; + this.logWriterFactory = logWriterFactory; this.bootstrapSequence = bootstrapSequence; this.sessionSequence = sessionSequence; this.serviceHost = serviceHost; @@ -100,6 +104,7 @@ namespace SafeExamBrowser.Service private void StartSession() { + InitializeSessionLogging(); logger.Info(AppendDivider("Session Start Procedure")); var result = sessionSequence.TryPerform(); @@ -128,6 +133,8 @@ namespace SafeExamBrowser.Service { logger.Info(AppendDivider("Session Stop Failed")); } + + FinalizeSessionLogging(); } private void RegisterEvents() @@ -182,5 +189,28 @@ namespace SafeExamBrowser.Service return $"### {dashesLeft} {message} {dashesRight} ###"; } + + private void InitializeSessionLogging() + { + if (Session?.AppConfig?.ServiceLogFilePath != null) + { + sessionWriter = logWriterFactory.Invoke(Session.AppConfig.ServiceLogFilePath); + logger.Subscribe(sessionWriter); + logger.LogLevel = Session.Settings.LogLevel; + } + else + { + logger.Warn("Could not initialize session writer due to missing configuration data!"); + } + } + + private void FinalizeSessionLogging() + { + if (sessionWriter != null) + { + logger.Unsubscribe(sessionWriter); + sessionWriter = null; + } + } } }