8000 Support partial import of organizations by Hakaou · Pull Request #55135 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Support partial import of organizations - #55135

Open
Hakaou wants to merge 1 commit into
keycloak:mainfrom
Hakaou:partial-import-organizations
Open

Hakaou wants to merge 1 commit into
keycloak:mainfrom
Hakaou:partial-import-organizations

Conversation

@Hakaou
@Hakaou Hakaou commented Nov 12, 2026 •
Copy link
Copy Markdown
Contributor

Follow-up to #54274. This PR supports skip and fail only, as discussed with @vramik in #54343.

Decisions:

  • Overwrite is refused in prepare(), before any handler removes a resource. Removing an organization deletes the accounts of its managed members.
  • An existing organization is found by its alias. When the file gives no alias the name in the file is used, as OrganizationProvider.create() does.
  • A new alias with the name of an existing organization fails with the 409 of the provider, also under the skip policy.
  • Organizations and their groups get new ids, as clients and identity providers do. With the ids of the file kept, the import of a file exported from another realm of the same server fails.
  • The handler is registered only when Organizations.isEnabled(session) is true. With the organization feature disabled, or with organizations disabled for the realm, the organizations of the file are ignored. The Admin Console dialog offers them under the same condition.
  • The code that creates an organization from its representation moved from DefaultExportImportManager to RepresentationToModel.importOrganization(), next to importGroup(). The full import calls it and then adds the members. A role of a missing client in an organization group now throws a ModelValidationException instead of a RuntimeException. The partial import and the creation of a realm then return a 400 that names the client instead of a 500.
  • A link to an identity provider that is missing from the realm fails the import with a 400 that names the alias. An invalid redirect URL returns a 400 too. So does an invalid membership type on an identity provider link. Without this the import fails with a 500 in these cases.
  • A request that posts a whole exported realm used to ignore the organizations of the file. With organizations enabled for the realm, it now fails under FAIL and OVERWRITE when one of them already exists. The upgrading guide has an entry.

Not in this PR:

An AI agent wrote the code and the tests under my direction.

Closes #54343

@Hakaou
Hakaou marked this pull request as ready for review November 13, 2026 08:13
@Hakaou
Hakaou requested review from a team as code owners November 13, 2026 08:13
Copilot AI balanced review requested due to automatic review settings November 13, 2026 08:13
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.

🟡 Changes recommended

An invalid membershipType escapes the partial-import error handler and produces HTTP 500 instead of the expected 400 response.

1 open issue
What changed in this PR

Adds organization definitions to Keycloak’s partial import, completing the partial-export support from #54274. Organizations can be copied without members, while existing organizations are protected from destructive overwrites.

Changes:

  • Adds feature-gated organization imports with alias-based conflict detection and fresh organization/group IDs.
  • Adds organization selection and result labels to the Admin Console.
  • Adds integration and UI tests, plus documentation of import policies and upgrade behavior.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​admin/​partialimport/​PartialImportOrganizationTest.java Tests imports, conflict policies, validation, and member preservation.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​admin/​partialimport/​PartialImportOrganizationDisabledTest.java Tests imports with the organization feature disabled.
services/​src/​main/​java/​org/​keycloak/​partialimport/​PartialImportManager.java Registers the organization handler when enabled.
services/​src/​main/​java/​org/​keycloak/​partialimport/​OrganizationsPartialImport.java Implements organization partial-import handling.
server-spi-private/​src/​main/​java/​org/​keycloak/​partialimport/​ResourceType.java Adds organization result and event metadata.
server-spi-private/​src/​main/​java/​org/​keycloak/​models/​utils/​RepresentationToModel.java Hosts shared organization import logic.
model/​storage-private/​src/​main/​java/​org/​keycloak/​storage/​datastore/​DefaultExportImportManager.java Delegates definition imports while retaining member handling.
js/​libs/​keycloak-admin-client/​src/​defs/​realmRepresentation.ts Adds organization definitions to the realm type.
js/​apps/​admin-ui/​test/​utils/​files/​organization-only.json Provides an organization import fixture.
js/​apps/​admin-ui/​test/​realm-settings/​import.ts Adds an organization-selection helper.
js/​apps/​admin-ui/​test/​realm-settings/​import.spec.ts Tests organization import through the console.
js/​apps/​admin-ui/​src/​realm-settings/​PartialImport.tsx Adds gated organization selection and result labels.
docs/​guides/​server/​importExport.adoc Documents organization imports and overwrite restrictions.
docs/​documentation/​upgrading/​topics/​changes/​changes-27_0_0.adoc Explains changed behavior for exported-realm imports.
core/​src/​main/​java/​org/​keycloak/​representations/​idm/​PartialImportRepresentation.java Adds organizations to the import request model.

Review effort: Balanced

