Package com.axelor.common.net
Class ClientAddressResolver
java.lang.Object
com.axelor.common.net.ClientAddressResolver
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
X_FORWARDED_FOR
- See Also:
-
-
Constructor Details
-
ClientAddressResolver
Creates a resolver.- Parameters:
clientIpHeader- the header providing the client IP address, ornullto useX-Forwarded-For
-
-
Method Details
-
resolve
Resolves the client address.- Parameters:
headers- returns the value of a request header, ornullif missingremoteAddr- the address of the direct peer of the connection- Returns:
- the normalized client address, or
remoteAddrif it can't be resolved from the headers
-