JWTFilter enforces the presence of a JWT on incoming requests, validates it, and exposes user details for the lifetime of the request.
- Requires the
jwtheader on requests (except excluded paths) - Validates and parses the token via
JWTService - Stores
userNameandscopein a request-scopedAuthDetailsbean
Defined in src/main/resources/application.yaml:
jwt:
secretKey: "it-must-be-a-string-secret-at-least-256-bits-long"
filter:
enabled: falsejwt.secretKey: Base64 key suitable for HS256 (≥ 256 bits)jwt.filter.enabled: When false, the filter is skipped entirely. When true, it runs for all paths except those excluded.
- Env var:
JWT_FILTER_ENABLED=true - Tests:
@SpringBootTest(properties = "jwt.filter.enabled=true") - Profile override:
application-<profile>.yaml
Currently excluded: /health. Extend in JWTFilter.shouldNotFilter(...) if needed.
- Missing header: 401 UNAUTHORIZED ("No jwt token passed")
- Invalid token: 400 BAD_REQUEST with details
uk.gov.hmcts.cp.filters.jwt.JWTFilteruk.gov.hmcts.cp.filters.jwt.JWTServiceuk.gov.hmcts.cp.filters.jwt.AuthDetailsuk.gov.hmcts.cp.config.JWTConfig