Skip to content
Advertisement

Retrieving data from LDAP

I want to fetch data from LDAP server. I can retrieve all users from the list. But now, what I want to do is get the person list under ‘directReports’ attribute. It returns users as java Objects. I cannot convert them to any type other than toString(). What I have done is convert objects to String and use string operations to get users’ names. But I think this is not a proper way to do this. Please give me a suggestion. Thanks!

JavaScript

Advertisement

Answer

In LDAP, the directReports attribute (==field) is of Distinguished Name (DN) type. That is a pointer to another object in the database, in this case a user. When you read it in Java, you get a list of strings.

Typically, the DN is of the format CN=username,OU=department,O=organization. CN may also be UID in some implementations. If the CN is what you want, then simply parsing the DN string value with two split() commands will work:

JavaScript

It is wise to do some sanity checking for null values in between.

If you want to retrieve other details about the user that the DN value is pointing to, you will need to read that object from LDAP in a second operation (LDAP reads are very fast):

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement