我知道有一个简单的答案,但我似乎无法在任何地方找到它。
下面是一小段代码。有人能告诉我如何列出rsa对象的所有属性及其相关值吗?
提前致谢,
NamingEnumeration answer = executeSearch(context,env,sBaseDN);
while (answer.hasMore()) { // For each ou
SearchResult sr = (SearchResult) answer.next();
Attributes rsa = sr.getAttributes();
// How do I list all the attributes that were returned?
答案 0 :(得分:1)
您可以通过调用Attributes的getAll()
方法获取NamingEnumerations的集合,然后遍历此集合以获取属性值,例如:
try {
for (NamingEnumeration attr = rsa.getAll(); attr.hasMore();) {
Attribute attribute= (Attribute) attr.next();
System.out.println("Attribute id: " + attribute.getID());
for (NamingEnumeration val = attribute.getAll(); val.hasMore();){
System.out.println("Attribute value: " + val.next());
}
}
} catch (NamingException e) {
e.printStackTrace();
}