|
@@ -0,0 +1,38 @@
|
|
|
+package com.fdkankan.openApi.aop;
|
|
|
+
|
|
|
+import cn.hutool.extra.servlet.ServletUtil;
|
|
|
+import com.fdkankan.openApi.service.system.ITIpWhiteService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.aspectj.lang.JoinPoint;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+import org.aspectj.lang.annotation.Before;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+@Order(999)
|
|
|
+@Component
|
|
|
+@Aspect
|
|
|
+@Slf4j
|
|
|
+public class ValidateIpAOP {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ITIpWhiteService itIpWhiteService;
|
|
|
+
|
|
|
+
|
|
|
+ @Before("@annotation(validateIp)")
|
|
|
+ public void doBefore(JoinPoint joinPoint, ValidateIp validateIp) {
|
|
|
+ ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
|
+ HttpServletRequest request = servletRequestAttributes.getRequest();
|
|
|
+
|
|
|
+ String clientIP = ServletUtil.getClientIP(request);
|
|
|
+ log.info("validateIp-访问ip,{}", clientIP);
|
|
|
+ itIpWhiteService.checkIp(clientIP);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|