【问题标题】:Does calling the method "SecurityUtils.getSubject();" will always hit the redis database?是否调用方法“SecurityUtils.getSubject();”会一直打redis数据库吗?
【发布时间】:2019-08-22 15:14:21
【问题描述】:

我正在我的项目中实现 redis-shiro 会话管理功能,目前我对 Shiro 和 Redis 的信息很少。

我想知道每次调用下面是否会访问redis数据库以检查redis数据库中是否存在任何sessionId。

服务中的代码

Subject currentUser = SecurityUtils.getSubject();
 Session session = currentUser.getSession();

控制器中的代码:

 public String getSomrthing(@CookieValue("JSESSIONID") String fooCookie){
       callingSomeServiceMethod(fooCookie);
       return "It does not matter";
   }

我们是否必须像下面在我们的服务中手动匹配 sessionId 还是 Shiro 会自动匹配它,因为我的应用程序将在多实例环境中运行。?

Subject currentUser = SecurityUtils.getSubject();
   if(currentUser.getId.equals(fooCookie)){
        //.....Some Code 
       //.....Some Code
  }

【问题讨论】:

    标签: java spring-boot redis shiro


    【解决方案1】:

    会话将在每个请求中最多查找一次,这取决于您配置的任何其他缓存。

    不过,您不会直接从控制器管理/查找 sessionId。所有这些逻辑都是透明的,并由 Shiro 和/或您的 servlet 容器的会话管理处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-24
      • 2012-08-29
      • 2011-10-07
      • 1970-01-01
      相关资源
      最近更新 更多