public SecurityViewModel(SecuritySettingsTO securitySettings, IResourcePickerDialog resourcePicker, DirectoryObjectPickerDialog directoryObjectPicker, IWin32Window parentWindow, IEnvironmentModel environment)
        {
            VerifyArgument.IsNotNull("resourcePicker", resourcePicker);
            VerifyArgument.IsNotNull("directoryObjectPicker", directoryObjectPicker);
            VerifyArgument.IsNotNull("parentWindow", parentWindow);
            VerifyArgument.IsNotNull("environment", environment);

            _resourcePicker = resourcePicker;
            _directoryObjectPicker = directoryObjectPicker;
            _parentWindow = parentWindow;
            _environment = environment;
            _directoryObjectPicker.AllowedObjectTypes = ObjectTypes.BuiltInGroups | ObjectTypes.Groups;
            _directoryObjectPicker.DefaultObjectTypes = ObjectTypes.Groups;
            _directoryObjectPicker.AllowedLocations = Locations.All;
            _directoryObjectPicker.DefaultLocations = Locations.JoinedDomain;
            _directoryObjectPicker.MultiSelect = false;
            _directoryObjectPicker.TargetComputer = string.Empty;
            _directoryObjectPicker.ShowAdvancedView = false;

            PickWindowsGroupCommand = new DelegateCommand(PickWindowsGroup);
            PickResourceCommand = new DelegateCommand(PickResource);

            InitializeHelp();

            InitializePermissions(securitySettings == null ? null : securitySettings.WindowsGroupPermissions);
        }
 public void SecuritySettingsTO_Contructor_CallBasicCtor_WindowsGroupPermissionsEmpty()
 {
     //------------Execute Test---------------------------
     var securitySettingsTO = new SecuritySettingsTO();
     //------------Assert Results-------------------------
     Assert.IsNotNull(securitySettingsTO.WindowsGroupPermissions);
     Assert.AreEqual(0, securitySettingsTO.WindowsGroupPermissions.Count);
 }
 public void SecuritySettingsTO_Contructor_CallOverloadedCtor_WindowsGroupPermissionsEmpty()
 {
     //------------Setup for test--------------------------
     List<WindowsGroupPermission> permissions = new List<WindowsGroupPermission>();
     permissions.Add(new WindowsGroupPermission());
     permissions.Add(new WindowsGroupPermission());
     //------------Execute Test---------------------------
     var securitySettingsTO = new SecuritySettingsTO(permissions);
     //------------Assert Results-------------------------
     Assert.IsNotNull(securitySettingsTO.WindowsGroupPermissions);
     Assert.AreEqual(2, securitySettingsTO.WindowsGroupPermissions.Count);
 }
 public void SecurityWrite_Execute_SecuritySettingsValuePassedValidJSON_ShouldWriteFile()
 {
     //------------Setup for test--------------------------
     var permission = new WindowsGroupPermission { Administrator = true, IsServer = true, WindowsGroup = Environment.UserName };
     var windowsGroupPermissions = new List<WindowsGroupPermission> { permission };
     var securitySettings = new SecuritySettingsTO(windowsGroupPermissions) { CacheTimeout = new TimeSpan(0, 2, 0) };
     var securitySettingsValue = JsonConvert.SerializeObject(securitySettings);
     var securityWrite = new SecurityWrite();
     //------------Execute Test---------------------------
     securityWrite.Execute(new Dictionary<string, StringBuilder> { { "SecuritySettings", new StringBuilder(securitySettingsValue) } }, null);
     //------------Assert Results-------------------------
     Assert.IsTrue(File.Exists("secure.config"));
     var fileData = File.ReadAllText("secure.config");
     Assert.IsFalse(fileData.StartsWith("{"));
     Assert.IsFalse(fileData.EndsWith("}"));
     Assert.IsFalse(fileData.Contains("IsServer"));
     File.Delete("secure.config");
 }
        public void SettingsRead_Execute_SecurityReadDoesNotThrowException_HasErrorsIsFalseAndSecurityPermissionsAreAssigned()
        {
            //------------Setup for test--------------------------
            var securityPermissions = new List<WindowsGroupPermission>
            {
                new WindowsGroupPermission { IsServer = true, WindowsGroup = "TestGroup", Permissions = AuthorizationContext.DeployFrom.ToPermissions() },
                new WindowsGroupPermission { IsServer = true, WindowsGroup = "NETWORK SERVICE", Permissions = AuthorizationContext.DeployTo.ToPermissions() }
            };

            var securitySettingsTO = new SecuritySettingsTO(securityPermissions);

            var securityRead = new Func<IEsbManagementEndpoint>(() =>
            {
                var endpoint = new Mock<IEsbManagementEndpoint>();
                endpoint.Setup(e => e.Execute(It.IsAny<Dictionary<string, StringBuilder>>(), It.IsAny<IWorkspace>()))
                    .Returns(new Dev2JsonSerializer().SerializeToBuilder(securitySettingsTO));

                return endpoint.Object;
            });

            var settingsRead = new TestSettingsRead(securityRead);

            //------------Execute Test---------------------------
            var jsonPermissions = settingsRead.Execute(null, null);
            var settings = JsonConvert.DeserializeObject<Settings>(jsonPermissions.ToString());

            //------------Assert Results-------------------------
            Assert.IsNotNull(settings);
            Assert.IsNotNull(settings.Security);
            Assert.IsFalse(settings.HasError);

            var comparer = new WindowsGroupPermissionEqualityComparer();
            Assert.AreEqual(2, settings.Security.WindowsGroupPermissions.Count);

            for(var i = 0; i < securityPermissions.Count; i++)
            {
                var result = comparer.Equals(securityPermissions[i], settings.Security.WindowsGroupPermissions[i]);
                Assert.IsTrue(result);
            }
        }
