0

我一直在尝试找到一种方法来发现目录上下文中对象类支持的所有属性。我曾尝试使用getattributes()目录上下文的方法,但这仅显示那些已填充的属性。我有兴趣发现仅支持特定对象类的所有属性,而不是所有对象类的所有属性。以下是我已经尝试过的代码片段。

//方法1

        System.out.println("using bindings.......");

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope( SearchControls.OBJECT_SCOPE );
        searchControls.setReturningAttributes( new String[]
            { "objectClasses" } );
        NamingEnumeration<SearchResult> results = conn.getInitialContext().search( "cn=schema", "(ObjectClass=*)", searchControls );

        SearchResult result = results.next();
        Attributes entry = result.getAttributes();

        javax.naming.directory.Attribute objectClasses = entry.get( "objectClasses" );
        System.out.println( objectClasses );

        System.out.println("................................");

//方法2

        DirContext tedClasses = (conn.getInitialContext().getSchemaClassDefinition(entryName));

        // Enumerate the class definitions
        NamingEnumeration namingEnum = tedClasses.search("", null);
        System.out.println("attrs are:");
        while (namingEnum.hasMore()) {
            System.out.println(namingEnum.next());
        }

Whereconn.getInitialContext()给出了目录上下文

4

1 回答 1

-1

您可以执行 ldapsearch 指定objectclass=x(x 是您想要的对象类)吗?

所以搜索人的对象类,例如

ldapsearch -h <host> -p <port> -D <useraccount> -w \? -b <search string> objectclass=person
于 2014-06-24T17:00:16.030 回答