简体   繁体   中英

LDAP Searching a user in Active directory with UPN

I am using LDAP Authentication, Need a help

Suppose i have a user(user1@zzservers.ad), 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 user1@zzservers.ad 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

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;
}

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

(userPrincipalName=jim@YOURDOMAIN.NET)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM