簡體   English   中英

使用Weblogic LDAP身份驗證器配置Spring Security

[英]Configure Spring Security with Weblogic LDAP authenticator

我試圖使用在Oracle Weblogic Server 10.3中配置的LDAP身份驗證器在我的應用程序中設置Spring Security。

我一直在互聯網上進行搜索,但是我發現的只是如何將LDAP直接設置到spring-security.xml中,但是與以某種方式將服務器上的配置導入到其中無關,因此當我嘗試登錄時- ,它將使用服務器上的身份驗證器檢查用戶和密碼。

我想這樣做是因為我無法訪問LDAP的配置(它在生產環境中),因此我必須直接將數據發送給它。

有什么辦法可以做到這一點?

您需要創建一個自定義AuthenticationHandler並在Spring Security配置中對其進行聲明,或者您可以編寫自己的UserDetailsS​​ervice來為您執行LDAP查詢。

<authentication-manager>
    <authentication-provider user-service-ref="jbossLdapController" >
       <password-encoder hash="sha" base64="true" ref="passwordEncoder">
          <salt-source ref="saltSource"/>
       </password-encoder>
    </authentication-provider>
</authentication-manager>

這樣,您可以創建一個實現UserDetailsService的類,以獲取此功能的所有功能,而不必使用典型的自定義身份驗證處理程序手動實現所有功能。

public class JBossLdapController implements UserDetailsService {
      ReflectionSaltSource saltSource;
      public void setSaltSource(ReflectionSaltSource saltSource) {
         this.saltSource = saltSource;
      }

      ShaPasswordEncoder passwordEncoder;
      public void setPasswordEncoder(ShaPasswordEncoder passwordEncoder) {
         this.passwordEncoder = passwordEncoder;
      }

      // LDAP stuff

      @Override
      public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
         // Build user details, call LDAP query.  User details functionality of Spring will automatically compare user supplied credentials with hash and salt source versus username and encrypted password in UserDetails object.
      }

請記住,這只是在不放棄Spring Security UserDetails功能優勢的情況下如何完成此操作的示例。 當然,在不了解您的LDAP提供程序的情況下,密碼可能無法使用SHA進行SHA加密。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM