2017-04-25 45 views
0

我正在嘗試創建一個安全模塊,用於檢查用戶憑證(登錄時)以及成功登錄時是否生成JWT,以便向服務器發出進一步請求。沒有彈簧安全性的ldap&JWT認證

目前我模塊的工作原理是這樣的: 我有3個休息API端點提供認證(登錄,驗證JWT,註銷)沒有被保護,任何人都必須能夠訪問這些端點, 也是1個userUpdate端點保護通過JWTAuthenticationProvider提供彈簧安全性

所有與JWT有關的東西已準備就緒,現在我只需創建一個方法來檢查LDAP中的用戶名和密碼是否正確。但我有一些麻煩理解我應該怎麼做ldap users

我已經有主用戶,並通過conect到ldap,但我發現大多數關於ldap身份驗證的例子是與春季安全,我不認爲多數民衆贊成在這種情況下做到這一點,因爲我需要驗證匹配我們/通過登錄(而不是保護我的端點安全)。

任何人都可以告訴我我應該怎麼做驗證?任何我不清楚的東西?請詢問並評論和回答。

感謝


哦一個編輯:

@Override 
public AuthenticationResponse login(AuthenticationRequest authenticationRequest) { 
    checkNotNull(authenticationRequest, "The authenticationRequest is a required argument!"); 

    AuthenticationResponse authenticationResponse = AuthenticationResponse.builder().build(); 

    //currently a pseudo authentication, here is where i should authenticate against LDAP 
    Optional<Usuario> optionalUsuario = service.findByNombreUsuario(authenticationRequest); 

    if (optionalUsuario.isPresent()) { 
     Usuario usuario = optionalUsuario.get(); 

     String token = JwtTokenUtil.generateToken(authenticationRequest); 
     authenticationResponse.setAuthenticationToken(token); 

     repository.saveToken(UserToken.builder() 
       .nombreUsuario(usuario.getNombreUsuario()) 
       .roles(usuario.getRoles()) 
       .build(), token); 

,你可以看到我的意圖,以使對LDAP認證只在登錄時,只檢查用戶和傳球都是正確的,我將管理使用其他數據庫的角色和權限


另一個編輯:我有一些bas爲LDAP身份驗證IC LDAP結構中使用Spring Security的,但我總是再次變得糟糕憑據


編輯:我設法使之與春季安全工作,但(如預期),是由我的團隊說,我們需要實現沒有彈簧安全性的身份驗證,以便與我們的自定義角色加載器和令牌創建集成

回答

0

使用http://docs.spring.io/spring-security/site/docs/current/apidocs/org/springframework/security/ldap/authentication/LdapAuthenticationProvider.html從LDAP進行身份驗證和獲取角色,應該使用spring安全性,我可能錯過了smth, t要使用它,因爲它是安全標準的

+0

因爲我已經有一個authenticat (JWT之一)來保護我的api的用戶端點 –

+0

首先您可以配置多個auth提供程序,secondary可以使用RememberMeAuthenticationFilter進行jwt令牌處理,希望這是有道理的 – NikSa

+0

嗯沒有多少有一個auth提供商。在那個筆記上我將如何配置安全性?我的意思是 '@Override protected void configure(AuthenticationManagerBuilder身份驗證)拋出異常{auth.authenticationProvider(provider); } '做基於提供者的配置。我可以有多個這些配置嗎? –