Represents a common dialog that allows a user to select directory objects.

The directory object picker dialog box enables a user to select one or more objects from either the global catalog, a Microsoft Windows 2000 domain or computer, a Microsoft Windows NT 4.0 domain or computer, or a workgroup. The object types from which a user can select include user, contact, group, and computer objects.

This managed class wraps the Directory Object Picker common dialog from the Active Directory UI.

It simplifies the scope (Locations) and filter (ObjectTypes) selection by allowing a single filter to be specified which applies to all scopes (translating to both up-level and down-level filter flags as necessary).

The object type filter is also simplified by combining different types of groups (local, global, etc) and not using individual well known types in down-level scopes (only all well known types can be specified).

The scope location is also simplified by combining down-level and up-level variations into a single locations flag, e.g. external domains.

Inheritance: System.Windows.Forms.CommonDialog
        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 static bool SelectAccount(System.Windows.Forms.IWin32Window parent, string targetComputerName, ref string acctName, out bool isGroup, out bool isService, out string sid)
 {
     Locations l = Locations.EnterpriseDomain | Locations.ExternalDomain | Locations.GlobalCatalog | Locations.JoinedDomain | Locations.LocalComputer;
     DirectoryObjectPickerDialog dlg = new DirectoryObjectPickerDialog() { TargetComputer = targetComputerName, MultiSelect = false, SkipDomainControllerCheck = true, AllowedLocations = l, DefaultLocations = l };
     dlg.AllowedObjectTypes = ObjectTypes.Users; // | ObjectTypes.WellKnownPrincipals | ObjectTypes.Computers;
     if (NativeMethods.AccountUtils.CurrentUserIsAdmin(targetComputerName)) dlg.AllowedObjectTypes |= ObjectTypes.BuiltInGroups | ObjectTypes.Groups;
     dlg.DefaultObjectTypes = dlg.AllowedObjectTypes;
     dlg.AttributesToFetch.Add("objectSid");
     if (dlg.ShowDialog(parent) == System.Windows.Forms.DialogResult.OK)
     {
         if (dlg.SelectedObject != null)
         {
             try
             {
                 if (!String.IsNullOrEmpty(dlg.SelectedObject.Upn))
                     acctName = NameTranslator.TranslateUpnToDownLevel(dlg.SelectedObject.Upn);
                 else
                     acctName = dlg.SelectedObject.Name;
             }
             catch
             {
                 acctName = dlg.SelectedObject.Name;
             }
             sid = AttrToString(dlg.SelectedObject.FetchedAttributes[0]);
             isGroup = dlg.SelectedObject.SchemaClassName.Equals("Group", StringComparison.OrdinalIgnoreCase);
             isService = NativeMethods.AccountUtils.UserIsServiceAccount(acctName);
             return true;
         }
     }
     isGroup = isService = false;
     sid = null;
     return false;
 }
Exemple #3
0
        public SchedulerViewModel(IEventAggregator eventPublisher, DirectoryObjectPickerDialog directoryObjectPicker, IPopupController popupController, IAsyncWorker asyncWorker, IConnectControlViewModel connectControlViewModel)
            : base(eventPublisher)
        {
            VerifyArgument.IsNotNull("directoryObjectPicker", directoryObjectPicker);
            DirectoryObjectPickerDialog directoryObjectPicker1 = directoryObjectPicker;

            VerifyArgument.IsNotNull("popupController", popupController);
            _popupController = popupController;

            VerifyArgument.IsNotNull("asyncWorker", asyncWorker);
            _asyncWorker = asyncWorker;

            IsLoading = false;
            directoryObjectPicker1.AllowedObjectTypes = ObjectTypes.Users;
            directoryObjectPicker1.DefaultObjectTypes = ObjectTypes.Users;
            directoryObjectPicker1.AllowedLocations = Locations.All;
            directoryObjectPicker1.DefaultLocations = Locations.JoinedDomain;
            directoryObjectPicker1.MultiSelect = false;
            directoryObjectPicker1.TargetComputer = string.Empty;
            directoryObjectPicker1.ShowAdvancedView = false;

            InitializeHelp();

            var taskServiceConvertorFactory = new TaskServiceConvertorFactory();
            SchedulerFactory = new ClientSchedulerFactory(new Dev2TaskService(taskServiceConvertorFactory), taskServiceConvertorFactory);
            ConnectControlViewModel = connectControlViewModel ?? new ConnectControlViewModel(OnServerChanged, "Server: ", false);
        }
