简体   繁体   English

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

[英]Modifying “msExchHideFromAddressLists” Active Directory Attribute Using JNDI

I have created an Active Directory client using JNDI, that has the ability to query for attributes, as well as modify existing ones.我使用 JNDI 创建了一个 Active Directory 客户端,它能够查询属性以及修改现有属性。 I have the need to modify the "msExchHideFromAddressLists" to set it equal to false, but I get a null pointer exception when trying to query for it.我需要修改“msExchHideFromAddressLists”以将其设置为 false,但在尝试查询时出现 null 指针异常。 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.显然,默认情况下“msExchHideFromAddressLists”属性没有被重视,因此对其的查询返回了 nullPointerException。 To modify this attribute, simply set the value to "TRUE" or "FALSE".要修改此属性,只需将值设置为“TRUE”或“FALSE”。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM