/// <summary> /// Возвращает все группы из AD, имена которых удовлетворяют заданному фильтру /// </summary> /// <param name="groupFilter">Фильтр по имени группы.</param> /// <param name="args"></param> /// <returns></returns> public ADGroupCollection FindGroups( string groupFilter ) { try { using (DirectoryEntry entry = new DirectoryEntry( _groupPath, LdapUserName, ConfigurationManager.AppSettings["LdapPassword"] )) using (DirectorySearcher searcher = new DirectorySearcher( entry )) { searcher.SearchScope = SearchScope.Subtree; searcher.Filter = String.Format( @"(&(objectCategory=group)(name={0}))", groupFilter ); ADGroupCollection groups = new ADGroupCollection(); try { foreach (SearchResult result in searcher.FindAll()) groups.Add( new ADGroup( result ) ); } catch (ArgumentException) { } // неверная строка поиска return groups; } } catch (Exception ex) { throw new CoreApplicationException(Resources.ResourceManager.GetString("ErrorSearchingGroupException"), ex); } }
/// <summary> /// This method will return a list of objects representing all records in the table. /// </summary> /// /// <returns>list of objects of class ADGroup in the form of object of ADGroupCollection </returns> public ADGroupCollection SelectAll() { ADGroupCollection aDGroupCollection = new ADGroupCollection(); foreach (POS.DataLayer.ADGroup _aDGroup in POS.DataLayer.ADGroupBase.SelectAll()) { _aDGroupWCF = new ADGroup(); _aDGroupWCF.GroupID = _aDGroup.GroupID; _aDGroupWCF.GroupName = _aDGroup.GroupName; aDGroupCollection.Add(_aDGroupWCF); } return aDGroupCollection; }
/// <summary> /// This method will return a list of objects representing all records in the table. /// </summary> /// /// <returns>list of objects of class ADGroup in the form of object of ADGroupCollection </returns> public ADGroupCollection SelectAll() { ADGroupCollection aDGroupCollection = new ADGroupCollection(); foreach (POS.DataLayer.ADGroup _aDGroup in POS.DataLayer.ADGroupBase.SelectAll()) { _aDGroupWCF = new ADGroup(); _aDGroupWCF.GroupID = _aDGroup.GroupID; _aDGroupWCF.GroupName = _aDGroup.GroupName; aDGroupCollection.Add(_aDGroupWCF); } return(aDGroupCollection); }
/// <summary> /// This method will return a list of objects representing the specified number of entries from the specified record number in the table /// using the value of the field specified /// </summary> /// /// <param name="field" type="string">Field of the class ADGroup</param> /// <param name="fieldValue" type="object">Value for the field specified.</param> /// <param name="fieldValue2" type="object">Value for the field specified.</param> /// <param name="typeOperation" type="TypeOperation">Operator that is used if fieldValue2=null or fieldValue2="".</param> /// <param name="orderByStatement" type="string">The field value to number.</param> /// <param name="pageSize" type="int">Number of records returned.</param> /// <param name="skipPages" type="int">The number of missing pages.</param> /// /// <returns>List of object of class ADGroup in the form of an object of class ADGroupCollection</returns> public ADGroupCollection SelectByFieldPaged(string field, object fieldValue, object fieldValue2, TypeOperation typeOperation, int pageSize, int skipPages, string orderByStatement) { ADGroupCollection aDGroupCollection = new ADGroupCollection(); foreach (POS.DataLayer.ADGroup _aDGroup in POS.DataLayer.ADGroupBase.SelectByFieldPaged(field, fieldValue, fieldValue2, typeOperation, pageSize, skipPages, orderByStatement)) { _aDGroupWCF = new ADGroup(); _aDGroupWCF.GroupID = _aDGroup.GroupID; _aDGroupWCF.GroupName = _aDGroup.GroupName; aDGroupCollection.Add(_aDGroupWCF); } return(aDGroupCollection); }
/// <summary> /// This method will return a list of objects representing the specified number of entries from the specified record number in the table. /// </summary> /// /// <param name="pageSize" type="int">Number of records returned.</param> /// <param name="skipPages" type="int">The number of missing pages.</param> /// <param name="orderByStatement" type="string">The field value to number.</param> /// /// <returns>list of objects of class ADGroup in the form of an object of class ADGroupCollection </returns> public ADGroupCollection SelectAllPaged(int?pageSize, int?skipPages, string orderByStatement) { ADGroupCollection aDGroupCollection = new ADGroupCollection(); foreach (POS.DataLayer.ADGroup _aDGroup in POS.DataLayer.ADGroupBase.SelectAllPaged(pageSize, skipPages, orderByStatement)) { _aDGroupWCF = new ADGroup(); _aDGroupWCF.GroupID = _aDGroup.GroupID; _aDGroupWCF.GroupName = _aDGroup.GroupName; aDGroupCollection.Add(_aDGroupWCF); } return(aDGroupCollection); }
/// <summary> /// This method will get row(s) from the database using the value of the field specified /// </summary> /// /// <param name="field" type="string">Field of the class ADGroup</param> /// <param name="fieldValue" type="object">Value for the field specified.</param> /// <param name="fieldValue2" type="object">Value for the field specified.</param> /// <param name="typeOperation" type="TypeOperation">Operator that is used if fieldValue2=null or fieldValue2="".</param> /// /// <returns>List of object of class ADGroup in the form of an object of class ADGroupCollection</returns> public ADGroupCollection SelectByField(string field, object fieldValue, object fieldValue2, TypeOperation typeOperation) { ADGroupCollection aDGroupCollection = new ADGroupCollection(); foreach (POS.DataLayer.ADGroup _aDGroup in POS.DataLayer.ADGroupBase.SelectByField(field, fieldValue, fieldValue2, typeOperation)) { _aDGroupWCF = new ADGroup(); _aDGroupWCF.GroupID = _aDGroup.GroupID; _aDGroupWCF.GroupName = _aDGroup.GroupName; aDGroupCollection.Add(_aDGroupWCF); } return(aDGroupCollection); }
private void InitADGroupData() { IListADGroups.Clear(); IStrADPath = string.Format("LDAP://{0}", IStrADDomain); ADUtility util = new ADUtility(IStrADPath, IStrADUser, IStrADPassword); try { ADGroupCollection groups = util.GetAllGroups(); foreach (ADGroup group in groups.AllItem) { BindItem item = new BindItem(); item.Name = group.Name; item.Display = group.DisplayName; item.Obj = group; IListADGroups.Add(item); } } catch (Exception ex) { SubDebug(string.Format("Get all AD groups fail.\t{0}", ex.Message)); } }
private void InitDomainTree() { if (domainInfo == null) { return; } IStrADDomain = domainInfo.DomainName; IStrADPassword = domainInfo.DomainUserPassWord; IStrADUser = domainInfo.DomainUserName; if (IStrADDomain == string.Empty || IStrADPassword == string.Empty || IStrADUser == string.Empty) { return; } string LDAPInfo = string.Format("{0}:{1}({2}:{3})", CurrentApp.GetLanguageInfo("11011602", "域账号"), IStrADUser, CurrentApp.GetLanguageInfo("11011601", "域名"), IStrADDomain); IListADUsers.Clear(); List <BindItem> listItems = new List <BindItem>(); IStrADPath = string.Format("LDAP://{0}", IStrADDomain); util = new ADUtility(IStrADPath, IStrADUser, IStrADPassword); ClearChildren(mRoot); //树中会清理掉list里面的部分内容 mListDomainObjItem.Clear(); //清理剩余的内容 try { //获取下面所有的OU ADGroupCollection OUs = util.GetAllOrganizationalUnit(); foreach (ADGroup group in OUs.AllItem) { DomainObjectItem doi = new DomainObjectItem(); doi.Name = group.Name; doi.FullName = group.Name; doi.mGuid = group.Guid; doi.ObjType = 111; doi.IsChecked = false; doi.Icon = "Images/org.ico"; DirectoryEntry de = group.MyDirectoryEntry; doi.ParentGuid = de.Parent.Guid; doi.ParentName = de.Parent.Name.Substring(3); doi.ParentFullName = doi.ParentName; mListDomainObjItem.Add(doi); } //获取下面所有用户 ADUserCollection Users = util.GetAllUsers(); foreach (ADUser user in Users) { //判断用户是否禁用 int ControlCode = user.UserAccountControl; string UserControlCode = Convert.ToString(ControlCode, 2); UserControlCode = UserControlCode.Substring(UserControlCode.Count() - 2, 1); if (UserControlCode == "1") { continue; } DomainObjectItem doi = new DomainObjectItem(); doi.Name = user.Name.Substring(3).ToLower(); doi.FullName = user.AccountName; if (doi.FullName == string.Empty) { doi.FullName = string.Format("{0}@{1}", IStrADDomain.ToLower(), user.AccountFullName.ToLower()); } else { List <string> listsp = doi.FullName.Split('@').ToList(); if (listsp.Count == 2) { doi.FullName = string.Format("{0}@{1}", IStrADDomain.ToLower(), listsp[0].ToLower()); } } doi.mGuid = user.Guid; doi.ObjType = 112; doi.IsChecked = false; doi.Icon = "Images/user.ico"; DirectoryEntry de = user.MyDirectoryEntry; doi.ParentGuid = de.Parent.Guid; doi.ParentName = de.Parent.Name.Substring(3); doi.ParentFullName = doi.ParentName; mListDomainObjItem.Add(doi); } //====================================================================== //获取组织结构distinguishedName ADUser Duser = util.GetADUser(IStrADUser); //ADGroupCollection groups = Duser.MemberOf; object obj = Duser.GetProperty("distinguishedName"); string OUCollection = obj.ToString(); //拆分string,获取dc下的第一个机构 List <string> OUsName = OUCollection.Split(',').ToList(); int count = 0; string OUName = string.Empty; string DName = OUsName[OUsName.Count - 2]; for (; count < OUsName.Count(); count++) { string tempOU = OUsName[count]; if (tempOU.Substring(0, 2) == "OU") { OUName = tempOU.Substring(3); DomainObjectItem objItem = new DomainObjectItem(); objItem.Name = OUName; objItem.FullName = objItem.Name; objItem.ObjType = 111; objItem.IsChecked = false; objItem.Icon = "Images/org.ico"; mRoot.AddChild(objItem); mListDomainObjItem.Add(objItem); GetChild(objItem); break; } } if (OUName == string.Empty && count == OUsName.Count)//是域下面的用户,直接获取整个结构树 { mRoot.Name = DName.Substring(3); GetChild(mRoot); } } catch (Exception ex) { ShowException(string.Format("Get Users Info From LDAP Fail:{0}", ex.Message)); CurrentApp.WriteLog(string.Format("Get all AD users fail.\t{0}", ex.Message)); } }
/// <summary> /// Populates the fields for multiple objects from the columns found in an open reader. /// </summary> /// /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param> /// /// <returns>Object of ADGroupCollection</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 3/7/2015 2:37:00 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// internal static ADGroupCollection PopulateObjectsFromReaderWithCheckingReader(IDataReader rdr, DatabaseHelper oDatabaseHelper) { ADGroupCollection list = new ADGroupCollection(); if (rdr.Read()) { ADGroup obj = new ADGroup(); PopulateObjectFromReader(obj, rdr); list.Add(obj); while (rdr.Read()) { obj = new ADGroup(); PopulateObjectFromReader(obj, rdr); list.Add(obj); } oDatabaseHelper.Dispose(); return list; } else { oDatabaseHelper.Dispose(); return null; } }
/// <summary> /// Populates the fields for multiple objects from the columns found in an open reader. /// </summary> /// /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param> /// /// <returns>Object of ADGroupCollection</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 3/7/2015 2:37:00 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// internal static ADGroupCollection PopulateObjectsFromReader(IDataReader rdr) { ADGroupCollection list = new ADGroupCollection(); while (rdr.Read()) { ADGroup obj = new ADGroup(); PopulateObjectFromReader(obj,rdr); list.Add(obj); } return list; }
/// <summary> /// This method will get row(s) from the database using the value of the field specified /// </summary> /// /// <param name="field" type="string">Field of the class ADGroup</param> /// <param name="fieldValue" type="object">Value for the field specified.</param> /// <param name="fieldValue2" type="object">Value for the field specified.</param> /// <param name="typeOperation" type="TypeOperation">Operator that is used if fieldValue2=null or fieldValue2="".</param> /// /// <returns>List of object of class ADGroup in the form of an object of class ADGroupCollection</returns> public ADGroupCollection SelectByField(string field, object fieldValue, object fieldValue2, TypeOperation typeOperation) { ADGroupCollection aDGroupCollection = new ADGroupCollection(); foreach (POS.DataLayer.ADGroup _aDGroup in POS.DataLayer.ADGroupBase.SelectByField(field, fieldValue, fieldValue2, typeOperation)) { _aDGroupWCF = new ADGroup(); _aDGroupWCF.GroupID = _aDGroup.GroupID; _aDGroupWCF.GroupName = _aDGroup.GroupName; aDGroupCollection.Add(_aDGroupWCF); } return aDGroupCollection; }
/// <summary> /// This method will return a list of objects representing the specified number of entries from the specified record number in the table /// using the value of the field specified /// </summary> /// /// <param name="field" type="string">Field of the class ADGroup</param> /// <param name="fieldValue" type="object">Value for the field specified.</param> /// <param name="fieldValue2" type="object">Value for the field specified.</param> /// <param name="typeOperation" type="TypeOperation">Operator that is used if fieldValue2=null or fieldValue2="".</param> /// <param name="orderByStatement" type="string">The field value to number.</param> /// <param name="pageSize" type="int">Number of records returned.</param> /// <param name="skipPages" type="int">The number of missing pages.</param> /// /// <returns>List of object of class ADGroup in the form of an object of class ADGroupCollection</returns> public ADGroupCollection SelectByFieldPaged(string field, object fieldValue, object fieldValue2, TypeOperation typeOperation, int pageSize, int skipPages, string orderByStatement) { ADGroupCollection aDGroupCollection = new ADGroupCollection(); foreach (POS.DataLayer.ADGroup _aDGroup in POS.DataLayer.ADGroupBase.SelectByFieldPaged(field, fieldValue, fieldValue2, typeOperation, pageSize, skipPages, orderByStatement)) { _aDGroupWCF = new ADGroup(); _aDGroupWCF.GroupID = _aDGroup.GroupID; _aDGroupWCF.GroupName = _aDGroup.GroupName; aDGroupCollection.Add(_aDGroupWCF); } return aDGroupCollection; }
/// <summary> /// This method will return a list of objects representing the specified number of entries from the specified record number in the table. /// </summary> /// /// <param name="pageSize" type="int">Number of records returned.</param> /// <param name="skipPages" type="int">The number of missing pages.</param> /// <param name="orderByStatement" type="string">The field value to number.</param> /// /// <returns>list of objects of class ADGroup in the form of an object of class ADGroupCollection </returns> public ADGroupCollection SelectAllPaged(int? pageSize, int? skipPages, string orderByStatement) { ADGroupCollection aDGroupCollection = new ADGroupCollection(); foreach (POS.DataLayer.ADGroup _aDGroup in POS.DataLayer.ADGroupBase.SelectAllPaged(pageSize, skipPages, orderByStatement)) { _aDGroupWCF = new ADGroup(); _aDGroupWCF.GroupID = _aDGroup.GroupID; _aDGroupWCF.GroupName = _aDGroup.GroupName; aDGroupCollection.Add(_aDGroupWCF); } return aDGroupCollection; }
/// <summary> /// Возвращает постранично группы из AD, имена которых удовлетворяют заданному фильтру /// </summary> /// <param name="groupFilter">Фильтр по имени группы.</param> /// <param name="args"></param> /// <returns></returns> public PagingResult FindGroups( string groupFilter, PagingArgs args ) { try { using (DirectoryEntry entry = new DirectoryEntry( _groupPath, LdapUserName, ConfigurationManager.AppSettings["LdapPassword"] )) using (DirectorySearcher searcher = new DirectorySearcher( entry )) { searcher.SearchScope = SearchScope.Subtree; searcher.Sort.PropertyName = ADGroup.GetADPropertyName( args.SortExpression ); searcher.Sort.Direction = args.SortOrderASC ? SortDirection.Ascending : SortDirection.Descending; searcher.Filter = String.Format( @"(&(objectCategory=group)(name={0}))", groupFilter ); ADGroupCollection groups = new ADGroupCollection(); try { foreach (SearchResult result in searcher.FindAll()) groups.Add( new ADGroup( result ) ); } catch (ArgumentException) { } // неверная строка поиска return groups.GetPage( args ); } } catch (Exception ex) { throw new CoreApplicationException(Resources.ResourceManager.GetString("ErrorSearchingGroupException"), ex); } }
/// <summary> /// Возвращает список групп, членом которым является указанный пользователь /// </summary> /// <param name="userName">Имя пользователя (login name без указания домена)</param> /// <returns></returns> public ADGroupCollection GetUserGroupsMembeship( string userName ) { ADGroupCollection groups = new ADGroupCollection(); SearchResult searchResult = FindUserEntry( userName ); foreach (string groupDn in searchResult.Properties["memberOf"]) { ADGroup group = new ADGroup(); group.DN = groupDn; groups.Add( group ); } return groups; }