title: How can I get the client IP address of requests in Spring Boot?
body: <p>I'm having trouble with my security configuration and I need to create a list of the Ip's that are accessing my application.</p>
  
  <p>My problem is to get the Ip in a dynamic way for all my application requests.
  But I don't want to add a HttpServletRequest for all the requests of my application, what I want is a method that is called before every request, even before SecurityConfig events.</p>
  
  <p>What I've tried to do is to use AuthenticationProvider to get the request HttpServletRequest and then get the Ip of my client. The problem is that I can't find a way to create a single class and it connects to all my requests. This is my code:</p>
  
  <pre><code>public abstract class IPAddressBasedAuthenticationProvider implements AuthenticationProvider {
  
    /**
     * Context http request
     */
    @Autowired
    private HttpServletRequest request;
  
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  
        String ipAddress = request.getRemoteAddr();
        System.out.println(ipAddress);
        return authentication;
    }
  }
  </code></pre>
  
  <p>What I was thinking was that my requests where going to pass in this code and then show my client Ip.</p>
  
  <p>I tried autowiring it in my controller classes but my application doesn't execute then.
  What can I do to make this work?</p>