mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
校验token
This commit is contained in:
@@ -46,10 +46,11 @@ public interface RouteInterceptor {
|
||||
/**
|
||||
* 是否匹配,返回true执行拦截器,默认true
|
||||
*
|
||||
* @param context context
|
||||
* @param context context
|
||||
* @param apiInfoDTO 接口信息
|
||||
* @return 返回true执行拦截器
|
||||
*/
|
||||
default boolean match(ApiRequestContext context) {
|
||||
default boolean match(ApiRequestContext context, ApiInfoDTO apiInfoDTO) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -19,11 +19,6 @@ import org.springframework.stereotype.Component;
|
||||
public class TokenValidateInterceptor implements RouteInterceptor {
|
||||
@Override
|
||||
public void preRoute(ApiRequestContext context, ApiInfoDTO apiInfoDTO) {
|
||||
Integer isNeedToken = apiInfoDTO.getIsNeedToken();
|
||||
if (YesOrNoEnum.of(isNeedToken) == YesOrNoEnum.NO) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 走到这里token肯定有值
|
||||
String appAuthToken = context.getApiRequest().getAppAuthToken();
|
||||
|
||||
@@ -32,6 +27,12 @@ public class TokenValidateInterceptor implements RouteInterceptor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(ApiRequestContext context, ApiInfoDTO apiInfoDTO) {
|
||||
Integer isNeedToken = apiInfoDTO.getIsNeedToken();
|
||||
return YesOrNoEnum.of(isNeedToken) == YesOrNoEnum.YES;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验token是否合法
|
||||
*
|
||||
|
@@ -121,7 +121,9 @@ public class RouteServiceImpl implements RouteService {
|
||||
|
||||
protected void doPreRoute(ApiRequestContext apiRequestContext, ApiInfoDTO apiInfoDTO) {
|
||||
for (RouteInterceptor routeInterceptor : routeInterceptors) {
|
||||
routeInterceptor.preRoute(apiRequestContext, apiInfoDTO);
|
||||
if (routeInterceptor.match(apiRequestContext, apiInfoDTO)) {
|
||||
routeInterceptor.preRoute(apiRequestContext, apiInfoDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user