Shiro SimpleAuthenticationInfo使用细节记录

最近发现 simpleAuthenticationIfo 中的principal疑问。
场景是这个样子的

//此处使用的是user对象,不是username
 SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
         user,
         user.getPassword(),
         getName()
 );

另外一种是

 SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
         username,
         user.getPassword(),
         getName()
 );

这两种写法都可以,那么问题来的。为什么都可以呢?到底principle到底是怎么使用的呢?

后来发现principle用作用户的唯一标识,他并不参与密码等之类的校对。

这个是别人的一些记录:
第一个参数principal使用一个可以表示该用户对象唯一身份的标识即可,其实不建议直接使用用户对象本身,因为如果开启了授权缓存,shiro在存放授权信息到缓存中时会将principal处理后作为key值。使用对象可能会引发一些不可控现象。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值