首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从域名获取UPN别名,使用LDAP获取UPN别名

从域名获取UPN别名,使用LDAP获取UPN别名
EN

Stack Overflow用户
提问于 2014-02-28 08:12:19
回答 1查看 1.1K关注 0票数 0

需要快速的帮助。

我使用LDAP对活动目录进行身份验证,

我想知道如何从UPN别名中获取域的所有UPN别名,

他们有什么办法能得到这个。

请帮帮我!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-28 10:02:00

您实际上可以从配置树从AD到LDAP读取这些值。如果您读取以下对象:CN=Partitions,CN=Configuration,DC=your,DC=domain,DC=com,它将包含一个名为uPNSuffixes的属性。

这个属性只包含额外的后缀,而不是默认的后缀(我猜您必须从域名本身获得这个后缀)。

规则是,如果uPNSuffixes属性不可用,则只有默认的UPN后缀是有效的。

编辑:一个简单的例子是:

代码语言:javascript
复制
public List<String> getUpnSuffixes( LdapContext ctx, String domainName )
{
   // Domain name should be in DC=you,DC=domain,DC=com format
   String domConfig = "CN=Partitions,CN=Configuration," +domainName ;
   List<String> names = new ArrayList<String>();
   // Dirty hack to get the default suffix
   names.add( domainName.replaceAll( "DC=", "" ).replaceAll( "," , "." );
   // Read the configuration
   Attributes attrs = ctx.getAttributes( domConfig , new String[] { "uPNSuffixes" } );
   Attribute attr = attrs.get( "uPNSuffixes" );
   for ( int i=0; i<attr.size(); i++ )
   {
       names.add( attr.get(i) );
   }
   // Now you have all the suffixes in the "names" list. 
   return names;
}

请注意,您可能必须捕获NamingException的ctx.getAttributes()attr.get()调用。

编辑2:如果您想要相反,搜索uPNSuffixes属性值:

代码语言:javascript
复制
public String getDomainFromUpnSuffix( LdapContext ctx, String uPNSuffix )
{
   String filter = "(&(CN=Partitions)(uPNSuffixes=" + uPNSuffix + "))" ;
   // Find the configuration for this suffix
   NamingEnumeration<SearchResult> results = ctx.search( "", filter, null );
   while ( results.hasMore() )
   {
       SearchResult result = results.next();
       return result.getNameInNamespace();
   }
   return null;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22089653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档