Reputation: 103
So let me first try to explain what I need and the use case so it will be easy to circle around my request:
We are building a voting system based on Quarkus and have to restrict under certain conditions the voter to be able to vote, e.g. he registered that he lives in France but the request is coming from Zambia.
For that we are thinking about getting the IP address of the request and with the help of ip2location.com, we plan on determining the location of the voter. The only mention that I saw to get the IP address was in a sample code regarding logging and I have found none to be able to get it from inside my code to be processed (in our case, get the IP, call the ip2location service, match against the database, reject or validate the vote).
So how can I get that IP address from inside an application built with Quarkus?
@Inject HttpServletRequest or @Inject HttpRequest definitely don't work.
Regards, D.
Upvotes: 0
Views: 1486
Reputation: 64011
You can use:
@Context
HttpServerRequest request;
...
request.remoteAddress();
in a JAX-RS resource class.
But even that won't be enough if you are behind a proxy. Im that case you would likely need to the read the X-Forwarded-For
HTTP header.
Upvotes: 2