有簡單的Spring Web應用安全與密碼編碼:認證Spring Security的蒙山編碼的密碼
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider user-service-ref="personService">
<security:password-encoder hash="md5" ref="passwordEncoder">
<!-- <security:salt-source user-property="username"/> -->
</security:password-encoder>
</security:authentication-provider>
</security:authentication-manager>
編碼也很簡單:
person.setPassword(encoder.encodePassword(person.getPassword(), null));
所以在數據庫中的所有密碼都將進行編碼。 現在我想要在應用程序中使用某個用戶名對某個用戶進行身份驗證。 之前(當passswords是明文),它是這樣的:
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
username, password);
Authentication authentication = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(authentication);
但現在我得到的編碼從數據庫的密碼和不能做身份驗證之前。
問題所在。該Spring不知道密碼來自已經編碼的UsernamePasswordAuthenticationToken。而且他第二次編碼。 誰可以幫忙?
編輯
所以,我在這裏看到的兩個解決方案:
- 實現自定義DaoAuthenticationProvider的時候在那裏添加檢查,如果這兩個密碼散列已經
- 實現自定義的身份驗證和手動把它在安全上下文。
其他?哪個最好?
包括一些SpringSecurity在[詳細這裏(http://techastute.blogspot.com /2013/01/spring-security-in-detail.html),可能對某個人有用。 – raksja 2013-01-21 17:51:21