校验token

This commit is contained in:
六如
2025-02-27 20:11:41 +08:00
parent b0a68908bd
commit a748399e41

View File

@@ -2,7 +2,9 @@ package com.gitee.sop.gateway.interceptor.internal;
import com.gitee.sop.gateway.common.ApiInfoDTO;
import com.gitee.sop.gateway.common.enums.YesOrNoEnum;
import com.gitee.sop.gateway.exception.ApiException;
import com.gitee.sop.gateway.interceptor.RouteInterceptor;
import com.gitee.sop.gateway.message.ErrorEnum;
import com.gitee.sop.gateway.request.ApiRequestContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -24,10 +26,22 @@ public class TokenValidateInterceptor implements RouteInterceptor {
// 这里做校验token操作如从redis查询token是否存在
// 走到这里token肯定有值
String appAuthToken = context.getApiRequest().getAppAuthToken();
log.info("访问token={}", appAuthToken);
// token不对抛出下面这个异常即可
// throw new ApiException(ErrorEnum.AOP_INVALID_AUTH_TOKEN, context.getLocale());
if (!checkToken(appAuthToken, context, apiInfoDTO)) {
throw new ApiException(ErrorEnum.AOP_INVALID_AUTH_TOKEN, context.getLocale());
}
}
/**
* 校验token是否合法
*
* @param appAuthToken token
* @param context 上下文
* @param apiInfoDTO 接口信息
* @return 返回true表示token合法false不合法
*/
protected boolean checkToken(String appAuthToken, ApiRequestContext context, ApiInfoDTO apiInfoDTO) {
// 完善token校验
return true;
}
}