Class 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:*")
    • 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

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

      • PatternRule

        public PatternRule​(boolean allow,
                           java.lang.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 java.lang.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​(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.
        Specified by:
        contains in interface IpSet
        Returns:
        returns true if the given IP address is contained in the current IpSet.
      • 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 interface java.lang.Comparable<java.lang.Object>