views:

68

answers:

1

Wrote a java code to search for users from Active Directory server. We get the user list but dont know the domain to which each user belongs. How can the domain of the user be found from Active Directory programatically.

One method thought of is :

1)Get the distinguished name of user from Active Directory. 2)Parse the distinguished name. 3)Get the substring that starts the first instance of "DC=". 4)Strip off the "DC=" at the beginning. 5)Replace all instances of ",DC=" with a "." 6)What is left is the DNS domain name of the user.

Is this reliable. Please suggest some other solution.

+1  A: 

The DistinguishedName attribute contains the domain name user comes from. Also, you might want to check the adspath attribute, which in my case looks like

LDAP://contoso/CN=John Doe,OU=Human-Resources,DC=contoso,DC=com

so, contcatenating all the DC attributes gives you the domain name user comes from.

naivists