【拦截器】更新黑白名单校验拦截器

dev-8.1.9
stylefeng 2024-07-11 11:15:46 +08:00
parent f96673ac20
commit 7830c7a42c
2 changed files with 41 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package cn.stylefeng.guns.config.web;
import cn.stylefeng.guns.core.error.CustomErrorAttributes;
import cn.stylefeng.guns.core.security.BlackWhiteInterceptor;
import cn.stylefeng.guns.core.security.TokenAndPermissionInterceptor;
import cn.stylefeng.roses.kernel.wrapper.field.jackson.CustomJacksonIntrospector;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@ -28,6 +29,9 @@ public class SpringMvcConfiguration implements WebMvcConfigurer {
@Resource
private TokenAndPermissionInterceptor tokenAndPermissionInterceptor;
@Resource
private BlackWhiteInterceptor blackWhiteInterceptor;
/**
*
*
@ -62,7 +66,8 @@ public class SpringMvcConfiguration implements WebMvcConfigurer {
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(tokenAndPermissionInterceptor);
registry.addInterceptor(blackWhiteInterceptor).order(100);
registry.addInterceptor(tokenAndPermissionInterceptor).order(200);
}
/**

View File

@ -0,0 +1,35 @@
package cn.stylefeng.guns.core.security;
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
import cn.stylefeng.roses.kernel.security.blackwhite.BlackWhiteValidateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* web·
*
* @author fengshuonan
* @since 2024/7/11 10:11
*/
@Component
@Slf4j
public class BlackWhiteInterceptor implements HandlerInterceptor {
@Resource
private BlackWhiteValidateService blackWhiteValidateService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// 校验黑白名单
blackWhiteValidateService.totalValidate(HttpServletUtil.getRequestClientIp(request));
return true;
}
}