Search user of specific domain name

Source: Internet
Author: User
Tags ldap ldap search filter samaccountname

Usually, we use a LDAP search filter to find a user. The filter like"(Samaccountname = user alias)".

But there is a special situation is: the domain what the LDAP path assign has several sub-domains, and there are several users of these sub-domains have same alias.

E. g.
The LDAP path is" GC: // dc = root, Dc = com ".
There are two sub-domains of root domain:
GC: // dc = sub1, Dc = root, Dc = com
GC: // dc = sub2, Dc = root, Dc = com
There are two users are:
Sub1 \ Username
Sub2 \ Username

We cannot write a filter like" (! (Domainname = Domain Name) (samaccountname = user alias )) ". If we use the filter" (Samaccountname = user alias) "To search from" GC: // dc = root, Dc = com ", We will get two results.

Which is our real target?

So, we must identify the distinguishedname of the user with regular expression"DC * = [^,] +"To get the use's domain name.

SearchresultcollectionResults = mysearcher. findall ();

// Check domain name

Foreach ( Searchresult Result In Results)

{

StringDN = result. properties ["Distinguishedname"] [0]. tostring ();

Match M = RegEx . Match (DN, "DC * = [^,] +" );

String Mvalue = RegEx . Replace (M. value, @ "[\ S]" , "" , Regexoptions . Ignorecase );

If ( String . Compare (mvalue, "DC =" + Userdomain, True ) = 0)

{

// The target is found

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.