问题描述
我想显示 LDAP 目录架构中存在的所有对象类,以帮助用户输入可用的对象类以添加新条目.
I want to show all objectclasses present in schema of LDAP Directory to help user to input available objectclasses for adding new entry.
DirContext schema = ctx.getSchema(""); Attributes answer = schema.getAttributes("ClassDefinition/person");
但这仅显示有关人员的信息.
but that shows information about person only.
推荐答案
你要查询subschema subentry 即cn=schema(以下代码已针对 Apache Directory Server 进行了测试)
You have to query the subschema subentry i.e cn=schema (the below code has been tested against the Apache Directory Server)
DirContext ctx = new InitialLdapContext( env, null ); SearchControls searchControls = new SearchControls(); searchControls.setSearchScope( SearchControls.OBJECT_SCOPE ); searchControls.setReturningAttributes( new String[] { "objectClasses" } ); NamingEnumeration<SearchResult> results = ctx.search( "cn=schema", "(ObjectClass=*)", searchControls ); SearchResult result = results.next(); Attributes entry = result.getAttributes(); Attribute objectClasses = entry.get( "objectClasses" ); System.out.println( objectClasses );