shrio缓存 用户 权限失效

  1. 系统使用了 redis 缓存 用户的 权限,现在的问题的是权限没有被缓存。

    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException,DisabledAccountException {
        ShiroToken token = (ShiroToken) authcToken;
        
        Person person = loginService.login(token.getUsername(),token.getPswd(),token.getHost());
        
        if(null == person)
            throw new AccountException("帐号或密码不正确!");
        
        if(!CloseEnums.NOCLOSE.getState().equals(person.getClose()))
            throw new DisabledAccountException("帐号已经禁止登录!");
        
        return new SimpleAuthenticationInfo(person,person.getPersonPwd(), getName());
        
    } 

用户登录 重写。

@Override
    public V get(K key) throws CacheException {
        byte[] byteKey = SerializeUtil.serialize(buildCacheKey(key));
        Object byteValue = null;
        try {
            byteValue = jedisManager.getValueByKey(DB_INDEX, byteKey);
            System.out.println("get " + key);
        } catch (Exception e) {
            LoggerUtils.error(SELF, "get value by cache throw exception",e);
        }
        return (V) byteValue;
    }

每次访问 打印的 key值都在变化。

Person person = (Person)SecurityUtils.getSubject().getPrincipal();
        
System.out.println(" getToken 2 " + person);

这个打印的值也是跟着上面变化。
--- 值是没有变化的,变化的是 对象地址。因为对象地址在不断的变换,导致 redis 的 key 不停的变化 缓存不了权限 一个类似的问题 http://shiro-user.582556.n2.n...

阅读 3.3k
1 个回答

你这块buildCacheKey是怎样的呢?还有 用户登录 重写。 get 方法 是 Shrio 的方法么?【没使用过这个权限框架】

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题