@Test public void trustAllReturnsFirstForwardedIp() { ServerWebExchange exchange = buildExchange(oneTwoThreeBuilder()); InetSocketAddress address = trustAll.resolve(exchange); assertThat(address.getHostName()).isEqualTo("0.0.0.1"); }
@Override public InetSocketAddress resolve(ServerWebExchange exchange) { List<String> xForwardedValues = extractXForwardedValues(exchange); Collections.reverse(xForwardedValues); if (!xForwardedValues.isEmpty()) { int index = Math.min(xForwardedValues.size(), maxTrustedIndex) - 1; return new InetSocketAddress(xForwardedValues.get(index), 0); } return defaultRemoteIpResolver.resolve(exchange); }
XForwardedRemoteAddressResolver implements RemoteAddressResolver { @Override public InetSocketAddress resolve(ServerWebExchange exchange) { List<String> xForwardedValues = extractXForwardedValues(exchange); Collections.reverse(xForwardedValues); if (!xForwardedValues.isEmpty()) { int index = Math.min(xForwardedValues.size(), maxTrustedIndex) - 1; return new InetSocketAddress(xForwardedValues.get(index), 0); } return defaultRemoteIpResolver.resolve(exchange); } }
XForwardedRemoteAddressResolver implements RemoteAddressResolver { @Override public InetSocketAddress resolve(ServerWebExchange exchange) { List<String> xForwardedValues = extractXForwardedValues(exchange); Collections.reverse(xForwardedValues); if (!xForwardedValues.isEmpty()) { int index = Math.min(xForwardedValues.size(), maxTrustedIndex) - 1; return new InetSocketAddress(xForwardedValues.get(index), 0); } return defaultRemoteIpResolver.resolve(exchange); } private  XForwardedRemoteAddressResolver(int maxTrustedIndex); }
XForwardedRemoteAddressResolver implements RemoteAddressResolver { @Override public InetSocketAddress resolve(ServerWebExchange exchange) { List<String> xForwardedValues = extractXForwardedValues(exchange); Collections.reverse(xForwardedValues); if (!xForwardedValues.isEmpty()) { int index = Math.min(xForwardedValues.size(), maxTrustedIndex) - 1; return new InetSocketAddress(xForwardedValues.get(index), 0); } return defaultRemoteIpResolver.resolve(exchange); } private  XForwardedRemoteAddressResolver(int maxTrustedIndex); static XForwardedRemoteAddressResolver trustAll(); static XForwardedRemoteAddressResolver maxTrustedIndex(int maxTrustedIndex); @Override InetSocketAddress resolve(ServerWebExchange exchange); }
XForwardedRemoteAddressResolver implements RemoteAddressResolver { @Override public InetSocketAddress resolve(ServerWebExchange exchange) { List<String> xForwardedValues = extractXForwardedValues(exchange); Collections.reverse(xForwardedValues); if (!xForwardedValues.isEmpty()) { int index = Math.min(xForwardedValues.size(), maxTrustedIndex) - 1; return new InetSocketAddress(xForwardedValues.get(index), 0); } return defaultRemoteIpResolver.resolve(exchange); } private  XForwardedRemoteAddressResolver(int maxTrustedIndex); static XForwardedRemoteAddressResolver trustAll(); static XForwardedRemoteAddressResolver maxTrustedIndex(int maxTrustedIndex); @Override InetSocketAddress resolve(ServerWebExchange exchange); static final String X_FORWARDED_FOR; }