mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
校验token
This commit is contained in:
@@ -2,7 +2,9 @@ package com.gitee.sop.gateway.interceptor.internal;
|
|||||||
|
|
||||||
import com.gitee.sop.gateway.common.ApiInfoDTO;
|
import com.gitee.sop.gateway.common.ApiInfoDTO;
|
||||||
import com.gitee.sop.gateway.common.enums.YesOrNoEnum;
|
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.interceptor.RouteInterceptor;
|
||||||
|
import com.gitee.sop.gateway.message.ErrorEnum;
|
||||||
import com.gitee.sop.gateway.request.ApiRequestContext;
|
import com.gitee.sop.gateway.request.ApiRequestContext;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -24,10 +26,22 @@ public class TokenValidateInterceptor implements RouteInterceptor {
|
|||||||
// 这里做校验token操作,如从redis查询token是否存在
|
// 这里做校验token操作,如从redis查询token是否存在
|
||||||
// 走到这里token肯定有值
|
// 走到这里token肯定有值
|
||||||
String appAuthToken = context.getApiRequest().getAppAuthToken();
|
String appAuthToken = context.getApiRequest().getAppAuthToken();
|
||||||
log.info("访问token={}", appAuthToken);
|
|
||||||
|
|
||||||
|
if (!checkToken(appAuthToken, context, apiInfoDTO)) {
|
||||||
|
throw new ApiException(ErrorEnum.AOP_INVALID_AUTH_TOKEN, context.getLocale());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// token不对抛出下面这个异常即可
|
/**
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user