Keycloak conditional authenticator that evaluates incoming HTTP headers against a Java regex.
- regex check for incoming HTTP headers in authentication flows
- optional boolean negation of the final condition
- supports multi-value headers (condition is true if any value matches)
- HTTP header name — header name to inspect
- Header regex — Java regex. The full header value must match because the authenticator uses
Matcher.matches(). Invalid regex fails closed and returnsfalseregardless of Negate result. - Negate result — invert match result
- Header name:
X-Env - Regex:
prod|stage - Negate result:
false
Condition returns true when the incoming X-Env header equals prod or stage.
- Header name:
X-Forwarded-Host - Regex:
^admin\\.example\\.com$ - Negate result:
true
Condition returns true when the incoming host does not match admin.example.com.
mvn clean packageCopy the resulting JAR to the Keycloak providers directory:
cp target/http-header-condition-plugin-*.jar /opt/keycloak/providers/Then rebuild or restart Keycloak depending on your distribution, for example:
/opt/keycloak/bin/kc.sh build
/opt/keycloak/bin/kc.sh start- Open Authentication in the Keycloak Admin Console.
- Create or edit a flow/subflow with requirement Conditional.
- Add execution Condition - HTTP Header Regex to that conditional subflow.
- Keep the execution requirement as Required unless you want to disable the condition.
- Configure HTTP header name and other settings.