2011-06-28 65 views
0

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

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

您的代码好吗? – MJB

+0

我刚刚添加了代码...谢谢。 – Thomas

回答

1

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

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