@Hakaou
Hakaou force-pushed the partial-import-organizations branch from 94f8ad8 to f6208a4 Compare November 13, 2026 09:00
Copilot AI balanced review requested due to automatic review settings November 13, 2026 09:00
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.

🟢 Approval recommended

No active review issues are reported for the organization partial-import changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@Hakaou
Hakaou commented Nov 13, 2026
Copy link
Copy Markdown
Contributor Author

Migration Tests (24.0.4, mssql) failed before any test started. Maven could not download io.quarkus.platform:quarkus-bom:pom:3.40.1.2 from Maven Central. The five other migration jobs passed. Could someone re-run it?

@vramik
vramik requested a review from pedroigor November 13, 2026 11:03
@vramik
vramik commented Nov 13, 2026
Copy link
Copy Markdown
Contributor

@Hakaou thank you! Could you rebase please? The branch caught a conflict.

@Hakaou
Hakaou force-pushed the partial-import-organizations branch from f6208a4 to 8599211 Compare November 13, 2026 11:50
Copilot AI balanced review requested due to automatic review settings November 13, 2026 11:50
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.

🟢 Approval recommended

No active review issues are reported for the organization partial-import changes.

No open issues 🎉

Review effort: Balanced

@Hakaou
Hakaou commented Nov 13, 2026
Copy link
Copy Markdown
Contributor Author

The status check fails only on SAST Check. It reports required.method.not.called at lines 1213 and 1265 of SamlService.java and at line 71 of SamlEcpProfileService.java. This PR does not change these files. The SAST Check run for #54527 reports the same errors at the same lines. I can rebase again once a fix is available.

@Hakaou
Hakaou force-pushed the partial-import-organizations branch from 8599211 to f82e129 Compare November 13, 2026 18:19
Copilot AI balanced review requested due to automatic review settings November 13, 2026 18:19
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.

🟡 Changes recommended

The TypeScript organization representation lacks groups, preventing typed callers from supplying or accessing organization group data that the server now supports.

1 open issue

Review effort: Balanced

@Hakaou
Hakaou force-pushed the partial-import-organizations branch from f82e129 to 0fbf263 Compare November 13, 2026 18:48
Copilot AI balanced review requested due to automatic review settings November 13, 2026 18:48
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.

🟡 Changes recommended

A missing client referenced by exported organization group role mappings triggers HTTP 500 rather than an actionable 400 because the exception bypasses partial-import validation handling.

1 open issue
1 resolved since last review

Review effort: Balanced

@Hakaou
Hakaou force-pushed the partial-import-organizations branch from 0fbf263 to f8b005f Compare November 13, 2026 19:35
Copilot AI balanced review requested due to automatic review settings November 13, 2026 19:35
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.

🟢 Approval recommended

No active review issues block the organization partial-import change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@Hakaou
Hakaou force-pushed the partial-import-organizations branch from f8b005f to a9caba2 Compare November 20, 2026 08:53
Copilot AI balanced review requested due to automatic review settings November 20, 2026 08: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.

🟢 Approval recommended

The organization partial-import changes have no active review issues.

No open issues 🎉

Review effort: Balanced

@Hakaou
Hakaou commented Nov 23, 2026
Copy link
Copy Markdown
Contributor Author

Hi @pedroigor, could you review this PR when you have time? All checks pass on a9caba2.

@pedroigor
Copy link
Copy Markdown
Contributor

@Hakaou, we are good after @vramik review. Thanks for it. Can you please rebase it?

pedroigor
pedroigor previously approved these changes Nov 25, 2026
@pedroigor
pedroigor enabled auto-merge (squash) November 25, 2026 18:52
The partial import reads the organizations of the file when
organizations are enabled for the realm. It creates them after the
identity providers, with new ids and without their members. An existing
organization is found by its alias. It can be skipped or can fail the
import. Overwrite is refused during preparation, because removing an
organization deletes the accounts of its managed members.

RepresentationToModel now holds the creation of an organization from its
representation. The full import and the partial import share it. A role
of a missing client in an organization group is now a validation error.

The Admin Console partial import dialog offers the organizations of the
file under the same condition. The admin client representation of an
organization now has its groups.

Closes keycloak#54343

Signed-off-by: Hakaou <hakaou@fr.scc.com>
auto-merge was automatically disabled November 25, 2026 19:02

Head branch was pushed to by a user without write access

@Hakaou
Hakaou force-pushed the partial-import-organizations branch from a9caba2 to 6877b0c Compare November 25, 2026 19:02
Copilot AI balanced review requested due to automatic review settings November 25, 2026 19:02
@Hakaou
Hakaou commented Nov 25, 2026
Copy link
Copy Markdown
Contributor Author

Thanks @pedroigor. Rebased on main, no other change.

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.

🟢 Approval recommended

No unresolved review issues are recorded for the organization partial-import changes.

No open issues 🎉

Review effort: Balanced

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.

Support partial import of organizations

4 participants

0