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