3 changed files with 36 additions and 0 deletions
@ -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()); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -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 { |
||||
|
} |
Loading…
Reference in new issue