数据库账号密码加密详解及实例
16lz
2022-01-02
数据库账号密码加密详解及实例
数据库中经常有对数据库账号密码的加密,但是碰到一个问题,在使用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())); }}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
更多相关文章
- MySQL系列多表连接查询92及99语法示例详解教程
- Android(安卓)- Manifest 文件 详解
- Android的Handler机制详解3_Looper.looper()不会卡死主线程
- Selector、shape详解(一)
- android2.2资源文件详解4--menu文件夹下的菜单定义
- Android发送短信方法实例详解
- EditText的属性:android:selectAllOnFocus
- Android(安卓)SyncManager 实现
- Android(安卓)读取资源文件实例详解