/// <summary>
/// Search for AD personnel
/// </summary>
/// <param name="keyWords"> Search Department keywords </param>
/// <returns>AD People assemble </returns>
public List<DomainUser> SearchPersonByDeptName(string keyWords)
{
List<DomainUser> ReturnList = SearchAdObjectCache(new DomainConfig(Constants.C_SEARCH_ByDeptName, ldapPath), keyWords).ConvertAll(new Converter<DomainObject, DomainUser>(O2User));
return ReturnList;
}
 public static readonly string C_SEARCH_ByDeptName = "(department={0}*)";
 internal struct DomainConfig
{
static DomainConfig()
{
string ServerUrl = "LDAP:// Domain ";
if (string.IsNullOrEmpty(ServerUrl))
{
_activeObject = Constants.C_ACTIVE_OBJECT;
}
else
{
_activeObject = ServerUrl;
}
}
private static string _activeObject;
public static string ActiveObject
{
get { return _activeObject; }
set { _activeObject = value; }
} private string _searchConditon;
public string SearchConditon
{
get { return _searchConditon; }
set { _searchConditon = value; }
}
string ldapPath ;
public DomainConfig(string sCodition, string LDAPPath)
{
_searchConditon = sCodition;
ldapPath = LDAPPath;
}
public DirectoryEntry[] ADEntrysGet()
{
string[] Paths=ldapPath.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
DirectoryEntry[] DEs = new DirectoryEntry[Paths.Length];
for (int i = ; i < Paths.Length;i++ )
{
DirectoryEntry deRoot;
string ADUser = string.Empty;
string ADPassword = string.Empty;
if (string.IsNullOrEmpty(ADUser))
{
deRoot = new DirectoryEntry(Paths[i]);
}
else
{
deRoot = new DirectoryEntry(Paths[i], ADUser, ADPassword);
}
DEs[i]=deRoot;
}
return DEs;
}
}
public static readonly string C_ACTIVE_OBJECT = "LDAP:// Domain ";
 /// </summary>
/// <param name="dc"> Search for targets and conditions </param>
/// <param name="keyWords"> keyword </param>
/// <returns>AD A collection of objects </returns>
private static List<DomainObject> SearchAdObjectCache(DomainConfig dc, string keyWords)
{
List<DomainObject> ReturnList = new List<DomainObject>();
object CacheObject;
string CacheName = "DomainSearchAdObjectCache" + dc.SearchConditon + keyWords;
if (string.IsNullOrEmpty(keyWords) || keyWords.Length < KeyWordLimitLength)
{ }
else
{
CacheObject = CacheHelper.Get(CacheName);
if (CacheObject != null)
{
ReturnList = (List<DomainObject>)CacheObject;
}
else
{
ReturnList = SearchAdObject(dc, keyWords);
CacheObject = CacheHelper.Get(CacheName);
if (CacheObject == null && ReturnList != null)
{
CacheHelper.Insert(CacheName, ReturnList, CacheDuration);
}
}
}
return ReturnList;
}
/// <summary>
/// AD Object search
/// </summary>
/// <param name="dc"> Search for targets and conditions </param>
/// <param name="keyWords"> keyword </param>
/// <returns>AD A collection of objects </returns>
private static List<DomainObject> SearchAdObject(DomainConfig dc, params object[] keyWords)
{
List<DomainObject> ObjectList = new List<DomainObject>();
DirectoryEntry[] DEs = dc.ADEntrysGet();
foreach (DirectoryEntry DE in DEs)
{
// establish ActiveDirectory binding
using (DirectoryEntry deRoot = DE)
{
// establish ActiveDirectory Search class
using (DirectorySearcher ds = new DirectorySearcher(deRoot))
{
// search criteria
ds.Filter = string.Format(dc.SearchConditon, keyWords);
// Set the return entry
//ds.SizeLimit = 40;
// The search results
SearchResultCollection srCollection = ds.FindAll();
// If there is no result , Return null data
if (srCollection != null && srCollection.Count > )
{
ADUser dUser = null;
ADGroup dGroup = null;
foreach (SearchResult sr in srCollection)
{
if (GetProperty(Constants.AD_USER_objectcategory, sr.Properties).ToString().ToLower().Contains("person"))
{
dUser = new ADUser();
dUser = ADUserSet(sr.Properties);
ObjectList.Add(dUser);
}
else
{
dGroup = new ADGroup();
dGroup = ADGroupSet(sr.Properties);
ObjectList.Add(dGroup);
}
}
}
}
}
}
return ObjectList;
}

