li4wang commented on code in PR #1943:
URL: https://github.com/apache/zookeeper/pull/1943#discussion_r1038401440
##########
zookeeper-server/src/main/java/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java:
##########
@@ -128,4 +131,18 @@ public boolean isValid(String id) {
return true;
}
+ /**
+ * Returns the HTTP(s) client IP address
+ * @param request HttpServletRequest
+ * @return IP address
+ */
+ public static String getClientIPAddress(final HttpServletRequest request) {
+ // to handle the case that a HTTP(s) client connects via a proxy or
load balancer
+ final String xForwardedForHeader =
request.getHeader(X_FORWARDED_FOR_HEADER_NAME);
+ if (xForwardedForHeader == null) {
+ return request.getRemoteAddr();
+ }
+ // the format of the field is: X-Forwarded-For: client, proxy1, proxy2
...
+ return new StringTokenizer(xForwardedForHeader,
",").nextToken().trim();
+ }
Review Comment:
This method is in `IPAuthenticationProvider `as it will be used by
`IPAuthenticationProvider` when providing IP auth support for admin server
APIs.
`IPAuthenticationProvider` will be enhanced for authenticating both
Zookeeper client and Admin Server APIs by the client IP address.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]