Helius
2020-07-10 7b65a55c4ca740f16f2316c3ddc02fc335be3388
src/main/java/com/xcong/excoin/configurations/security/TokenFilter.java
@@ -9,6 +9,7 @@
import com.xcong.excoin.common.system.bean.LoginUserBean;
import com.xcong.excoin.configurations.properties.ApplicationProperties;
import com.xcong.excoin.configurations.properties.SecurityProperties;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.utils.RedisUtils;
import com.xcong.excoin.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
@@ -43,6 +44,7 @@
    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端
@@ -53,9 +55,10 @@
            }
            String loginStr = (String) redisUtils.get(redisKey);
            log.info("当前登陆用户为:{}", loginStr);
            if (StrUtil.isNotBlank(loginStr)) {
                LoginUserBean loginUser = JSONObject.parseObject(loginStr, LoginUserBean.class);
                Authentication authentication = new UsernamePasswordAuthenticationToken(loginUser.getMemberEntity(), token, new ArrayList<>());
                MemberEntity loginUser = JSONObject.parseObject(loginStr, MemberEntity.class);
                Authentication authentication = new UsernamePasswordAuthenticationToken(loginUser, token, new ArrayList<>());
                SecurityContextHolder.getContext().setAuthentication(authentication);
                redisUtils.expire(redisKey, 300000);
            } else {