示例#1
0
        /// <summary>
        /// Used to find All groups list in active directory
        /// </summary>
        /// <param name="directoryEntry">Domain connection</param>
        /// <returns>Returns active directory groups list</returns>
        public List <Groups> FindAllGroups(string ldapurl, Domain domainObject, List <string> activeGroupsList)
        {
            var directoryServer   = new DirectoryServerDataAccess();
            var directoryEntry    = directoryServer.DomainConnection(ldapurl, domainObject);
            var directorySearcher = new DirectorySearcher(directoryEntry);

            directorySearcher.Filter = "(objectClass=group)";
            var groupList = new List <Groups>();
            var groups    = directorySearcher.FindAll();

            foreach (SearchResult group in groups)
            {
                DirectoryEntry DE = group.GetDirectoryEntry();
                try
                {
                    if (!activeGroupsList.Contains(DE.Properties["name"].Value.ToString().ToLower()))
                    {
                        groupList.Add(new Groups
                        {
                            GroupId          = Guid.Parse(DE.Guid.ToString()),
                            GroupName        = DE.Properties["name"].Value.ToString(),
                            GroupDescription =
                                DE.Properties["description"].Value != null
                                    ? DE.Properties["description"].Value.ToString()
                                    : String.Empty
                        });
                    }
                }
                catch
                {
                }
            }
            return(groupList);
        }
示例#2
0
        /// <summary>
        /// Used to delete a specific objects
        /// </summary>
        /// <param name="domainObject">Domain properties</param>
        /// <param name="objects">Object properties</param>
        /// <param name="distinguishedConnectionURL">Connection url for specific object</param>
        public void DeleteObjects(Domain domainObject, Objects objects, string distinguishedConnectionURL)
        {
            try
            {
                var dataAccessObject  = new DirectoryServerDataAccess();
                var _domainConnection = dataAccessObject.DomainConnection(distinguishedConnectionURL, domainObject);
                var dirEntry          = dataAccessObject.ObjectConnection(distinguishedConnectionURL, domainObject);

                _domainConnection.Children.Remove(dirEntry);
                //Console.WriteLine("user deleted successfully");
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Message:" + ex);
            }
        }
示例#3
0
        /// <summary>
        /// Used to unlock the specific user account
        /// </summary>
        /// <param name="dataAccess">Domain connection</param>
        /// <param name="userObject">User properties</param>
        /// <param name="objects">Object properties</param>
        /// <param name="domainObject">Domain properties</param>
        public void UnlockUserAccount(DirectoryEntry dataAccess, Users userObject, Objects objects, Domain domainObject)
        {
            try
            {
                var function_object             = new SecurityFunctions();
                var _distinguishedConnectionURL = function_object.DistinguishedConnectionURL(dataAccess, objects);
                var data_access_object          = new DirectoryServerDataAccess();

                var directoryEntry = data_access_object.ObjectConnection(_distinguishedConnectionURL, domainObject);
                directoryEntry.Properties["lockoutTime"].Value = 0;
                directoryEntry.CommitChanges();
                //Console.WriteLine("UnLock success");
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Message:" + ex);
            }
        }
示例#4
0
        /// <summary>
        /// Used to change user passwords
        /// </summary>
        /// <param name="dataAccess">Domain connection</param>
        /// <param name="userObject">User properties</param>
        /// <param name="domainObject">Domain properties</param>
        /// <param name="objects">Object properties</param>
        public void PasswordChange(DirectoryEntry dataAccess, Users userObject, Domain domainObject, Objects objects)
        {
            try
            {
                var function_object             = new SecurityFunctions();
                var _distinguishedConnectionURL = function_object.DistinguishedConnectionURL(dataAccess, objects);
                var dataAccessObject            = new DirectoryServerDataAccess();

                var dirEntry = dataAccessObject.ObjectConnection(_distinguishedConnectionURL, domainObject);
                dirEntry.Invoke("SetPassword", new object[] { userObject.Password });
                dirEntry.Properties["LockOutTime"].Value = 0; //unlock account
                dirEntry.Close();
                //Console.WriteLine("Reset password success");
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Message:" + ex);
            }
        }
示例#5
0
        /// <summary>
        /// User to remove a specific member from specific group
        /// </summary>
        /// <param name="dataAccess">Domain connection</param>
        /// <param name="userObject">User properties</param>
        /// <param name="objects">Object properties</param>
        /// <param name="domainObject">Domain properties</param>
        /// <param name="_distinguishedConnectionURL">Connection url for specific group</param>
        public void RemoveMemberfromGroup(DirectoryEntry dataAccess, Users userObject, Objects objects, Domain domainObject, string _distinguishedConnectionURL)
        {
            try
            {
                var securityFunction = new SecurityFunctions();
                var dataAccessObject = new DirectoryServerDataAccess();

                var dirEntry = dataAccessObject.ObjectConnection(_distinguishedConnectionURL, domainObject);
                var userDn   = securityFunction.DistinguishedName(dataAccess, objects);
                dirEntry.Properties["member"].Remove(userDn);
                //Console.WriteLine("You successfully add member to group");
                dirEntry.CommitChanges();
                dirEntry.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Message:" + ex);
            }
        }
示例#6
0
        /// <summary>
        /// Used to disable the specific user account
        /// </summary>
        /// <param name="dataAccess">Domain connection</param>
        /// <param name="userObject">User properties</param>
        /// <param name="objects">Object properties</param>
        /// <param name="domainObject">Domain properties</param>
        public void DisableUserAccount(DirectoryEntry dataAccess, Users userObject, Objects objects, Domain domainObject)
        {
            try
            {
                var function_object             = new SecurityFunctions();
                var _distinguishedConnectionURL = function_object.DistinguishedConnectionURL(dataAccess, objects);
                var data_access_object          = new DirectoryServerDataAccess();

                var dirEntry = data_access_object.ObjectConnection(_distinguishedConnectionURL, domainObject);
                var val      = (int)dirEntry.Properties["userAccountControl"].Value;
                dirEntry.Properties["userAccountControl"].Value = val | 0x2;;
                dirEntry.CommitChanges();
                dirEntry.Close();
                //Console.WriteLine("Disable success");
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Message:" + ex);
            }
        }