Interface InetAddressFilter
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Strategy interface used for
InetAddress-based filtering.
Allow HTTP clients to offer Server-Side Request Forgery (SSRF) mitigation features, for example by only allowing local addresses to be called.
Filters are typically built using the static factory methods on this interface, optionally combined with one or more of the logic methods. For example:
InetAddressFilter.of("192.168.0.0/24")
.andNot("192.168.0.1");
- Since:
- 4.1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic InetAddressFilteradapt(Predicate<@Nullable InetAddress> predicate) Adapt the givenPredicateinto anInetAddressFilter.static InetAddressFilterall()Return a filter that matches all addresses.default InetAddressFilterReturn a composed filter that represents a short-circuiting logical AND of this filter and other IP addresses.default InetAddressFilterand(Collection<? extends InetAddressFilter> filters) Return a composed filter that represents a short-circuiting logical AND of this filter and other filters.default InetAddressFilterand(InetAddressFilter... filters) Return a composed filter that represents a short-circuiting logical AND of this filter and other filters.default InetAddressFilterReturn a composed filter that represents a short-circuiting logical AND of this filter and othernegatedIP addresses.default InetAddressFilterandNot(Collection<? extends InetAddressFilter> filters) Return a composed filter that represents a short-circuiting logical AND of this filter and othernegatedfilters.default InetAddressFilterandNot(InetAddressFilter... filters) Return a composed filter that represents a short-circuiting logical AND of this filter and othernegatedfilters.static InetAddressFilterReturn a filter that will match external (non-private) IP addresses.static InetAddressFilterReturn a filter that will match internal (private) IP addresses.booleanmatches(InetAddress address) Whether the given address matches.default booleanmatches(InetSocketAddress address) Determine whether the given socket address matches.static InetAddressFilterReturns a filter that will match all multicast addresses.default InetAddressFilternegate()Return a new filter that represents the logical negation of this filter.static InetAddressFilternone()Return a filter that matches no addresses.static InetAddressFilterReturn a filter that is the negation of all the given addresses.static InetAddressFilternot(Collection<? extends InetAddressFilter> filters) Return a filter that is the negation of all the given filters.static InetAddressFilternot(InetAddressFilter... filters) Return a filter that is the negation of all the given matchers.static InetAddressFilterReturn a filter that matches any of the given IP addresses.static InetAddressFilterof(Collection<? extends InetAddressFilter> filters) Return a filter that matches any of the given filters.static InetAddressFilterof(InetAddressFilter... filters) Return a filter that matches any of the given filters.default InetAddressFilterReturn a composed filter that represents a short-circuiting logical OR of this filter and other IP addresses.default InetAddressFilteror(Collection<? extends InetAddressFilter> filters) Return a composed filter that represents a short-circuiting logical OR of this filter and other filters.default InetAddressFilteror(InetAddressFilter... filters) Return a composed filter that represents a short-circuiting logical OR of this filter and other filters.static InetAddressFilterroutable()Returns a filter that will match all routable addresses (not all zeros).static InetAddressFilterReturns a filter that will match special purpose IP addresses as defined by RFC 6890.
-
Method Details
-
matches
Determine whether the given socket address matches.- Parameters:
address- the socket address string to check- Returns:
- if the address matches
-
matches
Whether the given address matches.- Parameters:
address- the address to check- Returns:
- if the address matches
-
and
Return a composed filter that represents a short-circuiting logical AND of this filter and other IP addresses.- Parameters:
addresses- the addresses that will be logically-ANDed with this filter in any form supported byof(String...)- Returns:
- a new composed filter instance
-
and
Return a composed filter that represents a short-circuiting logical AND of this filter and other filters.- Parameters:
filters- the filters that will be logically-ANDed with this filter- Returns:
- a new composed filter instance
-
and
Return a composed filter that represents a short-circuiting logical AND of this filter and other filters.- Parameters:
filters- the filters that will be logically-ANDed with this filter- Returns:
- a new composed filter instance
-
andNot
Return a composed filter that represents a short-circuiting logical AND of this filter and othernegatedIP addresses.- Parameters:
addresses- the addresses that will benegatedand logically-ANDed with this filter in any form supported byof(String...)- Returns:
- a new composed filter instance
-
andNot
-
andNot
-
or
Return a composed filter that represents a short-circuiting logical OR of this filter and other IP addresses.- Parameters:
addresses- the addresses that will be logically-ORed with this filter in any form supported byof(String...)- Returns:
- a new composed filter instance
-
or
Return a composed filter that represents a short-circuiting logical OR of this filter and other filters.- Parameters:
filters- the matchers that will be logically-ORed with this filter- Returns:
- a new composed filter instance
-
or
Return a composed filter that represents a short-circuiting logical OR of this filter and other filters.- Parameters:
filters- the filters that will be logically-ORed with this filter- Returns:
- a new composed filter instance
-
negate
Return a new filter that represents the logical negation of this filter.- Returns:
- the negated filter
-
externalAddresses
Return a filter that will match external (non-private) IP addresses. External addresses are allroutableaddresses that are not:- Returns:
- a filter for external IP addresses
- See Also:
-
internalAddresses
Return a filter that will match internal (private) IP addresses.Internal addresses include loopback addresses (
127.0.0.0/8for IPv4,::1for IPv6), private IPv4 address ranges (10.0.0.0/8,172.16.0.0/12,192.168.0.0/16), and IPv6 Unique Local Addresses (fc00::/7).- Returns:
- a filter for external IP addresses
- See Also:
-
routable
Returns a filter that will match all routable addresses (not all zeros).- Returns:
- a filter for routable IP addresses
-
multicast
Returns a filter that will match all multicast addresses.- Returns:
- a filter for multicast IP addresses
-
specialPurpose
Returns a filter that will match special purpose IP addresses as defined by RFC 6890.- Returns:
- a filter for this network
-
not
Return a filter that is the negation of all the given addresses.- Parameters:
addresses- the addresses to negate in any form supported byof(String...)- Returns:
- a negated filter
- See Also:
-
not
Return a filter that is the negation of all the given matchers.- Parameters:
filters- the filters to negate- Returns:
- a negated filter
- See Also:
-
not
Return a filter that is the negation of all the given filters.- Parameters:
filters- the filters to negate- Returns:
- a negated filter
- See Also:
-
of
Return a filter that matches any of the given IP addresses. Address may be either a full IP address (e.g.192.168.1.1) or an IP address block spcified using CIDR notations (for example192.168.1.0/24). Both IPv4 and IPv6 addresses are supported.- Parameters:
addresses- the IP addresses to match- Returns:
- a filter that matches any of the given addresses
-
of
Return a filter that matches any of the given filters.- Parameters:
filters- the filters to include- Returns:
- a filter that matches any of the filters
-
of
Return a filter that matches any of the given filters.- Parameters:
filters- the filters to include- Returns:
- a filter that matches any of the filters
-
adapt
Adapt the givenPredicateinto anInetAddressFilter.- Parameters:
predicate- the predicate to adapt- Returns:
- a filter that matches using the predicate
-
all
Return a filter that matches all addresses.- Returns:
- a filter that matches all
-
none
Return a filter that matches no addresses.- Returns:
- a filter that matches none
-