Friday, May 1, 2009

How to get user ID of logged-in user from LDAP

How do you retrieve the user ID of a logged-in user from the LDAP instead of the user name which may not be unique?

There are two ways to achieve this :
1. Setting the "api.use.dn" parameter in to True gives you the distinguished name (DN) of the user instead of the display name when calling the getUserName() method.

2. You can dynamically set this by calling

"workspace.useDistinguishedNames(true)" before calling "workspace.getUserProfile()".
Essentially this would be similar to the following:

Workspace workspace = p_contextProcessorParams.getWorkspace();
String currentCust = CustContextProcessorUtils.getCustomer(workspace.getUserProfile().getUsername());