Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LDAP Searching a user in Active directory with UPN

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

like image 823
Charu Jain Avatar asked Dec 12 '25 11:12

Charu Jain


1 Answers

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;
}
like image 156
mvreijn Avatar answered Dec 15 '25 01:12

mvreijn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!