- java.lang.Object
-
- io.netty5.handler.ipfilter.AbstractRemoteAddressFilter<InetSocketAddress>
-
- io.netty5.handler.ipfilter.RuleBasedIpFilter
-
- All Implemented Interfaces:
ChannelHandler
public class RuleBasedIpFilter extends AbstractRemoteAddressFilter<InetSocketAddress>
This class allows one to filter new
Channel
s based on theIpFilterRule
s passed to its constructor. If no rules are provided, all connections will be accepted.If you would like to explicitly take action on rejected
Channel
s, you should overrideAbstractRemoteAddressFilter.channelRejected(ChannelHandlerContext, SocketAddress)
.Consider using
IpSubnetFilter
for better performance while not as general purpose as this filter.
-
-
Constructor Summary
Constructors Constructor Description RuleBasedIpFilter(boolean acceptIfNotFound, IpFilterRule... rules)
Create new Instance ofRuleBasedIpFilter
and filter incoming connections based on their IP address andrules
applied.RuleBasedIpFilter(IpFilterRule... rules)
Create new Instance ofRuleBasedIpFilter
and filter incoming connections based on their IP address andrules
applied.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress)
This method is called immediately after aChannel
gets registered.boolean
isSharable()
Returnstrue
if this handler is sharable and thus can be added to more than oneChannelPipeline
.-
Methods inherited from class io.netty5.handler.ipfilter.AbstractRemoteAddressFilter
channelAccepted, channelActive, channelRegistered, channelRejected
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Constructor Detail
-
RuleBasedIpFilter
public RuleBasedIpFilter(IpFilterRule... rules)
Create new Instance of
RuleBasedIpFilter
and filter incoming connections based on their IP address andrules
applied.acceptIfNotFound
is set totrue
.- Parameters:
rules
- An array ofIpFilterRule
containing all rules.
-
RuleBasedIpFilter
public RuleBasedIpFilter(boolean acceptIfNotFound, IpFilterRule... rules)
Create new Instance ofRuleBasedIpFilter
and filter incoming connections based on their IP address andrules
applied.- Parameters:
acceptIfNotFound
- Iftrue
then accept connection from IP Address if it doesn't match any rule.rules
- An array ofIpFilterRule
containing all rules.
-
-
Method Detail
-
isSharable
public boolean isSharable()
Description copied from interface:ChannelHandler
Returnstrue
if this handler is sharable and thus can be added to more than oneChannelPipeline
. By default, this method returnsfalse
. If this method returnsfalse
, you have to create a new handler instance every time you add it to a pipeline because it has unshared state such as member variables.
-
accept
protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) throws Exception
Description copied from class:AbstractRemoteAddressFilter
This method is called immediately after aChannel
gets registered.- Specified by:
accept
in classAbstractRemoteAddressFilter<InetSocketAddress>
- Returns:
- Return true if connections from this IP address and port should be accepted. False otherwise.
- Throws:
Exception
-
-