2
votes

I am using LDAP Authentication, Need a help

Suppose i have a user([email protected]), where zzservers.ad is a UPN Alias of demo.com domain , i already know of a way to search a user in active directory by domain.

But Does anyone know about how to search a user in active directory by UPN Alias.

Actually when user [email protected] login into the application, i want to know if user is present in AD, so as to proceed authentication further.

Any help would be hugely appreciated.

Thanks

2
possible duplicate of Fetch Domain name of UPN alias - tim_yates
I think this question is separate, it's more to the point as to finding a user instead of querying the domain configuration. - mvreijn
Hi mvreijn, so what's the way out of this, searching user by UPN, Any help on this? - Charu Jain

2 Answers

3
votes

This is more an ordinary user search:

public String findUserByUPN( LdapContext ctx, String username )
{
   // Domain name should be in DC=your,DC=domain,DC=com format
   String domain = "DC=demo,DC=com";
   String filter = "(userPrincipalName=" + username + ")" ;
   NamingEnumeration<SearchResult> results = ctx.search( domain, filter, null );
   while ( results.hasMore() )
   {
       SearchResult result = results.next();
       // If you get a result here, the user was found
       return result.getNameInNamespace();
   }
   return null;
}
2
votes

Not sure what you are trying to accomplish but a filter like:

([email protected])

Will locate a user from the value of the userPrincipalName attribute. -jim