public async Task AddFilteredComputer()
        {
            try
            {
                if (this.objectSelectionProvider.GetComputers(this, out List <SecurityIdentifier> sids))
                {
                    foreach (SecurityIdentifier sid in sids)
                    {
                        SecurityIdentifierViewModel sidvm = await Task.Run(() => new SecurityIdentifierViewModel(sid, directory));

                        if (this.FilteredComputers.Any(t => string.Equals(t.Sid, sidvm.Sid, StringComparison.OrdinalIgnoreCase)))
                        {
                            continue;
                        }

                        this.FilteredComputers.Add(sidvm);
                    }
                }
            }
            catch (Exception ex)
            {
                this.logger.LogError(EventIDs.UIGenericError, ex, "Select group error");
                await this.dialogCoordinator.ShowMessageAsync(this, "Error", $"An error occurred when processing the request\r\n{ex.Message}");
            }
        }
        public void RemoveAllowedPrincipal()
        {
            SecurityIdentifierViewModel selected = this.SelectedAllowedPrincipal;

            if (selected == null)
            {
                return;
            }

            this.model.AllowedPrincipals.Remove(selected.Sid);
            this.AllowedPrincipals.Remove(selected);
        }
        private void BuildAllowedToAuthenticateList()
        {
            this.AllowedPrincipals.Clear();

            foreach (var item in this.model.AllowedPrincipals)
            {
                if (item.TryParseAsSid(out SecurityIdentifier sid))
                {
                    SecurityIdentifierViewModel vm = new SecurityIdentifierViewModel(sid, directory);
                    this.AllowedPrincipals.Add(vm);
                }
            }
        }
        private void BuildAllowedToAuthenticateList()
        {
            this.AllowedPrincipals.Clear();

            foreach (var item in this.model.AllowedPrincipals)
            {
                if (item.TryParseAsSid(out SecurityIdentifier sid))
                {
                    SecurityIdentifierViewModel vm = new SecurityIdentifierViewModel
                    {
                        Sid         = sid.ToString(),
                        DisplayName = this.GetSidDisplayName(sid)
                    };

                    this.AllowedPrincipals.Add(vm);
                }
            }
        }
        public async Task AddAllowedPrincipal()
        {
            try
            {
                if (this.objectSelectionProvider.GetUserOrGroup(this, out SecurityIdentifier sid))
                {
                    SecurityIdentifierViewModel sidvm = new SecurityIdentifierViewModel(sid, directory);

                    if (this.model.AllowedPrincipals.Any(t => string.Equals(t, sidvm.Sid, StringComparison.OrdinalIgnoreCase)))
                    {
                        return;
                    }

                    this.model.AllowedPrincipals.Add(sidvm.Sid);
                    this.AllowedPrincipals.Add(sidvm);
                }
            }
            catch (Exception ex)
            {
                this.logger.LogError(EventIDs.UIGenericError, ex, "Select group error");
                await this.dialogCoordinator.ShowMessageAsync(this, "Error", $"An error occurred when processing the request\r\n{ex.Message}");
            }
        }
        public async Task AddAllowedPrincipal()
        {
            try
            {
                ExternalDialogWindow w = new ExternalDialogWindow();
                w.Title = "Select forest";
                var vm = new SelectForestViewModel();
                w.DataContext         = vm;
                w.SaveButtonName      = "Next...";
                w.SaveButtonIsDefault = true;
                vm.AvailableForests   = new List <string>();
                var domain = Domain.GetCurrentDomain();
                vm.AvailableForests.Add(domain.Forest.Name);
                vm.SelectedForest = domain.Forest.Name;

                foreach (var trust in domain.Forest.GetAllTrustRelationships().OfType <TrustRelationshipInformation>())
                {
                    if (trust.TrustDirection == TrustDirection.Inbound || trust.TrustDirection == TrustDirection.Bidirectional)
                    {
                        vm.AvailableForests.Add(trust.TargetName);
                    }
                }

                w.Owner = this.GetWindow();

                if (!w.ShowDialog() ?? false)
                {
                    return;
                }

                DsopScopeInitInfo scope = new DsopScopeInitInfo();
                scope.Filter = new DsFilterFlags();

                scope.Filter.UpLevel.BothModeFilter = DsopObjectFilterFlags.DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE | DsopObjectFilterFlags.DSOP_FILTER_GLOBAL_GROUPS_SE | DsopObjectFilterFlags.DSOP_FILTER_UNIVERSAL_GROUPS_SE | DsopObjectFilterFlags.DSOP_FILTER_USERS | DsopObjectFilterFlags.DSOP_FILTER_WELL_KNOWN_PRINCIPALS;

                scope.ScopeType = DsopScopeTypeFlags.DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN | DsopScopeTypeFlags.DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE | DsopScopeTypeFlags.DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN;

                scope.InitInfo = DsopScopeInitInfoFlags.DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS | DsopScopeInitInfoFlags.DSOP_SCOPE_FLAG_STARTING_SCOPE;

                string target = vm.SelectedForest == domain.Forest.Name ? null : vm.SelectedForest;

                var result = NativeMethods.ShowObjectPickerDialog(this.GetHandle(), target, scope, "objectClass", "objectSid").FirstOrDefault();

                if (result != null)
                {
                    byte[] sidraw = result.Attributes["objectSid"] as byte[];
                    if (sidraw == null)
                    {
                        return;
                    }

                    SecurityIdentifierViewModel sidvm = new SecurityIdentifierViewModel();
                    var sid = new SecurityIdentifier(sidraw, 0);
                    sidvm.Sid = sid.ToString();

                    if (this.model.AllowedPrincipals.Any(t => string.Equals(t, sidvm.Sid, StringComparison.OrdinalIgnoreCase)))
                    {
                        return;
                    }

                    sidvm.DisplayName = this.GetSidDisplayName(sid);

                    this.model.AllowedPrincipals.Add(sidvm.Sid);
                    this.AllowedPrincipals.Add(sidvm);
                }
            }
            catch (Exception ex)
            {
                this.logger.LogError(EventIDs.UIGenericError, ex, "Select group error");
                await this.dialogCoordinator.ShowMessageAsync(this, "Error", $"An error occurred when processing the request\r\n{ex.Message}");
            }
        }