SimpleAuthenticationInfo cannot be cast to AuthorizationInfo
hequanb opened this issue · 5 comments
hequanb commented
遇到这么一个问题, shiro把SimpleAuthenticationInfo 换存进去后, 再要取出时, 无法转化为AuthorizationInfo;
shiro源码:
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
if (principals == null) {
return null;
}
AuthorizationInfo info = null;
if (log.isTraceEnabled()) {
log.trace("Retrieving AuthorizationInfo for principals [" + principals + "]");
}
Cache<Object, AuthorizationInfo> cache = getAvailableAuthorizationCache();
if (cache != null) {
if (log.isTraceEnabled()) {
log.trace("Attempting to retrieve the AuthorizationInfo from cache.");
}
Object key = getAuthorizationCacheKey(principals);
** info = cache.get(key); ** // 这里就是报错的地方
if (log.isTraceEnabled()) {
if (info == null) {
log.trace("No AuthorizationInfo found in cache for principals [" + principals + "]");
} else {
log.trace("AuthorizationInfo found in cache for principals [" + principals + "]");
}
}
}
if (info == null) {
// Call template method if the info was not found in a cache
info = doGetAuthorizationInfo(principals);
// If the info is not null and the cache has been created, then cache the authorization info.
if (info != null && cache != null) {
if (log.isTraceEnabled()) {
log.trace("Caching authorization info for principals: [" + principals + "].");
}
Object key = getAuthorizationCacheKey(principals);
cache.put(key, info);
}
}
return info;
}
hequanb commented
应该是同时发出了几个请求, 有一些只有验证身份, 而有一些需要验证权限, 验证身份的请求往缓存内放入了SimpleAuthenticationInfo, 之后验证权限的请求去取缓存的时候无法将SimpleAuthenticationInfo转换为AuthorizationInfo, 请问楼主有这种情况的解决方案吗
dolyw commented
没理解你的意思。。你是改了什么吗,还是说直接执行我现在的代码会报错?
hequanb commented
我呢是参考您的代码的, 并没有直接down下来..
其实主要想问问, 身份的缓存 和 认证的缓存是不是分开的, 也就是说, 认证操作会去缓存取认证的信息的缓存;
而身份操作会去缓存取身份的信息的缓存.
dolyw commented
对啊,肯定是分开的,缓存只有doGetAuthorizationInfo授权方法开启了,doGetAuthenticationInfo认证方法是每次都需要认证的
hequanb commented
一直用自己的想法,以为shiro是把他们合在一起管理的, 浪费了一天时间...
谢谢您哪