3.2K Star 34.5K Fork 24.6K

若依 / RuoYi-Vue

 / 详情

token过滤器方法的问题JwtAuthenticationTokenFilter

已完成
创建于  
2024-06-19 14:54

这个方法中 @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { LoginUser loginUser = tokenService.getLoginUser(request); if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) { tokenService.verifyToken(loginUser); UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities()); authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(authenticationToken); } chain.doFilter(request, response); }
if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication()))不太明白,当前用户未登录,当前用户登录token过期了,当前用户登录token没过期,这三种情况下这个if成立吗?
另外token自动续期在哪里实现的?

评论 (1)

fanfada 创建了任务
  • 当前用户未登录:你前端传递的header中都不一定有token,getLoginUser(request)压根解析不出来,返回null。
  • 当前用户登录token过期了:此时getLoginUser(request)虽然能解析出token,但是在redis缓存中却查不出来,也是返回null。
  • 当前用户登录token没过期:此时getLoginUser(request)能返回出用户信息,然后后续再走 tokenService.verifyToken(loginUser),可能会触发refreshToken(loginUser)来实现token自动续期。
若依 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
JavaScript
1
https://gitee.com/y_project/RuoYi-Vue.git
git@gitee.com:y_project/RuoYi-Vue.git
y_project
RuoYi-Vue
RuoYi-Vue

搜索帮助

344bd9b3 5694891 D2dac590 5694891