Repository navigation
Treat blank repeat fields as unset in time-based policies - #53517
Merged
pedroigor merged 1 commit intoOct 6, 2026
Merged
Conversation
The admin console persists empty strings for unused repeat fields of a time policy (month, dayMonth, hour, ...). TimePolicyProvider only checked these values for null before parsing them, so evaluating any permission that referenced such a policy failed with a NumberFormatException. Blank or whitespace-only start values are now ignored, and a blank end value falls back to an exact match on the start value, consistent with the existing nbf/noa handling. Closes keycloak#53456 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Ayush0612005 <ayushkulshreshtha37@gmail.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fix addresses the reported failure and includes representative regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes time-policy evaluation when unused repeat fields contain blank values.
Changes:
- Treats null, empty, and whitespace-only repeat fields as unset.
- Trims configured repeat values before parsing.
- Adds evaluation coverage for blank fields, exact matches, and ranges.
| File | Description |
|---|---|
TimePolicyProvider.java |
Safely handles blank repeat fields. |
PolicyEvaluationTest.java |
Tests blank-field and range behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
pedroigor
approved these changes
Oct 5, 2026
Contributor
|
Thanks, @Ayush0612005. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #53456
A time-based policy saved from the Admin Console with only "Not before" / "Not on or after" set is persisted with empty strings for the unused repeat fields (
month,monthEnd,dayMonth,hour, ...).TimePolicyProvider.isInvalid()only checked those values fornull, soInteger.parseInt("")threw aNumberFormatExceptionand every permission referencing the policy failed with HTTP 500.Changes
TimePolicyProvider.isInvalid()now treats a null, empty or whitespace-only start value (trim().isEmpty(), as suggested by @muscla87) as "not configured", and a blank end value as "no range", so the start must match exactly. This matches the existingnbf/noahandling and covers policies created via the Admin Console, the Admin REST API and realm imports in one place.Tests
Added
PolicyEvaluationTest#testCheckDateAndTimeWithBlankRepeatFields, next to the existingtestCheckDateAndTime, with a fixed context time (kc.time.date_time):nbf/noarange -> PERMIT (previouslyNumberFormatException)monthset,monthEndblank -> exact match -> PERMITmonthset,monthEndwhitespace-only, no match -> DENYhourrange with the other fields blank -> PERMIT / DENY as expectedI also verified the change against the released 26.8.0 artifacts with a small standalone harness: the exact config from the issue throws
NumberFormatException: For input string: ""before the fix and evaluates to PERMIT after it, and policies without blank fields behave the same before and after. I could not run the full Arquillian testsuite locally, so I'm relying on CI forPolicyEvaluationTest.AI disclosure
This change (fix, tests and description) was prepared with the help of an AI coding agent (Claude Code). I have reviewed it, understand it, and will address review feedback myself.
cc @muscla87