亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

數(shù)據(jù)庫賬號(hào)密碼加密詳解及實(shí)例

 更新時(shí)間:2017年03月10日 08:34:28   投稿:lqh  
這篇文章主要介紹了數(shù)據(jù)庫賬號(hào)密碼加密詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下

數(shù)據(jù)庫賬號(hào)密碼加密詳解及實(shí)例

數(shù)據(jù)庫中經(jīng)常有對數(shù)據(jù)庫賬號(hào)密碼的加密,但是碰到一個(gè)問題,在使用UserService對密碼進(jìn)行加密的時(shí)候,spring security 也是需要進(jìn)行同步配置的,因?yàn)閟pring security 中驗(yàn)證的加密方式是單獨(dú)配置的。如下:

<authentication-manager>
  <authentication-provider user-service-ref="userDetailService">
    <password-encoder ref="passwordEncoder" />
  </authentication-provider>
</authentication-manager>

<beans:bean class="com.sapphire.security.MyPasswordEncoder" id="passwordEncoder">
  <beans:constructor-arg value="md5"></beans:constructor-arg>
</beans:bean>

如上述配置文件所示,passwordEncoder才是在spring security對賬號(hào)加密校驗(yàn)的地方。

spring security在攔截之后,會(huì)首先對用戶進(jìn)行查找,通過自己定義的userDetailService來找到對應(yīng)的用戶,然后由框架進(jìn)行密碼的匹配驗(yàn)證。

從userDetailService得到user以后,就會(huì)進(jìn)入到DaoAuthenticationProvider中,這是框架中定義的 ,然后跳入其中的authenticate方法中。

該方法會(huì)進(jìn)行兩個(gè)檢查,分別是

* preAuthenticationChecks : 主要進(jìn)行的是對用戶是否過期等信息的校驗(yàn),調(diào)用的方法在userDetail中有定義的。
* additionalAuthenticationChecks : 這個(gè)就是用戶名密碼驗(yàn)證的過程了。

而PasswordEncoder是我們xml中注入的bean,所以了,我們調(diào)用的則是我們自己完成的passwordEncoder

public class MyPasswordEncoder extends MessageDigestPasswordEncoder {
  public MyPasswordEncoder(String algorithm) {
   super(algorithm);
  }

  @Override
  public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
   return encPass.equals(DigestUtils.md5DigestAsHex(rawPass.getBytes()));
  }
}

這是我對其實(shí)現(xiàn)的一個(gè)簡單版本,調(diào)用的就是spring自帶的加密算法,很簡單了,當(dāng)然也可以使用復(fù)雜的加密方法,這個(gè)就靠自己了

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評(píng)論