Jim*_*den 0 java attributes jndi ldap
InitialLdapContext如果知道专有名称,则JNDI 类允许我在一行中检索LDAP条目的属性:
Attributes attributes = ctx.getAttributes(entryDN);
Run Code Online (Sandbox Code Playgroud)
但是,这不包括操作属性,例如entryCSN,modifyTimestamp等。当然,始终可以指定要通过字符串数组获取的属性:
Attributes attributes = ctx.getAttributes(entryDN, new String[] {"entryCSN"});
Run Code Online (Sandbox Code Playgroud)
但是,仅返回指定的属性。
我尝试过但不适合我的事情:
通过检索属性 ctx.search()
我知道我可以通过搜索获取所有属性(请参阅此处),但是我不希望a)如果我已经知道dn则进行整个Ldap查询,并且b)麻烦地处理搜索结果集。
仅对操作属性进行第二次查询
当然,我只能执行第二个查询,但是我想保存额外的行程并将第二个属性添加到第一个属性中,如下所示:
Attributes attributes = ctx.getAttributes(entryDN);
attributes.put(ctx.getAttributes(entryDN, new String[] {"entryCSN"}).get("entryCSN"));
Run Code Online (Sandbox Code Playgroud)
导致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)
Run Code Online (Sandbox Code Playgroud)列出字符串数组中的所有属性
由于返回的Ldap条目可以是不同的对象类,因此具有不同的属性,因此我认为没有实际的方法。
有谁知道如何一次获得正常属性和操作属性?
LDAP RFC中定义的属性有2个魔术值:“ *”表示所有用户属性。“ +”表示所有操作属性。
下面的代码应该工作:
Attributes attributes = ctx.getAttributes(entryDN, new String[] {"*", "+"});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1740 次 |
| 最近记录: |