LDAP 名稱空間選項

LDAP 實現廣泛使用 Spring LDAP,因此熟悉該專案的 API 可能會有所幫助。

使用

<ldap-server> 元素定義 LDAP 伺服器。此元素為其他 LDAP bean 設定 Spring LDAP ContextSource,定義 LDAP 伺服器的位置和其他連線資訊(例如使用者名稱和密碼,如果它不允許匿名訪問)。它還可以用於建立嵌入式伺服器進行測試。這兩種選項的語法詳細資訊在 LDAP 章中介紹。實際的 ContextSource 實現是 DefaultSpringSecurityContextSource,它擴充套件了 Spring LDAP 的 LdapContextSource 類。manager-dnmanager-password 屬性分別對映到後者的 userDnpassword 屬性。

如果您的應用程式上下文中只定義了一個伺服器,則其他由 LDAP 名稱空間定義的 bean 將自動使用它。否則,您可以為該元素指定一個 "id" 屬性,並使用 server-ref 屬性從其他名稱空間 bean 中引用它。這實際上是 ContextSource 例項的 bean id,如果您想在其他傳統的 Spring bean 中使用它。

<ldap-server> 屬性

  • mode 明確指定應使用哪個嵌入式 ldap 伺服器。唯一支援的值是 unboundid。預設情況下,它將取決於庫是否在類路徑中可用。

  • id 一個 bean 識別符號,用於在上下文中的其他地方引用該 bean。

  • ldif 明確指定要載入到嵌入式 LDAP 伺服器的 ldif 檔案資源。ldif 應該是一個 Spring 資源模式(即 classpath:init.ldif)。預設值是 classpath*:*.ldif

  • manager-dn 用於認證到(非嵌入式)LDAP 伺服器的“管理器”使用者身份的使用者名稱 (DN)。如果省略,將使用匿名訪問。

  • manager-password 管理器 DN 的密碼。如果指定了 manager-dn,則此項為必需。

  • port 指定 IP 埠號。例如,用於配置嵌入式 LDAP 伺服器。預設值為 33389。

  • root 嵌入式 LDAP 伺服器的可選根字尾。預設值為 "dc=springframework,dc=org"

  • url 未使用嵌入式 LDAP 伺服器時指定 ldap 伺服器 URL。

<ldap-authentication-provider>

此元素是建立 LdapAuthenticationProvider 例項的簡寫。預設情況下,它將配置一個 BindAuthenticator 例項和一個 DefaultAuthoritiesPopulator。與所有名稱空間身份驗證提供程式一樣,它必須作為 authentication-provider 元素的子元素包含在內。

<ldap-authentication-provider> 的父元素

