需要快速的帮助。
我使用LDAP对活动目录进行身份验证,
我想知道如何从UPN别名中获取域的所有UPN别名,
他们有什么办法能得到这个。
请帮帮我!
发布于 2014-02-28 10:02:00
您实际上可以从配置树从AD到LDAP读取这些值。如果您读取以下对象:CN=Partitions,CN=Configuration,DC=your,DC=domain,DC=com,它将包含一个名为uPNSuffixes的属性。
这个属性只包含额外的后缀,而不是默认的后缀(我猜您必须从域名本身获得这个后缀)。
规则是,如果uPNSuffixes属性不可用,则只有默认的UPN后缀是有效的。
编辑:一个简单的例子是:
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属性值:
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;
}https://stackoverflow.com/questions/22089653
复制相似问题