Class GuardRuleEngine

java.lang.Object
org.frontcache.guard.GuardRuleEngine

public class GuardRuleEngine extends Object
Runs the guard rules for every request, before cache and origin. Rules are evaluated in order, first match wins: 1. built-ins (uri-too-long, bad-request) - always first, they are the structural checks 2. rules from FRONTCACHE_HOME/conf/guard-rules.conf, in file order The rule list is global - there is no per-domain guard-rules.conf (a rule targets a domain with a host~ predicate). Guards run on the request thread for every request, so evaluate() is written to allocate nothing on the common no-match path and to never throw: any unexpected failure is logged and treated as "no match", leaving Frontcache behaving exactly as it does without guards.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    GuardRuleEngine(int maxRequestURILength)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Says, for every challenge rule, whether its provider can be used - at load, once the plugins have started (the engine's first load runs before them, so the engine calls this again after starting them).
    void
    Binds every rule's ext: predicates to the started plugins now - at load once they run, and by the engine right after it starts them (the engine's first load runs before) - so a name no plugin offers, or an argument a plugin refuses, is an ERROR in the log at once, not at the first request that reaches the rule.
    Runs the rules for one request.
     
    boolean
    Whether a plugin may send a visitor to target - the rule a guard rule's own redirect target is held to: a path on this site, or an absolute http(s) URL to an allowed redirect host (the site's public name, or front-cache.guard-rules.allowed-redirect-hosts).
    static List<String>
    What the started plugins say of a rule's ext: predicates - nothing when no plugin has started (the console and the portal parse with none, and a node checks its rules again once its plugins start).
    void
    Re-reads guard-rules.conf.
    validate(String content)
    Dry-parses a candidate guard-rules.conf without touching anything live, for the set-config management action.

    Methods inherited from class Object

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

  • Constructor Details

    • GuardRuleEngine

      public GuardRuleEngine(int maxRequestURILength)
  • Method Details

    • reload

      public void reload()
      Re-reads guard-rules.conf. Built-ins are rebuilt too, so a changed front-cache.max-request-uri-length is picked up by the next FrontCacheEngine reload.
    • getRules

      public List<GuardRule> getRules()
    • validate

      public List<String> validate(String content)
      Dry-parses a candidate guard-rules.conf without touching anything live, for the set-config management action. Nothing here mutates state. No rule swap, no ClientIpResolver.reload(), no hit counters reset, no rate-limit buckets bound to the live registry - the parsed rules are thrown away. The allowlist used is the live one, which is correct: it comes from frontcache.properties, not from the file being edited.
      Returns:
      one message per unusable line, "line N: ...", in file order; empty when the whole file parses
    • pluginPredicateRefusals

      public static List<String> pluginPredicateRefusals(List<GuardPredicate> predicates)
      What the started plugins say of a rule's ext: predicates - nothing when no plugin has started (the console and the portal parse with none, and a node checks its rules again once its plugins start).
    • checkPluginPredicates

      public void checkPluginPredicates()
      Binds every rule's ext: predicates to the started plugins now - at load once they run, and by the engine right after it starts them (the engine's first load runs before) - so a name no plugin offers, or an argument a plugin refuses, is an ERROR in the log at once, not at the first request that reaches the rule.
    • evaluate

      public GuardOutcome evaluate(RequestContext context)
      Runs the rules for one request. Never throws.
      Returns:
      a terminal outcome (reject/redirect) or CONTINUE, carrying any dry-run rules that matched so the caller can log them
    • checkChallengeProviders

      public void checkChallengeProviders()
      Says, for every challenge rule, whether its provider can be used - at load, once the plugins have started (the engine's first load runs before them, so the engine calls this again after starting them). A rule found unavailable here is not reported again by the first request that meets it.
    • isAllowedRedirectTarget

      public boolean isAllowedRedirectTarget(String target)
      Whether a plugin may send a visitor to target - the rule a guard rule's own redirect target is held to: a path on this site, or an absolute http(s) URL to an allowed redirect host (the site's public name, or front-cache.guard-rules.allowed-redirect-hosts).