How to show all objectclasses description of ldap directory using jndi

北城以北 提交于 2019-12-06 02:35:08

问题


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.


回答1:


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 );



回答2:


DirContext schema=dcx.getSchema("");
NamingEnumeration bindings = schema.listBindings("ClassDefinition");
while (bindings.hasMore())
{
    Binding bd = (Binding)bindings.next();
    System.out.println(bd.getName() + ": " + bd.getObject());
}

You can use various other bindings like

  • AttributeDefinition
  • ClassDefinition
  • SyntaxDefinition

Schema context may also provide bindings like
  • MatchingRule
  • ExtensionDefinition
  • ControlDefinition
  • SASLDefinition


来源:https://stackoverflow.com/questions/5273022/how-to-show-all-objectclasses-description-of-ldap-directory-using-jndi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!