本文介绍了使用javax.naming中,我能确定,如果我连接到AD或其他类型的服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只使用javax.naming中的API,是有一些元数据或其他伎俩,我可以用它来确定如果我实际上连接到Active Directory服务器或其他类型的目录服务器?

Using only the javax.naming API, is there some metadata or other trick I can use to determine if I am in fact connected to an Active Directory server or some other type of directory server ?

推荐答案

根DSE可能包含包含有关目录服务器的软件信息的属性。但是,根DSE和/或属性可能不是present或特性可能不被命名为在所有目录服务器实现是相同的。不过,你可以查询DSE,看看它提供的目录软件,您的应用程序支持。下面是一个LDAP搜索来获取根DSE:

The root DSE may contain attributes that contain information about the directory server's software. However, the root DSE and/or the attributes may not be present or attributes may not be named the same in all directory server implementations. Nevertheless, you can query the DSE and see what it offers for the directory software your app will support. Here's an LDAP search to get the root DSE:

ldapsearch -h HOST -b " " -s base objectclass=*

这假定DSE与一个对象类关联。供应商可以具有一个专有的方法,用于提供相同的。

This assumes that the DSE is associated with an objectclass. The vendor may have a proprietary method for providing the same.

有这个指导性的RFC 3045;它谈论存储供应商的相关信息在根DSE。可填充由目录服务器软件两个属性是'verndorname'和'vendorversion'。您可以检查这些存在于服务器(S)你正在使用返回的根DSE。

There is this informational RFC 3045; it talks about storing vendor related information in the root DSE. Two attributes that may be populated by the directory server software are 'verndorname' and 'vendorversion'. You can check the existence of these in the root DSE returned by the server(s) you're working with.

下面是一个粗糙的Java code从根DSE拉那两个属性(使用LDAP提供,这是):

Here's a crude Java code to pull those two attributes from the root DSE (using the LDAP provider, that is):

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;    
import javax.naming.directory.SearchResult;

public class RootDSE {
    public static void main(String[] args) throws Exception{
        Hashtable<String, String> jndiParms = new Hashtable<String, String>();

        jndiParms.put(Context.PROVIDER_URL, "ldap://my.ldap.server:389");
        jndiParms.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

        DirContext ctx = new InitialDirContext(jndiParms);

        String searchBase = "";
        String searchFilter = "(objectclass=*)";

        SearchControls searchCtls = new SearchControls();
        searchCtls.setSearchScope(SearchControls.OBJECT_SCOPE);
        searchCtls.setReturningAttributes(new String[] { "vendorname", "vendorversion" } );

        NamingEnumeration<SearchResult> searchResults = 
            ctx.search(searchBase, searchFilter, searchCtls);

        if (searchResults.hasMore()) {
            SearchResult searchResult = (SearchResult)searchResults.next();
            System.out.println(searchResult.getAttributes());
        }
        else {
            System.err.println("No results");
        }
    }
}

这篇关于使用javax.naming中,我能确定,如果我连接到AD或其他类型的服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 12:34