繁体   English   中英

批量通过JNDI检索操作(内部)LDAP属性

[英]Retrieving operational (internal) LDAP attributes via JNDI in one batch

如果知道专有名称,则JNDI InitialLdapContext类允许我在一行中检索LDAP条目的属性:

Attributes attributes = ctx.getAttributes(entryDN);

但是,这不包括操作属性,例如entryCSN,modifyTimestamp等。当然,始终可以指定要通过字符串数组获取的属性:

Attributes attributes = ctx.getAttributes(entryDN, new String[] {"entryCSN"});

但是,仅返回指定的属性。

我尝试过但不适合我的事情:

  1. 通过ctx.search()检索属性

    我知道我可以通过搜索获得所有属性(请参阅此处 ),但是我不希望a)如果我已经知道dn则进行整个Ldap查询,并且b)麻烦地处理搜索结果集。

  2. 仅对操作属性进行第二次查询

    当然,我只能执行第二个查询,但是我想保存额外的行程并将第二个属性添加到第一个属性中,如下所示:

     Attributes attributes = ctx.getAttributes(entryDN); attributes.put(ctx.getAttributes(entryDN, new String[] {"entryCSN"}).get("entryCSN")); 

    导致NoSuchElementException 堆栈跟踪:

     Exception thrown: java.util.NoSuchElementException: Vector Enumeration at java.util.Vector$1.nextElement(Vector.java:352) at javax.naming.directory.BasicAttribute$ValuesEnumImpl.nextElement(BasicAttribute.java:537) 
  3. 列出字符串数组中的所有属性

    由于返回的Ldap条目可以是不同的对象类,因此具有不同的属性,因此我认为没有实际的方法。

有谁知道如何一次获得正常属性和操作属性?

LDAP RFC中定义的属性有2个魔术值:“ *”表示所有用户属性。 “ +”表示所有操作属性。

下面的代码应该工作:

Attributes attributes = ctx.getAttributes(entryDN, new String[] {"*", "+"});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM