Class ClientAddressResolver

java.lang.Object
com.axelor.common.net.ClientAddressResolver

public class ClientAddressResolver extends Object
Resolves the IP address of the client that originated a request, from the headers set by a reverse proxy.

The client address is the left-most address of a single header: the configured client IP header, or X-Forwarded-For if none is configured.

If this header is missing, or doesn't provide a valid IP address, the address of the direct peer is used: no other header is tried, as the reverse proxy may not overwrite it, so it may have been forged by the client.

This header is trusted as it is: the reverse proxy must overwrite it, and the application must only be reachable through the proxy.

  • Field Details

  • Constructor Details

    • ClientAddressResolver

      public ClientAddressResolver(String clientIpHeader)
      Creates a resolver.
      Parameters:
      clientIpHeader - the header providing the client IP address, or null to use X-Forwarded-For
  • Method Details

    • resolve

      public String resolve(Function<String,String> headers, String remoteAddr)
      Resolves the client address.
      Parameters:
      headers - returns the value of a request header, or null if missing
      remoteAddr - the address of the direct peer of the connection
      Returns:
      the normalized client address, or remoteAddr if it can't be resolved from the headers