2011-06-28 78 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")); 
相關問題