Class GuardRuleEngine
java.lang.Object
org.frontcache.guard.GuardRuleEngine
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSays, 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).voidBinds every rule'sext: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(RequestContext context) Runs the rules for one request.getRules()booleanisAllowedRedirectTarget(String target) Whether a plugin may send a visitor totarget- 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, orfront-cache.guard-rules.allowed-redirect-hosts).pluginPredicateRefusals(List<GuardPredicate> predicates) What the started plugins say of a rule'sext: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).voidreload()Re-reads guard-rules.conf.Dry-parses a candidate guard-rules.conf without touching anything live, for theset-configmanagement action.
-
Field Details
-
GUARD_RULES_CONFIG_FILE
- See Also:
-
RULE_URI_TOO_LONG
- See Also:
-
RULE_BAD_REQUEST
- See Also:
-
-
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
-
validate
Dry-parses a candidate guard-rules.conf without touching anything live, for theset-configmanagement action. Nothing here mutates state. No rule swap, noClientIpResolver.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
What the started plugins say of a rule'sext: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'sext: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
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
Whether a plugin may send a visitor totarget- 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, orfront-cache.guard-rules.allowed-redirect-hosts).
-