private LdapState BaseLdapSearch(IList <string> otherReturnedAttributes, out IList <ILdapUser> searchResult, string searchFilter) { searchResult = new List <ILdapUser>(); otherReturnedAttributes = otherReturnedAttributes == null?_baseAttributes.ToList() : _baseAttributes.Union(otherReturnedAttributes).ToList(); try { searchResult = LdapUserUtils.ConvertToLdapUsers((SearchResponse)_ldapConnection.SendRequest( LdapRequestBuilder.GetSearchUserRequest(_configRepository.GetSearchBaseDn(), searchFilter, otherReturnedAttributes ))); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapSearchUserError)); return(LdapState.LdapSearchUserError); } if (searchResult.Count == 0) { _logger.Write(_logger.BuildLogMessage("Search Operation with NO RESULTS", LdapState.LdapSearchUserError)); return(LdapState.LdapSearchUserError); } _logger.Write(_logger.BuildLogMessage("Search Operation Success", LdapState.LdapUserManipulatorSuccess)); return(LdapState.LdapUserManipulatorSuccess); }
public LdapState SearchUsers(IList <string> otherReturnedAttributes, string[] searchedUsers, out IList <ILdapUser> searchResult) { searchResult = new List <ILdapUser>(); otherReturnedAttributes = otherReturnedAttributes == null?_baseAttributes.ToList() : _baseAttributes.Union(otherReturnedAttributes).ToList(); try { //Foreach all the credential,for everyone do the search and add user results to the out parameter searchResult = searchedUsers.Select( users => (SearchResponse)_ldapConnection.SendRequest( LdapRequestBuilder.GetSearchUserRequest(_configRepository.GetSearchBaseDn(), LdapFilterBuilder.GetSearchFilter(_configRepository.GetUserObjectClass(), _configRepository.GetMatchFieldName(), users), otherReturnedAttributes) )) .Aggregate(searchResult, (current, searchReturn) => current.Concat(LdapUserUtils.ConvertToLdapUsers(searchReturn)).ToList()); } catch (Exception e) { _logger.Write(_logger.BuildLogMessage(e.Message, LdapState.LdapSearchUserError)); return(LdapState.LdapSearchUserError); } if (searchResult.Count == 0) { _logger.Write(_logger.BuildLogMessage("Search Operation with NO RESULTS", LdapState.LdapSearchUserError)); return(LdapState.LdapSearchUserError); } _logger.Write(_logger.BuildLogMessage("Search Operation Success", LdapState.LdapUserManipulatorSuccess)); return(LdapState.LdapUserManipulatorSuccess); }
public void SearchRequest() { string ldapSearchFilter = String.Format("(&(objectClass={0})({1}={2}))", ObjectClass, "cn", UserCn); const string baseDn = "o=ApexNet,ou=People,dc=maxcrc,dc=com"; var attributes = new List <string> { "cn", "sn" }; SearchRequest req = LdapRequestBuilder.GetSearchUserRequest(baseDn, ldapSearchFilter, attributes); Assert.AreEqual(baseDn, req.DistinguishedName); Assert.AreEqual(ldapSearchFilter, req.Filter); Assert.AreEqual(SearchScope.Subtree, req.Scope); CollectionAssert.AreEqual(attributes, req.Attributes); }