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.PatternipPatternprivate booleanisAllowRuleprivate booleanlocalhostprivate static InternalLoggerloggerprivate java.util.regex.PatternnamePatternprivate java.lang.Stringpattern
-
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.StringaddRule(java.lang.String pattern, java.lang.String rule)intcompareTo(java.lang.Object o)booleancontains(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.StringgetPattern()returns the pattern.booleanisAllowRule()booleanisDenyRule()private static booleanisLocalhost(java.net.InetAddress address)private voidparse(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:
isAllowRulein interfaceIpFilterRule- Returns:
- True if this Rule is an ALLOW rule
-
isDenyRule
public boolean isDenyRule()
- Specified by:
isDenyRulein interfaceIpFilterRule- Returns:
- True if this Rule is a DENY rule
-
contains
public boolean contains(java.net.InetAddress inetAddress)
Description copied from interface:IpSetCompares 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:
compareToin interfacejava.lang.Comparable<java.lang.Object>
-
-