I recently wanted to integrate Active directory in one of my projects. I created web app with CodeIgniter and used this AD library to integrate AD.
https://github.com/kathmann/Auth_AD
Now it does everything I need, except I cannot get manager's samaccountname or email id.
For example I want to fetch one user 'xyz' all details, I used predefine function from the library which is
get_all_user_data('xyz');
This is getting me all the details and for manager, I am getting below details.
CN=ABC DEF, OU=Users,OU=example1,OU=example2,OU=Sites,DC=example3,DC=example4,DC=example5
Now I want to fetch samaccountname and email of the above. But i am not sure how to do it.
Just let me know what to code further and convert above string to samaccountname and email of the user.
I already saw this thread: ldap filter for distinguishedName
The person question is same as mine but I didn't understand what the answer says. I tried the answer but it gets all the user who has same manager instead the actual manager user.
Since you've already found out the manager's value for the said user, you already have the CN value for the manager in the same DN.
Manager's DN = CN=ABC DEF, # // OUs placed below for sake of understanding
OU=Users,OU=example1,OU=example2,OU=Sites,DC=example3,DC=example4,DC=example5
You should create another filter on this CN value of the manager ("CN=ABC DEF" for the manager derived above), and then retrieve the values of mail
and samaccountname
attribute.
Your search filter should be: "(&(objectCategory=person)(objectClass=user)(cn=ABC DEF))"
. Now you should be able to fetch this user (manager here) and its detailed information, based on this CN filter.