From 252788642fac8edb4f92405f1baca3351a9d13b3 Mon Sep 17 00:00:00 2001 From: gsd Date: Sun, 12 Mar 2023 23:20:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=B4=D1=83=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=B3=D0=BE=D0=B2=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../annotations/impl/ShowClientIPAspect.java | 23 +++++++++++++++++++ .../annotations/interfaces/ShowClientIP.java | 11 +++++++++ .../controllers/user/ProfileController.java | 2 ++ 3 files changed, 36 insertions(+) create mode 100644 src/main/java/app/annotations/impl/ShowClientIPAspect.java create mode 100644 src/main/java/app/annotations/interfaces/ShowClientIP.java diff --git a/src/main/java/app/annotations/impl/ShowClientIPAspect.java b/src/main/java/app/annotations/impl/ShowClientIPAspect.java new file mode 100644 index 0000000..72ac4b9 --- /dev/null +++ b/src/main/java/app/annotations/impl/ShowClientIPAspect.java @@ -0,0 +1,23 @@ +package app.annotations.impl; + +import jakarta.servlet.http.HttpServletRequest; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Configuration; + +@Aspect +@Configuration +public class ShowClientIPAspect { + + private final Logger logger = LoggerFactory.getLogger(ShowClientIPAspect.class); + + @Before("@annotation(app.annotations.interfaces.ShowClientIP) && args(request,..)") + public void before(HttpServletRequest request) { + String client_ip = request.getHeader("X-Forwarded-For"); + if (client_ip != null) { + logger.info("Client IP: {}, Request: {}", client_ip, request.getRequestURI()); + } + } +} diff --git a/src/main/java/app/annotations/interfaces/ShowClientIP.java b/src/main/java/app/annotations/interfaces/ShowClientIP.java new file mode 100644 index 0000000..41e6afe --- /dev/null +++ b/src/main/java/app/annotations/interfaces/ShowClientIP.java @@ -0,0 +1,11 @@ +package app.annotations.interfaces; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ShowClientIP { +} diff --git a/src/main/java/app/controllers/user/ProfileController.java b/src/main/java/app/controllers/user/ProfileController.java index 850397d..56a160c 100644 --- a/src/main/java/app/controllers/user/ProfileController.java +++ b/src/main/java/app/controllers/user/ProfileController.java @@ -3,6 +3,7 @@ package app.controllers.user; import app.annotations.enums.AuthMethod; import app.annotations.interfaces.BurstUpdatePlayers; import app.annotations.interfaces.CheckWebAccess; +import app.annotations.interfaces.ShowClientIP; import app.annotations.interfaces.WaitAfterNext; import app.entities.SocialAuth; import app.services.ProfileService; @@ -41,6 +42,7 @@ public class ProfileController { @CheckWebAccess @BurstUpdatePlayers @WaitAfterNext + @ShowClientIP public ResponseEntity GetCurrentUser(HttpServletRequest request, @CookieValue(value = "steam64", defaultValue = "") String steam64, @RequestParam(value = "requests", defaultValue = "") String requests