List of usage examples for io.netty.handler.ipfilter IpSubnetFilterRule matches
@Override public boolean matches(InetSocketAddress remoteAddress)
From source file:org.elasticsearch.xpack.security.transport.filter.SecurityIpFilterRuleTests.java
License:Open Source License
public void testParseIpSubnetFilterRule() throws Exception { final boolean allow = randomBoolean(); IpFilterRule rule = getRule(allow, "127.0.0.0/24"); assertThat(rule, instanceOf(IpSubnetFilterRule.class)); if (allow) {//from www. j a v a 2 s.c om assertEquals(rule.ruleType(), IpFilterRuleType.ACCEPT); } else { assertEquals(rule.ruleType(), IpFilterRuleType.REJECT); } IpSubnetFilterRule ipSubnetFilterRule = (IpSubnetFilterRule) rule; assertTrue(ipSubnetFilterRule.matches(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0))); }
From source file:org.springframework.cloud.gateway.handler.predicate.RemoteAddrRoutePredicateFactory.java
License:Apache License
@Override public Predicate<ServerWebExchange> apply(Config config) { List<IpSubnetFilterRule> sources = convert(config.sources); return exchange -> { InetSocketAddress remoteAddress = config.remoteAddressResolver.resolve(exchange); if (remoteAddress != null && remoteAddress.getAddress() != null) { String hostAddress = remoteAddress.getAddress().getHostAddress(); String host = exchange.getRequest().getURI().getHost(); if (log.isDebugEnabled() && !hostAddress.equals(host)) { log.debug("Remote addresses didn't match " + hostAddress + " != " + host); }// w w w. jav a 2 s . c o m for (IpSubnetFilterRule source : sources) { if (source.matches(remoteAddress)) { return true; } } } return false; }; }