Package io.inversion

Class Rule<R extends Rule>

java.lang.Object
io.inversion.Rule<R>
All Implemented Interfaces:
Comparable<R>
Direct Known Subclasses:
AclRule, Action, Api, Collection, Endpoint, Engine

public abstract class Rule<R extends Rule> extends Object implements Comparable<R>
Matches against an HTTP method and URL path to determine if the object should be included when processing the associated Request.

Matching relies heavily on variablized Path matching via Path.matches(String)

  • Field Details

    • log

      protected final transient org.slf4j.Logger log
    • includeMatchers

      protected final List<Rule.RuleMatcher> includeMatchers
      Method/path combinations that would cause this Rule to be included in the relevant processing.
    • excludeMatchers

      protected final List<Rule.RuleMatcher> excludeMatchers
      Method/path combinations that would cause this Rule to be excluded from the relevant processing.
    • configMap

      protected final transient JSNode configMap
      JSNode is used because it implements a case insensitive map without modifying the keys
    • name

      protected String name
      The name used for configuration and debug purposes.
    • order

      protected int order
      Rules are always processed in sequence sorted by ascending order.
    • configStr

      protected String configStr
    • includeOn

      protected String includeOn
    • excludeOn

      protected String excludeOn
  • Constructor Details

    • Rule

      public Rule()
  • Method Details

    • checkLazyConfig

      public void checkLazyConfig()
    • doLazyConfig

      protected void doLazyConfig()
    • getDefaultIncludeMatch

      protected Rule.RuleMatcher getDefaultIncludeMatch()
      Designed to allow subclasses to provide a default match behavior of no configuration was provided by the developer.
      Returns:
      the default include match "*","*"
    • matches

      public boolean matches(String method, String path)
      Check if the http method and path match this Rule.
      Parameters:
      method - the HTTP method to match
      path - the concrete path to match
      Returns:
      true if the http method and path are included and not excluded
    • matches

      public boolean matches(String method, Path path)
      Check if the http method and path match this Rule.
      Parameters:
      method - the HTTP method to match
      path - the concrete path to match
      Returns:
      true if the http method and path are included and not excluded
    • match

      protected Path match(String method, Path path)
      Find the first ordered Path that satisfies this method/path match.
      Parameters:
      method - the HTTP method to match
      path - the concrete path to match
      Returns:
      the first includeMatchers path to match when method also matches, null if no matches or excluded
    • getAllIncludePaths

      public List<Path> getAllIncludePaths()
    • getAllExcludePaths

      public List<Path> getAllExcludePaths()
    • getIncludeMatchers

      public List<Rule.RuleMatcher> getIncludeMatchers()
    • withIncludeOn

      public R withIncludeOn(Rule.RuleMatcher matcher)
    • withIncludeOn

      public R withIncludeOn(String methods, String paths)
      Select this Rule when any method and path match.
      Parameters:
      methods - or more comma separated http method names, can be null to match on any
      paths - each path can be one or more comma separated variableized Paths
      Returns:
      this
    • withIncludeOn

      public R withIncludeOn(String methodsAndOrPaths)
    • withExcludeOn

      public R withExcludeOn(String methods, String paths)
      Don't select this Rule when any method and path match.
      Parameters:
      methods - or more comma separated http method names, can be null to match on any
      paths - each path can be one or more comma separated variableized Paths
      Returns:
      this
    • withExcludeOn

      public R withExcludeOn(Rule.RuleMatcher matcher)
      Don't select this Rule when RuleMatcher matches
      Parameters:
      matcher - the method/path combo to exclude
      Returns:
      this
    • withExcludeOn

      public R withExcludeOn(String methodsAndOrPaths)
    • getExcludeMatchers

      public List<Rule.RuleMatcher> getExcludeMatchers()
    • getName

      public String getName()
    • withName

      public R withName(String name)
    • getOrder

      public int getOrder()
    • withOrder

      public R withOrder(int order)
    • getConfigKeys

      public Set<String> getConfigKeys()
    • getConfig

      public String getConfig(String key)
    • getConfig

      public String getConfig(String key, String defaultValue)
    • withConfig

      public R withConfig(String queryString)
    • compareTo

      public int compareTo(Rule a)
      Specified by:
      compareTo in interface Comparable<R extends Rule>
    • toString

      public String toString()
      Overrides:
      toString in class Object