alexxiyang / shiro-redis

shiro only provide the support of ehcache and concurrentHashMap. Here is an implement of redis cache can be used by shiro. Hope it will help you!
MIT License
1.17k stars 446 forks source link

shiro-redis是否不支持将单个用户ID作为shiro的principal存入redis? #108

Open Starix610 opened 5 years ago

Starix610 commented 5 years ago

如果在realm的认证方法中使用用户ID(而不是一个用户对象)作为principal参数传给shiro的new SimpleAuthenticationInfo(userId, credentials, salt, getName())方法,那么在shiro注销的时候就会报这个错(shiro认证和使用过程没有错误,但是注销清除redis中的session时就会报这个错): class java.lang.Long must has getter for field: authCacheKey or 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 authCacheKey or id, that means your principal object has a method called "getAuthCacheKey()" or "getId()"

提示我的principal(用户ID)必须要有一个唯一标识字段,但是我的principal只是一个用户ID。 请问使用该插件是否是在shiro认证时一定要存入用户对象到redis中?如果可以只存用户ID作principal,能告诉我该怎么做吗?

ghost commented 5 years ago

确实如此,redis序列化的是用户对象,而不是用户id,其实我认为id更好。

shanidb4u commented 4 years ago

We are also facing the similar issue that our principal object is a string not an object.