Class RuleBasedIpFilter

All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler

@Sharable public class RuleBasedIpFilter extends AbstractRemoteAddressFilter<InetSocketAddress>

This class allows one to filter new Channels based on the IpFilterRules passed to its constructor. If no rules are provided, all connections will be accepted.

If you would like to explicitly take action on rejected Channels, you should override AbstractRemoteAddressFilter.channelRejected(ChannelHandlerContext, SocketAddress).

Consider using IpSubnetFilter for better performance while not as general purpose as this filter.

  • Field Details

    • acceptIfNotFound

      private final boolean acceptIfNotFound
    • rules

      private final List<IpFilterRule> rules
  • Constructor Details

    • RuleBasedIpFilter

      public RuleBasedIpFilter(IpFilterRule... rules)

      Create new Instance of RuleBasedIpFilter and filter incoming connections based on their IP address and rules applied.

      acceptIfNotFound is set to true.

      Parameters:
      rules - An array of IpFilterRule containing all rules.
    • RuleBasedIpFilter

      public RuleBasedIpFilter(boolean acceptIfNotFound, IpFilterRule... rules)
      Create new Instance of RuleBasedIpFilter and filter incoming connections based on their IP address and rules applied.
      Parameters:
      acceptIfNotFound - If true then accept connection from IP Address if it doesn't match any rule.
      rules - An array of IpFilterRule containing all rules.
  • Method Details