月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-10-08 495253345194da937f134cfb2adb9eaf00c413d5
src/main/java/com/moon/server/interceptor/AuthInterceptor.java
@@ -29,19 +29,19 @@
    private static final Log log = LogFactory.getLog(AuthInterceptor.class);
    private static final String NO_TOKEN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.TOKEN_ERROR, "找不到令牌"));
    public static final String NO_TOKEN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.TOKEN_ERROR, "找不到令牌"));
    private static final String NO_LOGIN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.NO_LOGIN_ERROR, "用户未登录"));
    public static final String NO_LOGIN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.NO_LOGIN_ERROR, "用户未登录"));
    private static final String USER_LOCK = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.USER_LOCK_ERROR, "用户ID已禁用"));
    public static final String USER_LOCK = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.USER_LOCK_ERROR, "用户ID已禁用"));
    private static final String NO_AUTH = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.NO_AUTH_ERROR, "无权限访问"));
    public static final String NO_AUTH = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.NO_AUTH_ERROR, "无权限访问"));
    private static final String IP_NULL = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.UNAUTHORIZED, "IP地址为空"));
    public static final String IP_NULL = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.UNAUTHORIZED, "IP地址为空"));
    private static final String BLACK_LIST = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.UNAUTHORIZED, "该IP入黑名单"));
    public static final String BLACK_LIST = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.UNAUTHORIZED, "IP列入黑名单"));
    private static final String ILLEGAL_TOKEN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.UNAUTHORIZED, "令牌来源非法"));
    public static final String ILLEGAL_TOKEN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.UNAUTHORIZED, "令牌来源非法"));
    public AuthInterceptor(SysService sysService) {
        this.sysService = sysService;
@@ -65,8 +65,8 @@
                return WebHelper.writeStr2Page(response, NO_TOKEN);
            }
            // 3.获取用户令牌
            UserEntity ue = sysService.tokenService.getCurrentUser(request);
            // 3.获取用户
            UserEntity ue = sysService.tokenService.getUserByToken(token);
            if (ue == null) {
                return WebHelper.writeStr2Page(response, NO_LOGIN);
            }
@@ -87,9 +87,8 @@
                return true;
            }
            // 7.检查白名单
            // 7.检查白名单和IP一致性
            if (!checkWhiteList(ip, request)) {
                // 检查IP一致性
                if (!checkIpSource(ip, token)) {
                    return WebHelper.writeStr2Page(response, ILLEGAL_TOKEN);
                }
@@ -174,11 +173,11 @@
    }
    /**
     * 检查IP一致性
     * 检查IP一致性:固定令牌不检查
     */
    private boolean checkIpSource(String ip, String token) {
        TokenEntity te = sysService.tokenService.getEntityByToken(token);
        return te.getIp().equals(ip);
        return StaticData.I1 == te.getType() || te.getIp().equals(ip);
    }
}