예제 #6
0
        public StringBuilder Execute(Dictionary<string, StringBuilder> values, IWorkspace theWorkspace)
        {
            if(File.Exists(ServerSecurityService.FileName))
            {
                string encryptedData;
                using(var inStream = new FileStream(ServerSecurityService.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using(var reader = new StreamReader(inStream))
                    {
                        encryptedData = reader.ReadToEnd();
                    }
                }

                try
                {
                    var decryptData = SecurityEncryption.Decrypt(encryptedData);
                    var currentSecuritySettingsTo = JsonConvert.DeserializeObject<SecuritySettingsTO>(decryptData);
                    var permissionGroup = currentSecuritySettingsTo.WindowsGroupPermissions;

                    // We need to change BuiltIn\Administrators to -> Warewolf Administrators ;)
                    if(permissionGroup.Count > 0)
                    {
                        var adminGrp = permissionGroup[0].WindowsGroup;
                        if(adminGrp == "BuiltIn\\Administrators")
                        {
                            permissionGroup[0].WindowsGroup = WindowsGroupPermission.BuiltInAdministratorsText;
                            decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                        }
                    }

                    var hasGuestPermission = permissionGroup.Any(permission => permission.IsBuiltInGuests);
                    var hasAdminPermission = permissionGroup.Any(permission => permission.IsBuiltInAdministrators);
                    if(!hasAdminPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateAdministrators());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    if(!hasGuestPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateGuests());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    return new StringBuilder(decryptData);
                }
                catch(Exception e)
                {
                    Dev2Logger.Log.Error("SecurityRead", e);
                }
            }

            var serializer = new Dev2JsonSerializer();
            var securitySettingsTo = new SecuritySettingsTO(DefaultPermissions) { CacheTimeout = _cacheTimeout };
            return serializer.SerializeToBuilder(securitySettingsTo);
        }
        public void SecurityRead_Execute_WhenSecureConfigDoesExistWithNoGuestPermission_ShouldHaveExistingPermissionsAndGuest()
        {
            //------------Setup for test--------------------------
            if(File.Exists("secure.config"))
            {
                File.Delete("secure.config");
            }
            var permission = new WindowsGroupPermission { Administrator = true, IsServer = true, WindowsGroup = Environment.UserName };
            var permission2 = new WindowsGroupPermission { Administrator = false, DeployFrom = false, IsServer = true, WindowsGroup = "NETWORK SERVICE" };
            var windowsGroupPermissions = new List<WindowsGroupPermission> { permission, permission2 };
            var securitySettings = new SecuritySettingsTO(windowsGroupPermissions) { CacheTimeout = new TimeSpan(0, 10, 0) };
            var serializeObject = JsonConvert.SerializeObject(securitySettings);
            var securityWrite = new SecurityWrite();
            var securityRead = new SecurityRead();
            securityWrite.Execute(new Dictionary<string, StringBuilder> { { "SecuritySettings", new StringBuilder(serializeObject) } }, null);
            //------------Assert Preconditions-------------------------
            Assert.IsTrue(File.Exists("secure.config"));
            //------------Execute Test---------------------------
            var jsonPermissions = securityRead.Execute(null, null);
            File.Delete("secure.config");
            var readSecuritySettings = JsonConvert.DeserializeObject<SecuritySettingsTO>(jsonPermissions.ToString());
            //------------Assert Results-------------------------
            Assert.AreEqual(4, readSecuritySettings.WindowsGroupPermissions.Count);
            var guestPermission = readSecuritySettings.WindowsGroupPermissions.FirstOrDefault(p => p.WindowsGroup == WindowsGroupPermission.BuiltInGuestsText);
            Assert.IsNotNull(guestPermission);
            Assert.AreEqual(true, guestPermission.IsServer);
            Assert.AreEqual(false, guestPermission.View);
            Assert.AreEqual(false, guestPermission.Execute);
            Assert.AreEqual(false, guestPermission.Contribute);
            Assert.AreEqual(false, guestPermission.DeployTo);
            Assert.AreEqual(false, guestPermission.DeployFrom);
            Assert.AreEqual(false, guestPermission.Administrator);

            var networkServicePermission = readSecuritySettings.WindowsGroupPermissions.FirstOrDefault(p => p.WindowsGroup == "NETWORK SERVICE");
            Assert.IsNotNull(networkServicePermission);
            Assert.AreEqual(true, networkServicePermission.IsServer);
            Assert.AreEqual(false, networkServicePermission.View);
            Assert.AreEqual(false, networkServicePermission.Execute);
            Assert.AreEqual(false, networkServicePermission.Contribute);
            Assert.AreEqual(false, networkServicePermission.DeployTo);
            Assert.AreEqual(false, networkServicePermission.DeployFrom);
            Assert.AreEqual(false, networkServicePermission.Administrator);

            var userPermission = readSecuritySettings.WindowsGroupPermissions.FirstOrDefault(p => p.WindowsGroup == Environment.UserName);
            Assert.IsNotNull(userPermission);
            Assert.AreEqual(true, userPermission.IsServer);
            Assert.AreEqual(false, userPermission.View);
            Assert.AreEqual(false, userPermission.Execute);
            Assert.AreEqual(false, userPermission.Contribute);
            Assert.AreEqual(false, userPermission.DeployTo);
            Assert.AreEqual(false, userPermission.DeployFrom);
            Assert.AreEqual(true, userPermission.Administrator);

            Assert.AreEqual(new TimeSpan(0, 10, 0), readSecuritySettings.CacheTimeout);
        }
        public void SecurityWrite_Write_SecuritySettingsIsNotNull_PersistsSecuritySettings()
        {
            //------------Setup for test--------------------------
            if(File.Exists(ServerSecurityService.FileName))
            {
                File.Delete(ServerSecurityService.FileName);
            }

            var securitySettings = new SecuritySettingsTO();

            //------------Execute Test---------------------------
            SecurityWrite.Write(securitySettings);

            //------------Assert Results-------------------------
            Assert.IsTrue(File.Exists(ServerSecurityService.FileName));
            File.Delete(ServerSecurityService.FileName);
        }
예제 #9
0
 public override void Save(SecuritySettingsTO securitySettings)
 {
     SaveHitCount++;
     base.Save(securitySettings);
 }
예제 #10
0
 public TestSecurityViewModel(SecuritySettingsTO securitySettings, IResourcePickerDialog resourcePicker, DirectoryObjectPickerDialog directoryObjectPicker, IWin32Window parentWindow, IEnvironmentModel environment)
     : base(securitySettings, resourcePicker, directoryObjectPicker, parentWindow, environment)
 {
 }
 internal SecurityViewModel(SecuritySettingsTO securitySettings, IWin32Window parentWindow, IEnvironmentModel environment)
     : this(securitySettings, new ResourcePickerDialog(enDsfActivityType.All, environment), new DirectoryObjectPickerDialog(), parentWindow, environment)
 {
 }
        public virtual void Save(SecuritySettingsTO securitySettings)
        {
            VerifyArgument.IsNotNull("securitySettings", securitySettings);

            securitySettings.WindowsGroupPermissions.Clear();
            Copy(ServerPermissions, securitySettings.WindowsGroupPermissions);
            Copy(ResourcePermissions, securitySettings.WindowsGroupPermissions);
        }
예제 #13
0
 public static void Write(SecuritySettingsTO securitySettingsTo)
 {
     VerifyArgument.IsNotNull("securitySettingsTO", securitySettingsTo);
     var securitySettings = new Dev2JsonSerializer().SerializeToBuilder(securitySettingsTo);
     Write(securitySettings);
 }
        static void Verify_Constructor_InitializesProperties(SecuritySettingsTO securitySettingsTO)
        {
            //------------Execute Test---------------------------
            var viewModel = new SecurityViewModel(securitySettingsTO, new Mock<IResourcePickerDialog>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IWin32Window>().Object, new Mock<IEnvironmentModel>().Object);

            //------------Assert Results-------------------------
            Assert.IsTrue(viewModel.CloseHelpCommand.CanExecute(null));
            Assert.IsNotNull(viewModel.PickResourceCommand);
            Assert.IsTrue(viewModel.PickResourceCommand.CanExecute(null));
            Assert.IsNotNull(viewModel.PickWindowsGroupCommand);
            Assert.IsTrue(viewModel.PickWindowsGroupCommand.CanExecute(null));
            Assert.IsNotNull(viewModel.ServerPermissions);
            Assert.IsNotNull(viewModel.ResourcePermissions);

            var serverPerms = securitySettingsTO == null ? new List<WindowsGroupPermission>() : securitySettingsTO.WindowsGroupPermissions.Where(p => p.IsServer).ToList();
            var resourcePerms = securitySettingsTO == null ? new List<WindowsGroupPermission>() : securitySettingsTO.WindowsGroupPermissions.Where(p => !p.IsServer).ToList();

            // constructor adds an extra "new"  permission
            Assert.AreEqual(serverPerms.Count + 1, viewModel.ServerPermissions.Count);
            Assert.AreEqual(resourcePerms.Count + 1, viewModel.ResourcePermissions.Count);
        }
        public void SecurityViewModel_Constructor_AllParametersValid_PropertiesInitialized()
        {
            //------------Setup for test--------------------------
            var permissions = new[]
            {
                new WindowsGroupPermission
                {
                    IsServer = true, WindowsGroup = "Deploy Admins",
                    View = false, Execute = false, Contribute = false, DeployTo = true, DeployFrom = true, Administrator = false
                },

                new WindowsGroupPermission
                {
                    ResourceID = Guid.NewGuid(), ResourceName = "Category1\\Workflow1",
                    WindowsGroup = "Windows Group 1", View = false, Execute = true, Contribute = false
                }
            };
            var securitySettingsTO = new SecuritySettingsTO(permissions);

            Verify_Constructor_InitializesProperties(securitySettingsTO);
        }
        public void SecurityViewModel_Save_DeletedPermissions_DeletedPermissionsAreRemoved()
        {
            //------------Setup for test--------------------------          
            var permissions = CreatePermissions();

            var deletedPermission = permissions[permissions.Count - 1];
            deletedPermission.IsDeleted = true;

            var viewModel = new SecurityViewModel(new SecuritySettingsTO(permissions), new Mock<IResourcePickerDialog>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IWin32Window>().Object, new Mock<IEnvironmentModel>().Object);

            var target = new SecuritySettingsTO();

            var expectedCount = permissions.Count - 1;
            var expectedResourceCount = viewModel.ResourcePermissions.Count - 1;

            //------------Execute Test---------------------------
            viewModel.Save(target);

            //------------Assert Results-------------------------
            Assert.AreEqual(expectedCount, target.WindowsGroupPermissions.Count);
            Assert.AreEqual(expectedResourceCount, viewModel.ResourcePermissions.Count);
            foreach (var permission in target.WindowsGroupPermissions)
            {
                Assert.IsTrue(permission.IsValid);
                Assert.IsFalse(permission.IsNew);
            }
            Assert.AreEqual(1, viewModel.ResourcePermissions.Count(p => p.IsNew));
            Assert.AreEqual(1, viewModel.ServerPermissions.Count(p => p.IsNew));
        }