我想显示LDAP目录模式中存在的所有对象类,以帮助用户输入可用的对象类以添加新条目。
DirContext schema = ctx.getSchema("");
Attributes answer = schema.getAttributes("ClassDefinition/person");
但这只显示有关人的信息。
答案 0 :(得分:4)
DirContext schema=dcx.getSchema("");
NamingEnumeration bindings = schema.listBindings("ClassDefinition");
while (bindings.hasMore())
{
Binding bd = (Binding)bindings.next();
System.out.println(bd.getName() + ": " + bd.getObject());
}
您可以使用各种其他绑定,例如
答案 1 :(得分:3)
您必须查询子模式子条目,即cn = schema (以下代码已经针对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 );