Top Description Fields Constructors Methods
io.netty.handler.ipfilter

public Class RuleBasedIpFilter

extends AbstractRemoteAddressFilter<InetSocketAddress>
Class Inheritance
Annotations
@Sharable
Imports
io.netty.channel.Channel, .ChannelHandler.Sharable, .ChannelHandlerContext, io.netty.util.internal.ObjectUtil, java.net.InetSocketAddress, .SocketAddress, java.util.ArrayList, .List

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 Summary

Modifier and TypeField and Description
private final boolean
private final List<IpFilterRule>

Constructor Summary

AccessConstructor and Description
public
RuleBasedIpFilter(IpFilterRule...
An array of IpFilterRule containing all rules.
rules
)

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

public
RuleBasedIpFilter(boolean
If true then accept connection from IP Address if it doesn't match any rule.
acceptIfNotFound
,
IpFilterRule...
An array of IpFilterRule containing all rules.
rules
)

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

Method Summary

Modifier and TypeMethod and Description
protected boolean
accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress)

Implements abstract io.netty.handler.ipfilter.AbstractRemoteAddressFilter.accept.

This method is called immediately after a io.netty.channel.Channel gets registered.
Inherited from io.netty.handler.ipfilter.AbstractRemoteAddressFilter:
channelAcceptedchannelActivechannelRegisteredchannelRejected

Field Detail

acceptIfNotFoundback to summary
private final boolean acceptIfNotFound
rulesback to summary
private final List<IpFilterRule> rules

Constructor Detail

RuleBasedIpFilterback to summary
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:IpFilterRule[]

An array of IpFilterRule containing all rules.

RuleBasedIpFilterback to summary
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:boolean

If true then accept connection from IP Address if it doesn't match any rule.

rules:IpFilterRule[]

An array of IpFilterRule containing all rules.

Method Detail

acceptback to summary
protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) throws Exception

Implements abstract io.netty.handler.ipfilter.AbstractRemoteAddressFilter.accept.

Doc from io.netty.handler.ipfilter.AbstractRemoteAddressFilter.accept.

This method is called immediately after a io.netty.channel.Channel gets registered.

Returns:boolean

Return true if connections from this IP address and port should be accepted. False otherwise.

Annotations
@Override