Class PatternRule

java.lang.Object
org.jboss.netty.handler.ipfilter.PatternRule
All Implemented Interfaces:
Comparable<Object>, IpFilterRule, IpSet

public class PatternRule extends Object implements IpFilterRule, Comparable<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 Details

    • logger

      private static final InternalLogger logger
    • ipPattern

      private Pattern ipPattern
    • namePattern

      private Pattern namePattern
    • isAllowRule

      private boolean isAllowRule
    • localhost

      private boolean localhost
    • pattern

      private final String pattern
  • Constructor Details

    • PatternRule

      public PatternRule(boolean allow, String pattern)
      Instantiates a new pattern rule.
      Parameters:
      allow - indicates if this is an allow or block rule
      pattern - the filter pattern
  • Method Details

    • getPattern

      public String getPattern()
      returns the pattern.
      Returns:
      the pattern
    • isAllowRule

      public boolean isAllowRule()
      Specified by:
      isAllowRule in interface IpFilterRule
      Returns:
      True if this Rule is an ALLOW rule
    • isDenyRule

      public boolean isDenyRule()
      Specified by:
      isDenyRule in interface IpFilterRule
      Returns:
      True if this Rule is a DENY rule
    • contains

      public boolean contains(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.
      Specified by:
      contains in interface IpSet
      Returns:
      returns true if the given IP address is contained in the current IpSet.
    • parse

      private void parse(String pattern)
    • addRule

      private static String addRule(String pattern, String rule)
    • isLocalhost

      private static boolean isLocalhost(InetAddress address)
    • compareTo

      public int compareTo(Object o)
      Specified by:
      compareTo in interface Comparable<Object>