我正在使用 LDAP 身份验证,需要帮助
假设我有一个用户(user1@zzservers.ad),其中 zzservers.ad 是 demo.com 域的 UPN 别名,我已经知道一种在 Activity 目录中按域搜索用户的方法。
但是有谁知道如何通过 UPN 别名在 Activity 目录中搜索用户。
实际上当用户user1@zzservers.ad登录到应用程序时,我想知道用户是否存在于AD中,以便进一步进行身份验证。
如有任何帮助,我们将不胜感激。
谢谢
最佳答案
这更像是一个普通的用户搜索:
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;
}
关于java - LDAP 使用 UPN 在 Active Directory 中搜索用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22285357/