Java LDAP 使用 UPN 在 Active Directory 中搜索用户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22285357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 14:44:36  来源:igfitidea点击:

LDAP Searching a user in Active directory with UPN

javagroovyactive-directoryldapupn

提问by Charu Jain

I am using LDAP Authentication, Need a help

我正在使用 LDAP 身份验证,需要帮助

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.

假设我有一个用户([email protected]),其中 zzservers.ad 是 demo.com 域的 UPN 别名,我已经知道一种按域在活动目录中搜索用户的方法。

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

但是有谁知道如何通过 UPN 别名在活动目录中搜索用户。

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.

实际上,当用户 [email protected] 登录应用程序时,我想知道用户是否存在于 AD 中,以便进一步进行身份验证。

Any help would be hugely appreciated.

任何帮助将不胜感激。

Thanks

谢谢

采纳答案by mvreijn

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

回答by jwilleke

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

将根据 userPrincipalName 属性的值定位用户。-吉姆