Shiro-----凭证匹配器

一.概述

在实际应用中数据库密码都是加密的。Shiro内置了凭证匹配器,通过简单配置就可以实现明文数据和数据库中加密数据匹配的效果。

二.步骤总结

1.修改自定义的Realm

AuthenticationInfo 的构造方法由三个参数变成四个参数的。新增第三个参数表示加盐。一般都是拿用户数据的id作为盐。

  SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getPassword(), ByteSource.Util.bytes(user.getSalt()), "myrealm");

2.修改配置文件

[main]
md5CredentialsMatcher=org.apache.shiro.authc.credential.Md5CredentialsMatcher
#迭代次数
md5CredentialsMatcher.hashIterations=3

myrealm= com.yrp.realm.MyRealmAuthorizing
myrealm.credentialsMatcher=$md5CredentialsMatcher
securityManager.realms=$myrealm
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值