LDAP Query more articles about examples

  1. node.js Next LDAP Query practice

    The goal is : From a LDAP Server obtain uid=kxh User data for LDAP The address is :ldap://10.233.21.116:389 In the project root directory , First npm One LDAP Access library for ldpajs npm i ...

  2. SqlSugar- perform Sql Statement query instance

    Use SqlSugar perform sql sentence 1. Simple query SqlSugarClient db = SugarContext.GetInstance(); // perform sql sentence , Handle //1. perform sql, Turn into li ...

  3. 【MySQL】 Pagination query example explanation

    MySQL Pagination query example explanation 1. Preface This article describes a problem that the team encountered in their work MySQL Paging query problem , By the way, I will explain the relevant knowledge , For the latecomers . The point of this article is not " How to " Optimize table structure and SQL sentence , It's about exploration ...

  4. Use ssm(spring+springMVC+mybatis) Create a simple query instance ( 3、 ... and )( Wrong arrangement )

    Use ssm(spring+springMVC+mybatis) Create a simple query instance ( One ) Use ssm(spring+springMVC+mybatis) Create a simple query instance ( Two ) The above two articles have put the flow of ...

  5. Use ssm(spring+springMVC+mybatis) Create a simple query instance ( Two )( Code section )

    This is a continuation of the previous one : use ssm(spring+springMVC+mybatis) Create a simple query instance ( One ) The source code in github Can be downloaded from , Address :https://github.com/guoxia ...

  6. Use ssm(spring+springMVC+mybatis) Create a simple query instance ( One )

    Use under the comb spring+springMVC+mybatis A simple example of integration : Enter the user's ID, Then the user's information is displayed ( This time, due to the space problem , It will be explained in several times , This is the creation of the project , Reverse generation of files and this simple search ...

  7. php MongoDB driver Query instance

    // Whether to check only mx $mx_on_switch = I("post.mx_on_switch"); //mx Fuzzy query $mx_vague_check = I("post.m ...

  8. Elasticsearch Learning Series term and match Query instance

    Elasticsearch Query mode One is like transmission URL Parameter to pass the query statement , It's called simple query GET /library/books/_search // Inquire about index by library,type by boo ...

  9. Yii frame Multi table query instance

    Yii Frame multi table query instance : There are two steps ( I write all the following code in model in ):1. First in the main table model Declare the fields that need to be queried in the association table . public $surveyls_description; // ...

Random recommendation

  1. Android Study three : Thread operation

    As Android The components of development , Multithreading is very important , Let's talk about application scenarios first 1 Multithreading scenario 1.1 In normal use , There are often subthreads to update the interface UI The needs of , But Android doesn't allow child threads to update UI Use child threads to handle UI, If a thread ...

  2. openldap sshkey & User defined properties

    http://qiita.com/T_Tsan/items/eeb0a9ae9b4cdeb80934 https://www.ossramblings.com/using-ldap-to-store- ...

  3. nginx The notes

    nginx Installation Download address : http://nginx.org/download/nginx-1.4.2.tar.gz Installation preparation : nginx Depend on pcre library , Install first. pcre yum instal ...

  4. struts2 Process flow _2015.01.05

    01: First pass through web.xml The interception inside StrutsPrepareAndExecuteFilter 02: then struts2 Some built-in interceptors or user-defined interceptors Interceptor 03: User written ...

  5. Sorting exercises —— Before finding out m Big numbers classification : Sort 2015-06-08 09:33 21 Human reading Comment on (0) Collection

    Sorting exercises -- Before finding out m Big numbers Time Limit: 1000ms   Memory limit: 65536K   Have a question ? Click here ^_^ Title Description Given n A digital , Before finding out m Big numbers .   Input   Multi group transfusion ...

  6. Tomcat Set your own project as the default project ( use IP Visiting your own projects )

    Method 1 : Copy the project to webapps Next , And changed its name to ROOT; Method 2 : stay tomcat/conf/service.xml Of <host></host> Middle configuration <Context p ...

  7. C primer plus Reading notes Chapter Nine

    The title of this chapter is functions .C The design principle is to take the function as the component module of the program . 1. Function Overview Definition of function : A function is a self-contained unit of program code used to perform a specific task . The reason for using functions :1. The use of function can save repeated code .2. Make the program ...

  8. use switch The exercise of judging the month

    import java.util.Scanner; public class SwitchTest01 { public static void main(String[] args) { Syste ...

  9. How to get url Visit history

    In the crowd in the courtyard , Someone asked this question : A Page submit form to B page , And then in B The page clicks back , If in A On the page, judge whether it is direct access or backward access ? I don't want to change B page . So with the idea of a warm-hearted person , I helped him with , First of all, I think of ...

  10. word Post document to blog wordpress Website system

    today ytkah Receive a demand : take word Publish the document to wordpress On the website , Because customers are used to using word To edit an article , Want to import content directly into wp In the website , Actually Word This feature has been provided , And be able to keep Wor ...