Exemple #4
0
        // ReSharper disable TooManyDependencies
        public SchedulerViewModelForTesting(IEventAggregator eventPublisher, DirectoryObjectPickerDialog directoryObjectPicker, IPopupController popupController, IAsyncWorker asyncWorker)
            // ReSharper restore TooManyDependencies
            : base(eventPublisher, directoryObjectPicker, popupController, asyncWorker, new Mock<IConnectControlViewModel>().Object)
        {

        }
        public SchedulerViewModelForTest(IEventAggregator eventPublisher, DirectoryObjectPickerDialog directoryObjectPicker, IPopupController popupController, IAsyncWorker asyncWorker)
            : base(eventPublisher, directoryObjectPicker, popupController, asyncWorker, new Mock<IConnectControlViewModel>().Object)
        {

        }
 public TestSecurityViewModel(SecuritySettingsTO securitySettings, IResourcePickerDialog resourcePicker, DirectoryObjectPickerDialog directoryObjectPicker, IWin32Window parentWindow, IEnvironmentModel environment)
     : base(securitySettings, resourcePicker, directoryObjectPicker, parentWindow, environment)
 {
 }
Exemple #7
0
        private void BrowseBTN_Click(object sender, EventArgs e)
        {            
            try
            {
                DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog();

                picker.AllowedObjectTypes = CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.Computers | CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.BuiltInGroups | CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.Groups | CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.Users | CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.WellKnownPrincipals;
                picker.DefaultObjectTypes = picker.AllowedObjectTypes;
                picker.AllowedLocations = CubicOrange.Windows.Forms.ActiveDirectory.Locations.All;
                picker.DefaultLocations = CubicOrange.Windows.Forms.ActiveDirectory.Locations.All;
                picker.MultiSelect = false;
                picker.TargetComputer = null;
                
                if (picker.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                } 
                
                DirectoryObject[] results = picker.SelectedObjects;

                if (results == null || results.Length != 1)
                {
                    return;
                }

                if (!String.IsNullOrEmpty(results[0].Path))
                {
                    string path = results[0].Path;                    
                    string[] fields = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                    string domain  = fields[fields.Length-2];
                    string account = fields[fields.Length-1];

                    if (String.Compare(domain, System.Net.Dns.GetHostName(), StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        m_identity = new NTAccount(account);
                    }
                    else
                    {
                        m_identity = new NTAccount(domain, account);
                    }
                }
                else
                {
                    m_identity = new NTAccount(results[0].Name);
                }

                if (m_identity != null)
                {
                    IdentityNameTB.Text = m_identity.ToString();
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception);
            }
        }
        /// <summary>
        /// ADs the object picker show dialog.
        /// </summary>
        /// <param name="handle">The owner handle.</param>
        /// <param name="showLocalUsersAndGroups">if set to <c>true</c> [show local users and groups].</param>
        /// <param name="showOnlyUsers">if set to <c>true</c> [show only users].</param>
        /// <param name="multipleSelection">if set to <c>true</c> [multiple selection].</param>
        /// <returns></returns>
        public static ADObject[] ADObjectPickerShowDialog(IWin32Window owner, bool showLocalUsersAndGroups, bool showOnlyUsers, bool multipleSelection)
        {
            #region OLD CODE
            //try
            //{
            //    // Initialize 1st search scope

            //    uint flType = 0;

            //    flType = flType |
            //        DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN |
            //        DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN |
            //        DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN |
            //        DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_GLOBAL_CATALOG |
            //        DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN |
            //        DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN |
            //        DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE |
            //        DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE;
            //    //DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_WORKGROUP;

            //    if (showLocalUsersAndGroups)
            //        flType = flType | DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_TARGET_COMPUTER;

            //    uint flScope =
            //        DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP |
            //        DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS |
            //        DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT |
            //        DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_STARTING_SCOPE |
            //        DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_WANT_DOWNLEVEL_BUILTIN_PATH; // Starting !?;

            //    if (!showOnlyUsers)
            //        flScope = flScope | DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS;

            //    uint flBothModes =
            //        DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_INCLUDE_ADVANCED_VIEW |
            //        DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_USERS;

            //    if (!showOnlyUsers)
            //        flBothModes = flBothModes |
            //        DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_BUILTIN_GROUPS |
            //        //DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_DOMAIN_LOCAL_GROUPS_DL |
            //        DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE |
            //        //DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_GLOBAL_GROUPS_DL |
            //        DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_GLOBAL_GROUPS_SE |
            //        //DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_UNIVERSAL_GROUPS_DL |
            //        DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_UNIVERSAL_GROUPS_SE |
            //        DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_WELL_KNOWN_PRINCIPALS;

            //    uint flDownlevel =
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_ANONYMOUS |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_AUTHENTICATED_USER |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_BATCH |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_CREATOR_GROUP |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_CREATOR_OWNER |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_DIALUP |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_INTERACTIVE |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_LOCAL_SERVICE |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_NETWORK |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_NETWORK_SERVICE |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_REMOTE_LOGON |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_SERVICE |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_SYSTEM |
            //        //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_TERMINAL_SERVER |
            //        DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_USERS;
            //    //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_WORLD;

            //    if (!showOnlyUsers)
            //    {
            //        flDownlevel = flDownlevel
            //            | DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS
            //            | DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS
            //            | DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS;
            //    }

            //    ADObjectPickerClass cadObjectPicker = new ADObjectPickerClass();
            //    cadObjectPicker.InitInfo_OptionFlags = DSOP_INIT_INFO_FLAGS.DSOP_FLAG_SKIP_TARGET_COMPUTER_DC_CHECK;
            //    if (multipleSelection)
            //    {
            //        cadObjectPicker.InitInfo_OptionFlags = cadObjectPicker.InitInfo_OptionFlags
            //            | DSOP_INIT_INFO_FLAGS.DSOP_FLAG_MULTISELECT;
            //    }

            //    cadObjectPicker.ScopeTypeFlags = flType;
            //    cadObjectPicker.ScopeFlags = flScope;
            //    cadObjectPicker.UplevelFilterFlags_Both = flBothModes;
            //    cadObjectPicker.DownLevelFilterFlags = flDownlevel;
            //    cadObjectPicker.InvokeDialog(handle.ToInt32());
            //    ADObjectColl result = (ADObjectColl)cadObjectPicker.ADObjectsColl;
            //    ADObject[] results = new ADObject[result.Count];
            //    for (uint j = 1; j <= result.Count; j++)
            //    {
            //        try
            //        {
            //            int i = (int)j;
            //            ADObjectInfo info = (ADObjectInfo)result.Item(i);
            //            results[j - 1] = new ADObject();
            //            results[j - 1].ADSPath = info.ADPath;
            //            results[j - 1].ClassName = info.Class;
            //            results[j - 1].Name = info.Name;
            //            results[j - 1].UPN = info.UPN;
            //        }
            //        catch
            //        {
            //            continue;
            //        }
            //    }
            //    return results;
            //}
            //catch (System.ArgumentException)
            //{
            //    return new ADObject[0];
            //}
            #endregion OLD CODE
            try
            {
                // Show dialog
                DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog();
                ObjectTypes allowedTypes = ObjectTypes.None;

                if (!showOnlyUsers)
                    allowedTypes = ObjectTypes.BuiltInGroups | ObjectTypes.Groups | ObjectTypes.Users | ObjectTypes.WellKnownPrincipals;
                else
                    allowedTypes = ObjectTypes.Users;
                ObjectTypes defaultTypes = allowedTypes;
                picker.AllowedObjectTypes = allowedTypes;
                picker.DefaultObjectTypes = defaultTypes;
                Locations allowedLocations = Locations.None;
                Locations defaultLocations = Locations.None;
                if (showLocalUsersAndGroups)
                {
                    allowedLocations = Locations.All;
                    defaultLocations = Locations.GlobalCatalog | Locations.EnterpriseDomain | Locations.ExternalDomain | Locations.JoinedDomain;
                    if (Environment.MachineName.Equals(Environment.UserDomainName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        //NOT JOINED TO A DOMAIN
                        defaultLocations |= Locations.LocalComputer;
                    }
                }
                else
                {
                    allowedLocations = Locations.GlobalCatalog | Locations.EnterpriseDomain | Locations.ExternalDomain | Locations.JoinedDomain;
                    defaultLocations = Locations.GlobalCatalog | Locations.EnterpriseDomain | Locations.ExternalDomain | Locations.JoinedDomain;
                }
                picker.AllowedLocations = allowedLocations;
                picker.DefaultLocations = defaultLocations;
                picker.MultiSelect = multipleSelection;
                picker.ShowAdvancedView = true;
                DialogResult dialogResult = picker.ShowDialog(owner);
                if (dialogResult == DialogResult.OK)
                {
                    if (picker.SelectedObjects == null)
                    {
                        return new ADObject[0];
                    }
                    ADObject[] results = new ADObject[picker.SelectedObjects.Length];
                    for (int j = 0; j < picker.SelectedObjects.Length; j++)
                    {
                        try
                        {
                            DirectoryObject info = (DirectoryObject)picker.SelectedObjects[j];
                            results[j] = new ADObject();
                            results[j].ADSPath = info.Path;
                            results[j].ClassName = info.SchemaClassName;
                            results[j].Name = info.Name;
                            results[j].UPN = info.Upn;
                        }
                        catch
                        {
                            continue;
                        }
                    }
                    return results;
                }
                else
                {
                    return new ADObject[0];
                }
            }
            catch
            {
                return new ADObject[0];
            }
        }