<ldap-authentication-provider> 屬性

  • group-role-attribute 包含將在 Spring Security 中使用的角色名稱的 LDAP 屬性名稱。對映到 DefaultLdapAuthoritiesPopulatorgroupRoleAttribute 屬性。預設為 "cn"。

  • group-search-base 組A成員搜尋的搜尋基。對映到 DefaultLdapAuthoritiesPopulatorgroupSearchBase 建構函式引數。預設為 ""(從根目錄搜尋)。

  • group-search-filter 組搜尋過濾器。對映到 DefaultLdapAuthoritiesPopulatorgroupSearchFilter 屬性。預設為 (uniqueMember={0})。替換引數是使用者的 DN。

  • role-prefix 將新增到從持久化儲存載入的角色字串的非空字串字首。對映到 DefaultLdapAuthoritiesPopulatorrolePrefix 屬性。預設為 "ROLE_"。在預設值非空的情況下,使用值 "none" 表示沒有字首。

  • server-ref 要使用的可選伺服器。如果省略,並且已註冊預設 LDAP 伺服器(使用沒有 Id 的 <ldap-server>),則將使用該伺服器。

  • user-context-mapper-ref 允許透過指定一個 UserDetailsContextMapper bean 來顯式自定義載入的使用者物件,該 bean 將使用使用者目錄條目中的上下文資訊進行呼叫。

  • user-details-class 允許指定使用者條目的 objectClass。如果設定,框架將嘗試將定義類的標準屬性載入到返回的 UserDetails 物件中。

  • user-dn-pattern 如果您的使用者在目錄中的固定位置(即,您無需進行目錄搜尋即可直接從使用者名稱中找出 DN),則可以使用此屬性直接對映到 DN。它直接對映到 AbstractLdapAuthenticatoruserDnPatterns 屬性。該值是用於構建使用者 DN 的特定模式,例如 uid={0},ou=people。鍵 {0} 必須存在並將替換為使用者名稱。

  • user-search-base 使用者搜尋的搜尋基。預設為 ""。僅與 'user-search-filter' 一起使用。

    如果您需要執行搜尋以在目錄中定位使用者,那麼您可以設定這些屬性來控制搜尋。BindAuthenticator 將配置一個 FilterBasedLdapUserSearch,屬性值直接對映到該 bean 建構函式的前兩個引數。如果未設定這些屬性並且未提供 user-dn-pattern 作為替代,則將使用預設搜尋值 user-search-filter="(uid={0})"user-search-base=""

  • user-search-filter 用於搜尋使用者的 LDAP 過濾器(可選)。例如 (uid={0})。替換引數是使用者的登入名。

    如果您需要執行搜尋以在目錄中定位使用者,那麼您可以設定這些屬性來控制搜尋。BindAuthenticator 將配置一個 FilterBasedLdapUserSearch,屬性值直接對映到該 bean 建構函式的前兩個引數。如果未設定這些屬性並且未提供 user-dn-pattern 作為替代,則將使用預設搜尋值 user-search-filter="(uid={0})"user-search-base=""

<ldap-authentication-provider> 的子元素

<password-compare>

此元素用作 <ldap-provider> 的子元素,並將身份驗證策略從 BindAuthenticator 切換到 PasswordComparisonAuthenticator

<password-compare> 的父元素

<password-compare> 屬性

  • hash 定義使用者密碼使用的雜湊演算法。我們強烈建議不要使用 MD4,因為它是一種非常弱的雜湊演算法。

  • password-attribute 目錄中包含使用者密碼的屬性。預設為 "userPassword"。

<password-compare> 的子元素

<ldap-user-service>

此元素配置一個 LDAP UserDetailsService。使用的類是 LdapUserDetailsService,它是 FilterBasedLdapUserSearchDefaultLdapAuthoritiesPopulator 的組合。它支援的屬性與 <ldap-provider> 中的用法相同。

<ldap-user-service> 屬性

  • cache-ref 定義對與 UserDetailsService 一起使用的快取的引用。

  • group-role-attribute 包含將在 Spring Security 中使用的角色名稱的 LDAP 屬性名稱。預設為 "cn"。

  • group-search-base 組A成員搜尋的搜尋基。預設為 ""(從根目錄搜尋)。

  • group-search-filter 組搜尋過濾器。預設為 (uniqueMember={0})。替換引數是使用者的 DN。

  • id 一個 bean 識別符號,用於在上下文中的其他地方引用該 bean。

  • role-prefix 將新增到從持久化儲存載入的角色字串的非空字串字首(例如 "ROLE_")。在預設值非空的情況下,使用值 "none" 表示沒有字首。

  • server-ref 要使用的可選伺服器。如果省略,並且已註冊預設 LDAP 伺服器(使用沒有 Id 的 <ldap-server>),則將使用該伺服器。

  • user-context-mapper-ref 允許透過指定一個 UserDetailsContextMapper bean 來顯式自定義載入的使用者物件,該 bean 將使用使用者目錄條目中的上下文資訊進行呼叫。

  • user-details-class 允許指定使用者條目的 objectClass。如果設定,框架將嘗試將定義類的標準屬性載入到返回的 UserDetails 物件中。

  • user-search-base 使用者搜尋的搜尋基。預設為 ""。僅與 'user-search-filter' 一起使用。

  • user-search-filter 用於搜尋使用者的 LDAP 過濾器(可選)。例如 (uid={0})。替換引數是使用者的登入名。

© . This site is unofficial and not affiliated with VMware.