0

I have a web app written in Java using Spring as a backend framework. This application is running on AWS ElasticBeanstalk with an Application Load Balancer. I was wondering how can I get the IP of all the users sending requests to my web app.

[EDIT 1] I noticed that just by doing this I correctly get my ip address.

@GetMapping
public String processData(HttpServletRequest request) {

    String ipAddress = request.getRemoteAddr());

}

I don't know if there are particular cases in which this does not work.

Stefano Sambruna
  • 767
  • 2
  • 10
  • 29

2 Answers2

0

You can enable access logs on ALB which will record all requests to ALB. Info recorded: (https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html) If you have some compliance requirements, don't forget to rotate the logs (s3 lifecycle) accordingly.

zoran2709
  • 171
  • 4
  • Thank you very much for your help. But how can I use this log then? I would like to store the page visits and use them... how can I do that with the solution you gave me? – Stefano Sambruna Dec 03 '19 at 15:34
0

request.getRemoteAddr(); pretty much sums it up. You can do the same for the port and other properties as well.

Hemin
  • 712
  • 1
  • 14
  • 29