Class 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:*")
    • Constructor Detail

      • 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 Detail

      • 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.