Spring LDAP 常見問題
操作屬性
如何使用 context.removeAttributeValue()
移除操作屬性?
預設情況下,DirContextAdapter
僅讀取可見屬性。這是因為操作屬性只有在明確要求時才會由伺服器傳回,而且 Spring LDAP 無法得知要要求哪些屬性。這表示 DirContextAdapter
未填入操作屬性。因此,removeAttributeValue
不會有任何效果(因為從 DirContextAdapter
的角度來看,它一開始就不在那裡)。
基本上有兩種方法可以做到這一點
-
使用搜尋或查詢方法,該方法將屬性名稱作為引數,例如
LdapTemplate#lookup(Name, String[], ContextMapper)
。然後使用ContextMapper
實作,該實作在mapFromContext()
中傳回提供的DirContextAdapter
。 -
直接使用
LdapTemplate#modifyAttributes(Name, ModificationItem[])
,手動建立ModificationItem
陣列。