msExchHideFromAddressLists

msExchHideFromAddressLists

我已经使用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();
}

最佳答案

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

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

10-02 07:01