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

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

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

Attributes attributes = ctx.getAttributes(entryDN);

但是,这不包括操作属性,例如entryCSN、modifyTimestamp等。当然,总是可以用字符串数组指定获取哪些属性:

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

但随后只返回指定的属性。

我尝试过但对我不起作用的事情:

  1. 通过ctx.search()

    检索属性

    我知道我可以通过搜索获取​​所有属性(参见 here),但我不希望 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.nextElement(Vector.java:352)
    at javax.naming.directory.BasicAttribute$ValuesEnumImpl.nextElement(BasicAttribute.java:537)
    
  3. 列出字符串数组中的所有属性

    由于返回的 Ldap 条目可以是不同的对象 classes,因此具有不同的属性,我认为没有可行的方法来做到这一点。

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

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

以下代码应该有效:

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