public static LdapUser CreateFromResult([NotNull] LdapSearchResult result) { return(new LdapUser { Id = new Guid(result.Entry.GetAttribute("objectGuid").ByteValue), Email = result.Entry.GetAttribute("mail").StringValue }); }
/// <summary> /// Add the new result to the collection /// </summary> /// <param name="result">The result to be collected</param> /// <returns>The index position it was added to.</returns> public int Add(LdapSearchResult result) { int idx = -1; idx = List.Add(result); if ( OnNew != null ) { LdapSearchResultCollectionEventArgs args = new LdapSearchResultCollectionEventArgs(result, SmartChangeType.New); OnNew(this, args); } return idx; }
private string getStringRepresentaionOfEventInformation() { StringBuilder buf = new StringBuilder(); LdapSearchResult result = (LdapSearchResult)ldap_message; buf.AppendFormat("(Entry={0})", result.Entry); LdapControl[] controls = result.Controls; if (null != controls) { buf.Append("(Controls="); int i = 0; foreach (LdapControl control in controls) { buf.AppendFormat("(Control{0}={1})", ++i, control.ToString()); } buf.Append(")"); } return(buf.ToString()); }
/// <summary> /// Get the properties specific to the LDAP entry. /// </summary> protected override LdapSearchResult CreateSearchEntry(Hashtable ht) { LdapSearchResult ee = new LdapSearchResult(); #region User Information if( ht.ContainsKey("cn") ) ee.DisplayName = ht["cn"].ToString(); if( ht.ContainsKey("displayname") ) ee.DistinguishName = ht["displayname"].ToString(); if( ht.ContainsKey("givenname") ) ee.GivenName = ht["givenname"].ToString(); if( ht.ContainsKey("sn") ) ee.Surname = ht["sn"].ToString(); if( ht.ContainsKey("uid") ) ee.Alias = ht["uid"].ToString(); // Check that the display name has something if not then // use the alias if ( ee.DisplayName.Length == 0 && ee.Alias.Length > 0 ) ee.DisplayName = ee.Alias; // If both of the common Name and Alias is blank then // find use AdsPath and get the CN from that. if ( ht.ContainsKey("adspath") == true && ee.DisplayName.Length == 0 && ee.Alias.Length == 0) { string path = ht["adspath"].ToString().ToLower(SmartResourceManager.CurrentCulture); int start = path.IndexOf("cn=") + 3; int len = path.IndexOf(",",start) - start; ee.DisplayName = ht["adspath"].ToString().Substring(start,len); } if( ht.ContainsKey("adspath") ) ee.AdsPath = ht["adspath"].ToString(); if( ht.ContainsKey("objectclass") ) { ee.ResultType = LdapSearchResultType.Object; string[] classTypes = ht["objectclass"].ToString().Split(','); foreach( string classType in classTypes ) { switch( classType.ToLower(System.Threading.Thread.CurrentThread.CurrentCulture) ) { case "organizationalperson": case "person": ee.ResultType = LdapSearchResultType.User; break; case "groupofnames": ee.ResultType = LdapSearchResultType.Group; break; } if ( ee.ResultType != LdapSearchResultType.Object ) break; } } // Workout the Novell Login Info. string tree = ""; string org = ""; if( ht.ContainsKey("federationboundary") ) tree = ht["federationboundary"].ToString(); if ( ee.AdsPath.Length > 0 ) { int start = ee.AdsPath.IndexOf("o="); int end = ee.AdsPath.IndexOf(",", start); if ( end == -1 ) end = ee.AdsPath.Length; int len = end - start; org = ee.AdsPath.Substring(start, len); } StringBuilder user = new StringBuilder(); user.AppendFormat("{0}.{1}{2}{3}", ee.DisplayName, org, (tree.Length > 0 ? "." : ""), tree); ee.DomainAccount = user.ToString(); #endregion #region Business Info if( ht.ContainsKey("company") ) ee.Company = ht["company"].ToString(); if( ht.ContainsKey("department") ) ee.Department = ht["department"].ToString(); if( ht.ContainsKey("title") ) ee.Title = ht["title"].ToString(); if( ht.ContainsKey("telephonenumber") ) ee.TelephoneNumber = ht["telephonenumber"].ToString(); #endregion #region Address Information StringBuilder addr = new StringBuilder(); if( ht.ContainsKey("postaladdress") ) addr.AppendFormat("{0}{1}", ht["postaladdress"].ToString(), (ht["postaladdress"].ToString().Length > 0 ? Environment.NewLine : "")); if( ht.ContainsKey("postalcode") ) addr.AppendFormat("{0}{1}", ht["postalcode"].ToString(), (ht["postalcode"].ToString().Length > 0 ? Environment.NewLine : "")); if( ht.ContainsKey("l") ) addr.AppendFormat("{0}{1}", ht["l"].ToString(), (ht["l"].ToString().Length > 0 ? Environment.NewLine : "")); if( ht.ContainsKey("st") ) addr.AppendFormat("{0}{1}", ht["st"].ToString(), (ht["st"].ToString().Length > 0 ? Environment.NewLine : "")); if( ht.ContainsKey("homecountry") ) addr.AppendFormat("{0}{1}", ht["homecountry"].ToString(), (ht["homecountry"].ToString().Length > 0 ? Environment.NewLine : "")); ee.Address = addr.ToString().Trim(); #endregion #region Email Inforamation if( ht.ContainsKey("mail") ) { ee.EmailAddress = ht["mail"].ToString(); ee.SmtpAddress = ht["mail"].ToString(); } #endregion return ee; }
/// <summary> /// This method will return the list of members that belong to the group specified on /// the LDAP server. /// </summary> /// <param name="group">The group to search for</param> /// <returns>The array of search results</returns> public override LdapSearchResult[] RetrieveGroupMembers(LdapSearchResult group) { string msg = SmartResourceManager.GetString("INVALID_OP_NOVELL", "Workshare.Common.Exceptions.Resources", Assembly.GetAssembly(typeof(LdapNovellSearchEngine)), SmartResourceManager.CurrentCulture); throw new InvalidOperationException(msg); }
public Response <UserInfoDirectory[]> getUsersActiveDirectory() { Response <UserInfoDirectory[]> response = new Response <UserInfoDirectory[]> { }; try { _connection.Connect(_config.Url, LdapConnection.DEFAULT_PORT); _connection.Bind(_config.BindDn, _config.BindCredentials); var result = _connection.Search( "OU=divkum,DC=divkum,DC=polri,DC=go,DC=id", LdapConnection.SCOPE_SUB, string.Format("objectclass=person"), new[] { "cn", "displayName", "title" }, false, null, null ); LdapMessage message; List <UserInfoDirectory> dns = new List <UserInfoDirectory> { }; int xx = 0; while ((message = result.getResponse()) != null) { xx++; if (!(message is LdapResponse xxxx)) { LdapSearchResult entry = (LdapSearchResult)message; var read = _connection.Read(entry.Entry.DN); var ds = read.getAttribute("displayName"); string displayName = ds != null?read.getAttribute("displayName").StringValue : "empty"; var uids = read.getAttribute("cn"); string uid = uids != null?read.getAttribute("cn").StringValue : "empty"; var ts = read.getAttribute("title"); string title = ts != null?read.getAttribute("title").StringValue : "empty"; dns.Add(new UserInfoDirectory { DisplayName = displayName, Username = uid, //Title = title }); } // /* * if (!(message is LdapResponse xxxx)) * { * LdapSearchResult entry = (LdapSearchResult)message; * var read = _connection.Read(entry.Entry.DN); * * * //{LdapEntry: cn=Dan Jump,ou=users,dc=contoso,dc=com; LdapAttributeSet: LdapAttribute: {type='title', value='CEO'} LdapAttribute: {type='userPassword', value='{SHA}RKkNn7+KoG94IN3x/B2jnm/4DS0='} LdapAttribute: {type='gidNumber', value='70001'} LdapAttribute: {type='displayName', value='Dan Jump'} LdapAttribute: {type='uid', value='danj'} LdapAttribute: {type='homeDirectory', value='/home/danj'} LdapAttribute: {type='mail', value='*****@*****.**'} LdapAttribute: {type='objectClass', values='inetOrgPerson','person','organizationalPerson','posixAccount','top'} LdapAttribute: {type='givenName', value='Dan'} LdapAttribute: {type='cn', value='Dan Jump'} LdapAttribute: {type='sn', value='Jump'} LdapAttribute: {type='telephoneNumber', value='(425) 555-0179'} LdapAttribute: {type='uidNumber', value='70000'}} * // read.getAttribute("").StringValue; * * * dns.Add(new UserInfoDirectory { * DisplayName=read.getAttribute("displayName").StringValue, * Username = read.getAttribute("uid").StringValue, * //DN = entry.Entry.DN, * Title = read.getAttribute("title").StringValue * * }); * }*/ if (!(message is LdapSearchResult searchResultMessage)) { continue; } } response.message_type = 1; response.data = dns.ToArray(); } catch (Exception exc) { throw new Exception("Search Error" + exc.Message); } _connection.Disconnect(); return(response); }
/// <summary> /// Creates a new instance of LdapSearchEventArgs which will contain the entry that fired the event /// </summary> public LdapSearchEventArgs(LdapSearchResult entry, bool isSelected) { m_isSelected = isSelected; m_entry = entry; }
/// <summary> /// Get the properties specific to the LDAP entry. /// </summary> protected override LdapSearchResult CreateSearchEntry(Hashtable ht) { LdapSearchResult ee = new LdapSearchResult(); #region User Information if( ht.ContainsKey("cn") ) ee.DisplayName = ht["cn"].ToString(); if( ht.ContainsKey("distinguishedname") ) ee.DistinguishName = ht["distinguishedname"].ToString(); if( ht.ContainsKey("givenname") ) ee.GivenName = ht["givenname"].ToString(); if( ht.ContainsKey("sn") ) ee.Surname = ht["sn"].ToString(); if( ht.ContainsKey("uid") ) ee.Alias = ht["uid"].ToString(); if( ht.ContainsKey("objectsid") ) if ( ht["objectsid"].GetType() == typeof(byte[]) ) ee.CreateAccountInfo((byte[])ht["objectsid"]); if( ht.ContainsKey("adspath") ) ee.AdsPath = ht["adspath"].ToString(); if( ht.ContainsKey("objectclass") ) { ee.ResultType = LdapSearchResultType.Object; string[] classTypes = ht["objectclass"].ToString().Split(','); foreach( string classType in classTypes ) { switch( classType.ToLower(System.Threading.Thread.CurrentThread.CurrentCulture) ) { case "organizationalperson": case "person": case "user": ee.ResultType = LdapSearchResultType.User; break; case "group": ee.ResultType = LdapSearchResultType.Group; break; } if ( ee.ResultType != LdapSearchResultType.Object ) break; } } #endregion #region Business Info if( ht.ContainsKey("company") ) ee.Company = ht["company"].ToString(); if( ht.ContainsKey("department") ) ee.Department = ht["department"].ToString(); if( ht.ContainsKey("title") ) ee.Title = ht["title"].ToString(); if( ht.ContainsKey("telephonenumber") ) ee.TelephoneNumber = ht["telephonenumber"].ToString(); #endregion #region Address Information StringBuilder addr = new StringBuilder(); if( ht.ContainsKey("postaladdress") ) addr.AppendFormat("{0}{1}", ht["postaladdress"].ToString(), (ht["postaladdress"].ToString().Length > 0 ? Environment.NewLine : "")); if( ht.ContainsKey("postalcode") ) addr.AppendFormat("{0}{1}", ht["postalcode"].ToString(), (ht["postalcode"].ToString().Length > 0 ? Environment.NewLine : "")); if( ht.ContainsKey("l") ) addr.AppendFormat("{0}{1}", ht["l"].ToString(), (ht["l"].ToString().Length > 0 ? Environment.NewLine : "")); if( ht.ContainsKey("st") ) addr.AppendFormat("{0}{1}", ht["st"].ToString(), (ht["st"].ToString().Length > 0 ? Environment.NewLine : "")); if( ht.ContainsKey("co") ) addr.AppendFormat("{0}{1}", ht["co"].ToString(), (ht["co"].ToString().Length > 0 ? Environment.NewLine : "")); ee.Address = addr.ToString().Trim(); #endregion #region Email Inforamation if( ht.ContainsKey("mail") ) { ee.EmailAddress = ht["mail"].ToString(); ee.SmtpAddress = ht["mail"].ToString(); } #endregion return ee; }
/// <summary> /// Does the specified column exist in the collection /// </summary> /// <param name="value">Column to check for</param> /// <returns>True if it does</returns> public bool Contains( LdapSearchResult value ) { // If value is not of type SmartListControlColumn, this will return false. return( List.Contains( value ) ); }
/// <summary> /// This method will process the LDAP group to extract the individual user /// accounts out and then add these. It will call itself if the there are /// embedded groups. /// </summary> /// <param name="group">The group to be processed</param> private void ProcessLdapGroup( LdapSearchResult group ) { LdapSearchResult[] members = m_ldap.RetrieveGroupMembers(group); foreach( LdapSearchResult entry in members ) { if ( entry.ResultType == LdapSearchResultType.Group ) ProcessLdapGroup(entry); else AddLdapMemberToList( entry ); } }
/// <summary> /// Remove the specified column /// </summary> /// <param name="value">Column to be removed</param> public void Remove( LdapSearchResult value ) { List.Remove( value ); if ( OnRemoved != null ) { LdapSearchResultCollectionEventArgs args = new LdapSearchResultCollectionEventArgs(value, SmartChangeType.Removed); OnRemoved(this, args); } }
/// <summary> /// Insert the Search Result at the specified position /// </summary> /// <param name="index">Index position</param> /// <param name="value">The Search Result to insearch</param> public void Insert( int index, LdapSearchResult value ) { List.Insert( index, value ); if ( OnInserted != null ) { LdapSearchResultCollectionEventArgs args = new LdapSearchResultCollectionEventArgs(value, SmartChangeType.New); OnInserted(this, args); } }
/// <summary> /// Get the index position of the search result /// </summary> /// <param name="result">The search result to search for</param> /// <returns>Index position found or -1 if not found</returns> public int IndexOf(LdapSearchResult result) { return List.IndexOf(result); }
/// <summary> /// Provide the strongly typed Copy To function /// </summary> /// <param name="array">An array of columns</param> /// <param name="index">The index start position</param> public void CopyTo(LdapSearchResult[] array, int index) { List.CopyTo(array,index); }
/// <summary> /// This method will return the list of members that belong to the group specified on /// the LDAP server. /// </summary> /// <param name="group">The group to search for</param> /// <returns>The array of search results</returns> public virtual LdapSearchResult[] RetrieveGroupMembers(LdapSearchResult group) { ArrayList ees = new ArrayList(); SearchResultCollection src = SearchLdap("groupOfNames", "member", "cn", group.DisplayName); foreach( SearchResult sr in src ) { foreach( string str in sr.Properties.PropertyNames ) { if ( str == "member" ) { foreach( string mem in sr.Properties[str] ) { // Work out the RDN from the LDAP string string prop = mem.ToLower(SmartResourceManager.CurrentCulture); int start = prop.IndexOf("cn=") + 3; int end = prop.IndexOf(",",prop.IndexOf("cn=")); int len = end - start; string member = prop.Substring(start, len ); SearchResultCollection memberSearch = SearchLdap(m_defaultClass, m_groupAttribute, member); LdapSearchResult lsr = null; foreach( SearchResult mems in memberSearch ) { Hashtable ht = SearchForProperties(mems, SearchProperties); lsr = CreateSearchEntry(ht); break; } if ( lsr != null ) ees.Add(lsr); } break; } } } src.Dispose(); return (LdapSearchResult[])ees.ToArray(typeof(LdapSearchResult)); }
/// <summary> /// This method will add the LDAP entry to the list /// </summary> /// <param name="member">The LDAP entry to be added</param> private void AddLdapMemberToList( LdapSearchResult member ) { // Make sure we have not already added this to the list if ( m_listView.Rows.ContainsValue("email", member.DisplayName) == false ) { if ( member != null ) { SmartRow rc = new SmartRow((member.ResultType == LdapSearchResultType.Group ? 0 : 2)); if ( member.DomainAccount == "[No Domain Account]" ) { rc.IconNumber = 1; m_numberInvalid++; } SmartColumnValue scv1 = new SmartColumnValue("email", member.DisplayName); SmartColumnValue scv2 = new SmartColumnValue("role",m_defValue); rc.Columns.Add(scv1); rc.Columns.Add(scv2); rc.Tag = member; m_listView.Rows.Add(rc); } } pbMain.Value += 1; if ( pbMain.Value >= 100 ) pbMain.Value = 50; Application.DoEvents(); }
/// <summary> /// Creates a new instance of LDAP Search Result which will contain the entry that fired the event /// </summary> public LdapSearchResultCollectionEventArgs(LdapSearchResult entry, SmartChangeType type) { m_type = type; m_entry = entry; }
/// <summary> /// Get the properties specific to the LDAP entry. /// </summary> protected override LdapSearchResult CreateSearchEntry(Hashtable ht) { LdapSearchResult ee = new LdapSearchResult(); #region User Information object item = ht["cn"]; if (item != null) { ee.DisplayName = item.ToString(); } item = ht["distinguishedname"]; if (item != null) { ee.DistinguishName = item.ToString(); } item = ht["givenname"]; if (item != null) { ee.GivenName = item.ToString(); } item = ht["sn"]; if (item != null) { ee.Surname = item.ToString(); } item = ht["uid"]; if (item != null) { ee.Alias = item.ToString(); } item = ht["assoc-nt-account"]; if (item != null && item is byte[]) { ee.CreateAccountInfo(item as byte[]); } item = ht["adspath"]; if (item != null) { ee.AdsPath = item.ToString(); } item = ht["objectclass"]; if (item != null) { ee.ResultType = LdapSearchResultType.Object; string[] classTypes = item.ToString().Split(','); foreach (string classType in classTypes) { switch (classType.ToLower(System.Threading.Thread.CurrentThread.CurrentCulture)) { case "organizationalperson": case "person": ee.ResultType = LdapSearchResultType.User; break; case "groupofnames": ee.ResultType = LdapSearchResultType.Group; break; } if (ee.ResultType != LdapSearchResultType.Object) { break; } } } #endregion #region Business Info item = ht["company"]; if (item != null) { ee.Company = item.ToString(); } item = ht["department"]; if (item != null) { ee.Department = item.ToString(); } item = ht["title"]; if (item != null) { ee.Title = item.ToString(); } item = ht["telephonenumber"]; if (item != null) { ee.TelephoneNumber = item.ToString(); } #endregion #region Address Information StringBuilder addr = new StringBuilder(); string[] addressParts = { "postaladdress", "postalcode", "l", "st", "co" }; foreach (string part in addressParts) { item = ht[part]; if (item != null) { string value = item.ToString(); if (value.Length > 0) { addr.AppendLine(value); } } } ee.Address = addr.ToString().Trim(); #endregion #region Email Inforamation item = ht["mail"]; if (item != null) { ee.EmailAddress = item.ToString(); } item = ht["rfc822mailbox"]; if (item != null) { ee.SmtpAddress = item.ToString(); } #endregion return ee; }