rg.crazycake.shiro.exception.PrincipalInstanceException: class java.util.HashMap must has getter for field: id
We need a field to identify this Cache Object in Redis. So you need to defined an id field which you can get unique id to identify this principal. For example, if you use UserInfo as Principal class, the id field maybe userId, userName, email, etc. For example, getUserId(), getUserName(), getEmail(), etc.
Default value is "id", that means your principal object has a method called "getId()"

shiro与redis整合过程中出现以上的问题:根据错误的信息,是信息认证实体中需要id的getter信息。根据官方文档配置相应的模块:

cacheManager.principalIdFieldName = <your id field name of principal object>

在spring boot 中的非xml配置如下:

/**
* cacheManager 缓存 redis实现
* 使用的是shiro-redis开源插件
*
* @return
*/
public RedisCacheManager cacheManager() {
RedisCacheManager redisCacheManager = new RedisCacheManager();
redisCacheManager.setRedisManager(redisManager());
redisCacheManager.setPrincipalIdFieldName("id");
return redisCacheManager;
}
在shiro realm中修改认证的信息配置如下:
@Override
public AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String useranme = (String) token.getPrincipal();
System.out.println("登录方法:" + useranme);
User user = new User();
user = userService.getCredential(useranme);
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getPassword(), ByteSource.Util.bytes(user.getSalt()), getName());
Session session = SecurityUtils.getSubject().getSession();
session.setAttribute("username", useranme);
return info;
}

调整之后可以正常进入授权啦~~
 

shiro无法进入授权的方法org.crazycake.shiro.exception.PrincipalInstanceException: class java.util.HashMap must has getter for field: id的更多相关文章

  1. Shiro中的授权问题(二)

    上篇博客(Shiro中的授权问题 )我们介绍了Shiro中最最基本的授权问题,以及常见的权限字符的匹配问题.但是这里边还有许多细节需要我们继续介绍,本节我们就来看看Shiro中授权的一些细节问题. 验 ...

  2. Shiro学习总结(10)——Spring集成Shiro

    1.引入Shiro的Maven依赖 [html] view plain copy <!-- Spring 整合Shiro需要的依赖 --> <dependency> <g ...

  3. 【从0到1,搭建Spring Boot+RESTful API+Shiro+Mybatis+SQLServer权限系统】05、Shiro集成

    1.POM文件中加入Shiro和fastJSON依赖 <dependency> <groupId>org.apache.shiro</groupId> <ar ...

  4. java遍历Hashmap/Hashtable的几种方法

    一>java遍历Hashtabe: import java.util.Hashtable; import java.util.Set; public class HashTableTest { ...

  5. Java 之HashMap.values()方法误用

    1.出错 今天在测试代码的时候发现程序报错,看代码才知道是使用HashMap.values()方法的时候出错.因为项目中需要获取Map的值的集合然后进行遍历,所以就很自然的调用了HashMap.val ...

  6. java中HashMap的基本方法使用

    遍历,添加词,等等 package test; import java.util.HashMap; import java.util.Iterator; import java.util.ArrayL ...

  7. java.util.ConcurrentModificationException 异常解决的方法及原理

    近期在修程序的bug,发现后台抛出下面异常: Exception in thread "main" java.util.ConcurrentModificationExceptio ...

  8. Shiro【授权、整合Spirng、Shiro过滤器】

    前言 本文主要讲解的知识点有以下: Shiro授权的方式简单介绍 与Spring整合 初始Shiro过滤器 一.Shiro授权 上一篇我们已经讲解了Shiro的认证相关的知识了,现在我们来弄Shiro ...

  9. Shiro中的授权问题

    在初识Shiro一文中,我们对Shiro的基本使用已经做了简单的介绍,不懂的小伙伴们可以先阅读上文,今天我们就来看看Shiro中的授权问题. Shiro中的授权,大体上可以分为两大类,一类是隐式角色, ...

随机推荐

  1. python写入文件编码报错

    decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode('gb2312'),表示将gb2312编码的字符串str1转换成unicode编码. encode的作用是将u ...

  2. jq中打开新页面 并获取携带值

    打开新页面:window.location.href = "./index.html?id=1"获取携带值: function GetRequest() { var url = l ...

  3. superset 错误解决

    访问superset localhost:8088   securety->list Role 报错 xxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx ...

  4. 如何使用ROS查找rgbdslam代码包框架的输入

    我想这是一个天大的错误,在没有对整个ROS下的代码有一个整体理性的认知时,我使用感性认知. 由于在跑他的测试代码时,只替换了两个节点的名称,相当于remap了它,以为就可以跑了,结果是不行的. 然后用 ...

  5. windows severs 2008r2 180天激活

    无需破解:Windows Server 2008 R2 至少免费使用 900天 1.首先安装后,有一个180天的试用期. 2.在180天试用期即将结束时,使用下面的评估序列号激活Svr 2008 R2 ...

  6. 1、gitlab的理论知识

    2.1 svn与git对比 . svn git 分布式 不是 是 在线阅读 不支持 不仅支持,而且可以在线编辑 存储方式 按文件 按元数据 完整性 一般 优 离线工作 日志都没法看 完全没问题 分支 ...

  7. php魔术常量、超全局变量、魔术方法

    一.魔术常量(魔术变量) 概念:所谓的魔术常量就是PHP预定义的一些常量,这些常量会随着所在的位置而变化. 1.__LINE__  获取文件中的当前行号. 2.__FILE__  获取文件的完整路径和 ...

  8. C语言中malloc函数的使用方法

    C语言中malloc是动态内存分配函数.函数原型:void *malloc(unsigned int num_bytes);参数:num_bytes 是无符号整型,用于表示分配的字节数.返回值:如果分 ...

  9. JMeter - 如何创建可重用和模块化测试脚本

    概述: 我的应用程序几乎没有业务关键流程,我们可以从中提出不同的业务工作流程.当我试图在JMeter中提出性能测试脚本时,我需要找到一些方法来创建可重用/模块化的测试脚本.这样我就可以创建不同的工作流 ...

  10. 解决tomcat闪退问题

    https://blog.csdn.net/zh2nd/article/details/79068680 转载此博客链接内容,非常感谢博主 本文参考CSDN博主 哈克沃德.的<Tomcat8启动 ...