2015-02-05 14 views
0

我註冊了jdbcAuthentication()。我怎樣才能替換SELECT語句中推送的密碼?如何在彈簧安全性中使用它進行認證之前修改表單登錄中的密碼?

A PasswordEncoder是不夠的,因爲我想連接傳入的登錄請求的用戶名和密碼,然後對此字符串進行哈希處理,並使用outcoming hash作爲密碼以使用JDBC進行身份驗證。

@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
    auth 
     .jdbcAuthentication() 
      .dataSource(datasource) 
      .usersByUsernameQuery("SELECT username, password, true as enabled " 
        + "FROM users WHERE username = ?") 
      .authoritiesByUsernameQuery("SELECT username, role as authority " 
        + "FROM users, roles " 
        + "WHERE username = ?"); 
    } 
} 

我添加了一個自定義的UsernamePasswordAuthenticationFilter但其attemptAuthentication()方法不會被調用的登錄嘗試之內。

http.addFilterBefore(new CustomUsernamePasswordAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); 
+0

可能的重複http://stackoverflow.com/questions/22994851/how-to-register-saltsource-in-java-config-no-xml – holmis83 2015-02-05 21:51:05

回答

0

如果我理解正確此,您在數據庫password場實際上是用戶名密碼的哈希?

Spring Security的工作方式是首先從數據庫加載UserDetails對象,僅基於username。然後它將密碼(在任何必要的編碼之後 - 例如鹽等)與提供的密碼(在任何必要的編碼之後)進行比較。

爲了實現您的目標,我相信您需要提供一個自定義的「AuthenticationProvider配置」類來使用自定義提供程序。

相關問題