开发者

Modifying "msExchHideFromAddressLists" Active Directory Attribute Using JNDI

开发者 https://www.devze.com 2023-03-16 14:23 出处:网络
I have created an Active Directory client using JNDI, that has the ability to query for attributes, as well as modify existing ones.I have the need to modify the \"msExchHideFromAddressLists\" to set

I have created an Active Directory client using JNDI, that has the ability to query for attributes, as well as modify existing ones. I have the need to modify the "msExchHideFromAddressLists" to set it equal to false, but I get a null pointer exception wh开发者_如何学JAVAen trying to query for it. Any insight? Thanks

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();
}


I found out what the issue was. Apparently, the "msExchHideFromAddressLists" attribute is not valued by default, so a query on it was returning a nullPointerException. To modify this attribute, simply set the value to "TRUE" or "FALSE".

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

精彩评论

暂无评论...
验证码 换一张
取 消