Skip to content

Flush auto-created roles during user import to avoid duplicate role inserts in batch mode - #51210

Open
theohh0 wants to merge 2 commits into
keycloak:mainfrom
theohh0:testfix
Open

Flush auto-created roles during user import to avoid duplicate role inserts in batch mode#51210
theohh0 wants to merge 2 commits into
keycloak:mainfrom
theohh0:testfix

Conversation

@theohh0

@theohh0 theohh0 commented Jul 27, 2026

Copy link
Copy Markdown

Implements #50056 to fix #49731 and fixes failing checks (as requested by @sguilhen: #50056 (comment)) by:

  • Moving RealmImportSharedUndefinedClientRoleTest from deprecated testsuite to tests/base/src/test/java/org/keycloak/tests/exportimport/
  • Updating imports and test assertions as necessary
  • Running Spotless to fix import ordering

Note: I used IBM bob to fix some of the import requirements

wilmerdooley and others added 2 commits June 26, 2026 20:18
Signed-off-by: wilmerdooley <wilmerdooley1@gmail.com>
…x spotless

Signed-off-by: theohh0 <theo.hinton-hallows@ibm.com>
Copilot AI review requested due to automatic review settings July 27, 2026 21:06
@theohh0
theohh0 requested a review from a team as a code owner July 27, 2026 21:06

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

Prevents duplicate role inserts during batched realm user imports.

Changes:

  • Flushes auto-created roles during batch imports.
  • Reuses existing roles during role-definition import.
  • Adds unit and integration regression coverage.

Reviewed changes

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

File Description
RepresentationToModel.java Adds role reuse and batch-aware flushing.
DefaultExportImportManager.java Passes the session to role mapping creation.
RepresentationToModelTest.java Tests reuse of existing client roles.
RealmImportSharedUndefinedClientRoleTest.java Tests shared undefined client-role imports.

@sguilhen sguilhen 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.

Looks ok to me - the license headers are not necessary but that a nit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating a new realm from json using kcadm gives a PK violation on KEYCLOAK_ROLE despite it only being defined once in the JSON.

4 participants