Helius
2021-05-27 9a968ba186af5280fcc29cc3eb04412eff204ba7
src/main/java/com/xcong/excoin/configurations/security/TokenFilter.java
@@ -12,6 +12,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.dao.MemberDao;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.utils.RedisUtils;
import com.xcong.excoin.utils.SpringContextHolder;
@@ -28,6 +29,7 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.*;
import java.io.IOException;
import java.util.ArrayList;
@@ -65,13 +67,13 @@
                    MemberEntity loginUser = JSONObject.parseObject(loginStr, MemberEntity.class);
                    Authentication authentication = new UsernamePasswordAuthenticationToken(loginUser, token, new ArrayList<>());
                    SecurityContextHolder.getContext().setAuthentication(authentication);
                    redisUtils.expire(redisKey, 300000);
                    redisUtils.expire(redisKey, 36000);
                } else {
                    log.info("token无法查询:{}", token);
                    SecurityContextHolder.clearContext();
                }
            } else {
                log.info("token为空:{}", request.getRequestURI());
//                log.info("token为空:{}", request.getRequestURI());
                SecurityContextHolder.clearContext();
            }
        } else {
@@ -99,12 +101,12 @@
                if (verifyTokenExpired(Long.parseLong(tokens[1]))) {
                    return tokens[0];
                } else {
                    log.info("前面token为{}", tokens[0]);
                    log.info("时间为:{}, 当前时间为:{}", tokens[1], System.currentTimeMillis());
//                    log.info("前面token为{}", tokens[0]);
//                    log.info("时间为:{}, 当前时间为:{}", tokens[1], System.currentTimeMillis());
                    return AppContants.TIME_OUT;
                }
            }
            log.info("bearerToken---->{}", bearerToken);
//            log.info("bearerToken---->{}", bearerToken);
        } catch (Exception e) {
            log.error("#解析token异常#", e);
            return null;
@@ -116,7 +118,7 @@
        boolean isDebug = applicationProperties.isDebug();
        if (!isDebug) {
            long currentTime = System.currentTimeMillis();
            return currentTime - time <= 5000;
            return currentTime - time <= 10000;
        }
        return true;
    }