JspHelper { public static String getRemoteAddr(HttpServletRequest request) { String remoteAddr = request.getRemoteAddr(); String proxyHeader = request.getHeader("X-Forwarded-For"); if (proxyHeader != null && ProxyServers.isProxyServer(remoteAddr)) { final String clientAddr = proxyHeader.split(",")[0].trim(); if (!clientAddr.isEmpty()) { remoteAddr = clientAddr; } } return remoteAddr; } private  JspHelper(); static DatanodeInfo bestNode(LocatedBlocks blks, Configuration conf); static String validatePath(String p); static Long validateLong(String value); static String getDefaultWebUserName(Configuration conf); static UserGroupInformation getUGI(HttpServletRequest request,
      Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf); static UserGroupInformation getUGI(ServletContext context,
      HttpServletRequest request, Configuration conf,
      final AuthenticationMethod secureAuthMethod,
      final boolean tryUgiParameter); static String getRemoteAddr(HttpServletRequest request); static void checkUsername(final String expected, final String name
      ); static String getDelegationTokenUrlParam(String tokenString); static String getUrlParam(String name, String val, String paramSeparator); static String getUrlParam(String name, String val, boolean firstParam); static String getUrlParam(String name, String val); static final String CURRENT_CONF; static final String DELEGATION_PARAMETER_NAME; static final String NAMENODE_ADDRESS; }
@Test public void testRemoteAddr() { assertEquals(clientAddr, getRemoteAddr(clientAddr, null, false)); }
@Test public void testRemoteAddrWithUntrustedProxy() { assertEquals(proxyAddr, getRemoteAddr(clientAddr, proxyAddr, false)); }
@Test public void testRemoteAddrWithTrustedProxy() { assertEquals(clientAddr, getRemoteAddr(clientAddr, proxyAddr, true)); assertEquals(clientAddr, getRemoteAddr(chainedClientAddr, proxyAddr, true)); }
@Test public void testRemoteAddrWithTrustedProxyAndEmptyClient() { assertEquals(proxyAddr, getRemoteAddr(null, proxyAddr, true)); assertEquals(proxyAddr, getRemoteAddr("", proxyAddr, true)); }