Shiro SimpleAuthenticationInfo使用
2017-11-25 21:55
232 查看
SimpleAuthenticationInfo这里原理很简单,又有一些值得挖掘的东西。
这个东西是在realm中的,第一个参数user,这里好多地方传的时候都是user对象,但是都在备注用户名。可是我如果传入username,就会报类型转换问题。
但是在开涛大神的博客中,无状态的shiro里,那边给出的例子是传username。我自己测试的,可以传username,也可以传user对象,仅限他那边一段代码。网上有文章说,这里其实是user和username的集合,后端是分两个字段接收的。由于时间的问题,没有深入里了解这块,传user对象是OK的。
第二个字段是user.getPassword(),注意这里是指从数据库中获取的password。
第三个字段是realm,即当前realm的名称。
看了几篇文章介绍说,这块对比逻辑是先对比username,但是username肯定是相等的,所以真正对比的是password。从这里传入的password(这里是从数据库获取的)和token(filter中登录时生成的)中的password做对比,如果相同就允许登录,不相同就抛出异常。
如果验证成功,最终这里返回的信息authenticationInfo 的值与传入的第一个字段的值相同(我这里传的是user对象)。
//此处使用的是user对象,不是username SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( user, user.getPassword(), getName() );
这个东西是在realm中的,第一个参数user,这里好多地方传的时候都是user对象,但是都在备注用户名。可是我如果传入username,就会报类型转换问题。
但是在开涛大神的博客中,无状态的shiro里,那边给出的例子是传username。我自己测试的,可以传username,也可以传user对象,仅限他那边一段代码。网上有文章说,这里其实是user和username的集合,后端是分两个字段接收的。由于时间的问题,没有深入里了解这块,传user对象是OK的。
第二个字段是user.getPassword(),注意这里是指从数据库中获取的password。
第三个字段是realm,即当前realm的名称。
看了几篇文章介绍说,这块对比逻辑是先对比username,但是username肯定是相等的,所以真正对比的是password。从这里传入的password(这里是从数据库获取的)和token(filter中登录时生成的)中的password做对比,如果相同就允许登录,不相同就抛出异常。
如果验证成功,最终这里返回的信息authenticationInfo 的值与传入的第一个字段的值相同(我这里传的是user对象)。
相关文章推荐
- 使用shiro框架进行用户登录认证报错(HTTP Status 500 - Authentication failed for token submission )解决
- shiro重复登录不重新执行doGetAuthenticationInfo认证解决办法
- 使用shiro的SimpleHash来生成常用的摘要串
- 【Shiro】调用doGetAuthenticationInfo进行认证成功之后,isAuthenticated是false的问题。
- shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决
- shiro doGetAuthenticationInfo
- shiro 使用缓存时出现:java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource
- shiro 使用缓存时出现:java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource
- shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决
- WPF IDataErrorInfo使用-数据对象上验证
- Apache Shiro 使用手册(四)Realm 实现
- 使用SimpleDateFormat可以获取给定日期的年份、月份、日期和月份
- (12)ListView之SimpleAdapter的使用
- ListView与SimpleAdapter的使用
- win32环境下配置使用php_fileinfo.dll
- SHELLEXECUTEINFO 和 ShellExecuteEx的使用
- dubbo监控工具dubbo-monitor-simple安装使用
- ActiveMQ(3) ActiveMQ创建(simpleAuthenticationPlugin)安全认证
- Android SimpleDateFormat的使用
- Info 命令的使用