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);
可能的重複http://stackoverflow.com/questions/22994851/how-to-register-saltsource-in-java-config-no-xml – holmis83 2015-02-05 21:51:05