数据库账号密码加密详解及实例

数据库中经常有对数据库账号密码的加密,但是碰到一个问题,在使用UserService对密码进行加密的时候,spring security 也是需要进行同步配置的,因为spring security 中验证的加密方式是单独配置的。如下:

<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>

spring security在拦截之后,会首先对用户进行查找,通过自己定义的userDetailService来找到对应的用户,然后由框架进行密码的匹配验证。

从userDetailService得到user以后,就会进入到DaoAuthenticationProvider中,这是框架中定义的 ,然后跳入其中的authenticate方法中。

该方法会进行两个检查,分别是

* preAuthenticationChecks : 主要进行的是对用户是否过期等信息的校验,调用的方法在userDetail中有定义的。* additionalAuthenticationChecks : 这个就是用户名密码验证的过程了。
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()));  }}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. Android(安卓)- Manifest 文件 详解
  3. Android的Handler机制详解3_Looper.looper()不会卡死主线程
  4. Selector、shape详解(一)
  5. android2.2资源文件详解4--menu文件夹下的菜单定义
  6. Android发送短信方法实例详解
  7. EditText的属性:android:selectAllOnFocus
  8. Android(安卓)SyncManager 实现
  9. Android(安卓)读取资源文件实例详解

随机推荐

  1. 在linux 列出 超级用户 普通用户和 系统
  2. Ubuntu 14.04 LTS 使用sudo免输密码
  3. 为SWIG指定Python头和库。
  4. 如何在qt上访问父窗口小部件?
  5. Linux 常用命令汇总--加了注释
  6. Scientific Linux:我需要获取一个shell脚
  7. Linux进程间通信—— 内存映射
  8. 正则表达式匹配安全的openssl和不安全的o
  9. linux实战-redis(1) -- 在centos中安装redi
  10. 小小的一句话愁了一天!