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