/// <summary> /// Gets the group. /// </summary> /// <returns>The user.</returns> /// <param name="DN">The Disitnguesh name of the group</param> /// <param name="_listCN">If true the members will only contain the CN</param> public Group GetGroup(string DN, Boolean _listCN = false, Boolean _searchByCN = false) { var sMgmt = LdapQueryManager.Instance; try { LdapEntry entry; if (!_searchByCN) { entry = sMgmt.GetRegister(DN); } else { var results = sMgmt.ExecuteSearch("", "(&(objectClass=group)(cn=" + LdapInjectionControll.EscapeForSearchFilter(DN) + "))"); if (results.Count == 0) { logger.Debug("Group not found {0}", DN); return(null); } entry = results.First(); } var group = ConvertfromLdap(entry, _listCN); return(group); } catch (LdapException ex) { logger.Debug("Group not found {0} Ex: {1}", DN, ex.Message); return(null); } }
/// <summary> /// Gets the user. /// </summary> /// <returns>The user.</returns> /// <param name="DN">The Disitnguesh name of the user</param> /// <<param name="attribute">Optional attribute to use as search base</param> public User GetUser(string userID, string attribute = "") { var sMgmt = LdapQueryManager.Instance; try { LdapEntry entry; if (attribute != "") { var results = sMgmt.ExecutePagedSearch("", "(&(objectClass=user)(objectCategory=person)(" + LdapInjectionControll.EscapeForSearchFilter(attribute) + "=" + LdapInjectionControll.EscapeForSearchFilter(userID) + "))"); if (results.Entries.Count == 0) { logger.Debug("User not found {0}", userID); return(null); } entry = results.Entries.First(); } else { entry = sMgmt.GetRegister(userID, userAttrs); } //entry = sMgmt.GetRegister(userID); var user = ConvertfromLdap(entry); return(user); }catch (LdapException ex) { logger.Debug("User not found {0} Ex: {1}", userID, ex.Message); return(null); } }