Package org.jboss.netty.handler.ipfilter
Class PatternRule
- java.lang.Object
-
- org.jboss.netty.handler.ipfilter.PatternRule
-
- All Implemented Interfaces:
java.lang.Comparable<java.lang.Object>
,IpFilterRule
,IpSet
public class PatternRule extends java.lang.Object implements IpFilterRule, java.lang.Comparable<java.lang.Object>
The Class PatternRule represents an IP filter rule using string patterns.
Rule Syntax:
Rule ::= [n|i]:address n stands for computer name, i for ip address address ::= <regex> | localhost regex is a regular expression with '*' as multi character and '?' as single character wild card
Example: allow localhost:
new PatternRule(true, "n:localhost")
Example: allow local lan:
new PatternRule(true, "i:192.168.0.*")
Example: block all
new PatternRule(false, "n:*")
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.regex.Pattern
ipPattern
private boolean
isAllowRule
private boolean
localhost
private static InternalLogger
logger
private java.util.regex.Pattern
namePattern
private java.lang.String
pattern
-
Constructor Summary
Constructors Constructor Description PatternRule(boolean allow, java.lang.String pattern)
Instantiates a new pattern rule.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
addRule(java.lang.String pattern, java.lang.String rule)
int
compareTo(java.lang.Object o)
boolean
contains(java.net.InetAddress inetAddress)
Compares the given InetAddress against the IpSet and returns true if the InetAddress is contained in this Rule and false if not.java.lang.String
getPattern()
returns the pattern.boolean
isAllowRule()
boolean
isDenyRule()
private static boolean
isLocalhost(java.net.InetAddress address)
private void
parse(java.lang.String pattern)
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
ipPattern
private java.util.regex.Pattern ipPattern
-
namePattern
private java.util.regex.Pattern namePattern
-
isAllowRule
private boolean isAllowRule
-
localhost
private boolean localhost
-
pattern
private final java.lang.String pattern
-
-
Method Detail
-
getPattern
public java.lang.String getPattern()
returns the pattern.- Returns:
- the pattern
-
isAllowRule
public boolean isAllowRule()
- Specified by:
isAllowRule
in interfaceIpFilterRule
- Returns:
- True if this Rule is an ALLOW rule
-
isDenyRule
public boolean isDenyRule()
- Specified by:
isDenyRule
in interfaceIpFilterRule
- Returns:
- True if this Rule is a DENY rule
-
contains
public boolean contains(java.net.InetAddress inetAddress)
Description copied from interface:IpSet
Compares the given InetAddress against the IpSet and returns true if the InetAddress is contained in this Rule and false if not.
-
parse
private void parse(java.lang.String pattern)
-
addRule
private static java.lang.String addRule(java.lang.String pattern, java.lang.String rule)
-
isLocalhost
private static boolean isLocalhost(java.net.InetAddress address)
-
compareTo
public int compareTo(java.lang.Object o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<java.lang.Object>
-
-