| | |
| | | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
| | | HttpServletRequest request = (HttpServletRequest) servletRequest; |
| | | String token = resolveToken(request); |
| | | log.info("token为-->{}", token); |
| | | if (StrUtil.isNotBlank(token)) { |
| | | String redisKey = ""; |
| | | // 根据user-agent判断pc端还是app端 |
| | |
| | | } |
| | | |
| | | String loginStr = (String) redisUtils.get(redisKey); |
| | | log.info("当前登陆用户为:{}", loginStr); |
| | | if (StrUtil.isNotBlank(loginStr)) { |
| | | MemberEntity loginUser = JSONObject.parseObject(loginStr, MemberEntity.class); |
| | | Authentication authentication = new UsernamePasswordAuthenticationToken(loginUser, token, new ArrayList<>()); |
| | | SecurityContextHolder.getContext().setAuthentication(authentication); |
| | | redisUtils.expire(redisKey, 300000); |
| | | } else { |
| | | log.info("token无法查询:{}", token); |
| | | SecurityContextHolder.clearContext(); |
| | | } |
| | | } else { |
| | | log.info("token为空:{}", request.getRequestURI()); |
| | | SecurityContextHolder.clearContext(); |
| | | } |
| | | |