These are chat archives for spring-cloud/spring-cloud

14th
Jan 2018
Spencer Gibb
@spencergibb
Jan 14 2018 00:55
@Fitzoh yup, super simple now. Should probably add a helper method in ServerWebExchangeUtils if there isn't one already.
Andrew Fitzgerald
@fitzoh
Jan 14 2018 00:55
cool
I’m working on a building out a simple ip whitelist filter
currently running into using issues with using RemoteAddrRoutePredicateFactory with forwards… How would you feel about making it configurable so you could either pull from remoteAddress or X-Forwarded-For?
current workaround:

public class ForwardAwareRemoteAddrRoutePredicateFactory extends RemoteAddrRoutePredicateFactory {

    public static final String X_FORWARDED_FOR = "X-Forwarded-For";

    private static final Log log = LogFactory.getLog(RemoteAddrRoutePredicateFactory.class);

    public Predicate<ServerWebExchange> apply(List<SubnetUtils> sources) {
        return exchange -> {
            List<String> forwardedIps = exchange.getRequest().getHeaders().get(X_FORWARDED_FOR);
            if (forwardedIps.size() > 0) {
                String hostAddress = forwardedIps.get(0).split(", ")[0];
                String host = exchange.getRequest().getURI().getHost();

                if (!hostAddress.equals(host)) {
                    log.warn("Remote addresses didn't match " + hostAddress + " != " + host);
                }

                for (SubnetUtils source : sources) {
                    if (source.getInfo().isInRange(hostAddress)) {
                        return true;
                    }
                }
            }

            return false;
        };
    }
}
(I’ll put an issue in)
Spencer Gibb
@spencergibb
Jan 14 2018 01:05
sure, PR welcome
Andrew Fitzgerald
@fitzoh
Jan 14 2018 01:05
spring-cloud/spring-cloud-gateway#155
yeah, I’m interested in contributing on that one, just let me know if you have any thoughts on the approach
Spencer Gibb
@spencergibb
Jan 14 2018 02:05
Maybe a configuration option?
Andrew Fitzgerald
@fitzoh
Jan 14 2018 02:06
Yeah, I’m trying to figure out how to pass in multiple arguments to the factory using the Tuple args
    public Predicate<ServerWebExchange> apply(Tuple args) {
        validate(1, args);

        List<SubnetUtils> sources = new ArrayList<>();
        if (args != null) {
            for (Object arg : args.getValues()) {
                addSource(sources, (String) arg);
            }
        }
        return apply(sources);
    }