Skip to content

Fix removal of custom required actions via admin user API#48485

Open
ozimakov wants to merge 4 commits into
keycloak:mainfrom
ozimakov:fix/48144-remove-custom-required-actions
Open

Fix removal of custom required actions via admin user API#48485
ozimakov wants to merge 4 commits into
keycloak:mainfrom
ozimakov:fix/48144-remove-custom-required-actions

Conversation

@ozimakov

Copy link
Copy Markdown

Summary

When updating a user via PUT /admin/realms/{realm}/users/{id}, custom required actions (registered via the RequiredActionProvider SPI) could not be removed. The old code iterated only over registered provider factory IDs to decide which actions to remove — any action not in that factory set was silently retained.

The fix replaces the single-pass "diff against factory IDs" approach with a clear-then-set approach: on update, all existing required actions are removed first, then only the valid requested ones are added back. This correctly handles custom, built-in, and orphaned actions alike.

Two new integration tests verify:

  • Removing a custom required action by sending an empty list
  • Selectively removing a custom action while keeping a built-in one

Closes #48144


Note: Claude Code (AI agent) was used to help navigate the codebase, research the issue, and draft the fix and tests. All changes were reviewed and are fully understood by the author.

ozimakov and others added 2 commits April 26, 2026 18:41
When updating a user via PUT /admin/realms/{realm}/users/{id}, custom
required actions (registered via RequiredActionProvider SPI) could not
be removed. The old code only iterated over registered provider factory
IDs to decide which actions to remove, so any action not in that set
was silently retained.

Replace the single-pass "diff against factory IDs" approach with a
clear-then-set approach: on update, remove all existing required
actions first, then add back only the valid requested ones. This
correctly handles custom, built-in, and orphaned actions alike.

Closes keycloak#48144

Signed-off-by: Oleg Zimakov <oleg@zimakov.net>
@ozimakov
ozimakov marked this pull request as ready for review April 27, 2026 01:47
@ozimakov
ozimakov requested a review from a team as a code owner April 27, 2026 01:47
@sebastianandress

Copy link
Copy Markdown

Thank you very much, looks to me as it should fix the issue #48144 which btw also occurs by using the admin interface

@ozimakov

Copy link
Copy Markdown
Author

@stianst May I get a review for this one? Thx.

Signed-off-by: Oleg Zimakov <oleg.zimakov@gmail.com>
Copilot AI review requested due to automatic review settings July 19, 2026 05:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes required-action removal during Admin API user updates.

Changes:

  • Replaces factory-based removal with clear-and-reapply logic.
  • Adds integration tests for custom required-action removal.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
services/.../UserResource.java Updates required-action synchronization.
tests/.../UserRequiredActionsTest.java Adds custom-action removal tests.

… API

Required-action values stored on a user are realm aliases, which are not
necessarily equal to the provider factory id (they can diverge once an
action's alias is renamed). The re-add filter now resolves the realm
required-action model by alias first, then validates that its provider id
maps to a registered factory. This keeps custom actions whose alias differs
from the provider id from being silently dropped on a user update.

Update the integration tests to register the dummy action and then rename
its alias so it no longer matches the provider factory id. The tests now
exercise the alias/provider-id distinction and reproduce the reported
failure, and a new test asserts such an aliased action is retained across an
update.

Signed-off-by: Oleg Zimakov <oleg.zimakov@gmail.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLP6kVvr88Q87AtHhS7b9w
Copilot AI review requested due to automatic review settings July 19, 2026 07:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom Required Actions cannot be removed via PUT /admin/realms/{realm}/users/{id}

4 participants