使用JNDI修改“msExchHideFromAddressLists”Active Directory属性

时间:2011-06-28 23:31:08

标签: java attributes active-directory jndi

我使用JNDI创建了一个Active Directory客户端,它能够查询属性以及修改现有属性。我需要修改“msExchHideFromAddressLists”将其设置为false,但在尝试查询时我得到一个空指针异常。任何见解?感谢

String filter = "(&(objectCategory=user) (sAMAccountName=" + sAMAccountName + "))";
results = ctx.search(ou, filter, controls);

while(results.hasMore()) {
    SearchResult searchResult = (SearchResult) results.next();
    Attributes attributes = searchResult.getAttributes();

    Attribute attr = attributes.get("msExchHideFromAddressLists");
    String output = (String) attr.get();
}

1 个答案:

答案 0 :(得分:1)

我发现了问题所在。显然,默认情况下不对“msExchHideFromAddressLists”属性进行赋值,因此对它的查询返回nullPointerException。要修改此属性,只需将值设置为“TRUE”或“FALSE”。

ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("msExchHideFromAddressLists", "TRUE"));