Class RuleBasedIpFilter
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.ipfilter.AbstractRemoteAddressFilter<InetSocketAddress>
io.netty.handler.ipfilter.RuleBasedIpFilter
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionRuleBasedIpFilter(boolean acceptIfNotFound, IpFilterRule... rules) Create new Instance ofRuleBasedIpFilterand filter incoming connections based on their IP address andrulesapplied.RuleBasedIpFilter(IpFilterRule... rules) Create new Instance ofRuleBasedIpFilterand filter incoming connections based on their IP address andrulesapplied. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanaccept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) This method is called immediately after aChannelgets registered.Methods inherited from class AbstractRemoteAddressFilter
channelAccepted, channelActive, channelRegistered, channelRejectedMethods inherited from class ChannelInboundHandlerAdapter
channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
handlerAdded, handlerRemoved
-
Constructor Details
-
RuleBasedIpFilter
Create new Instance of
RuleBasedIpFilterand filter incoming connections based on their IP address andrulesapplied.acceptIfNotFoundis set totrue.- Parameters:
rules- An array ofIpFilterRulecontaining all rules.
-
RuleBasedIpFilter
Create new Instance ofRuleBasedIpFilterand filter incoming connections based on their IP address andrulesapplied.- Parameters:
acceptIfNotFound- Iftruethen accept connection from IP Address if it doesn't match any rule.rules- An array ofIpFilterRulecontaining all rules.
-
-
Method Details
-
accept
protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) throws Exception Description copied from class:AbstractRemoteAddressFilterThis method is called immediately after aChannelgets registered.- Specified by:
acceptin classAbstractRemoteAddressFilter<InetSocketAddress>- Returns:
- Return true if connections from this IP address and port should be accepted. False otherwise.
- Throws:
Exception
-