Skip to content

CAMEL-23452: camel-keycloak - Add Organizations API operations (Keycloak 26+)#23113

Merged
oscerd merged 3 commits into
apache:mainfrom
oscerd:CAMEL-23452
May 11, 2026
Merged

CAMEL-23452: camel-keycloak - Add Organizations API operations (Keycloak 26+)#23113
oscerd merged 3 commits into
apache:mainfrom
oscerd:CAMEL-23452

Conversation

@oscerd
Copy link
Copy Markdown
Contributor

@oscerd oscerd commented May 11, 2026

Motivation

Keycloak 26 introduced an Organizations primitive that allows realms to model multi-tenant scenarios — companies, customer accounts, etc. — with members and identity-provider links.

The Keycloak admin client 26.0.8 already on camel-keycloak's classpath exposes the Organizations API via OrganizationsResource / OrganizationResource / OrganizationMembersResource / OrganizationIdentityProvidersResource, but none of it was surfaced as Camel operations. This change wires the full Organizations CRUD plus member and identity-provider management into the existing camel-keycloak producer.

JIRA: https://issues.apache.org/jira/browse/CAMEL-23452

Changes

New operations on KeycloakOperations

Operation Description
createOrganization Create a new organization (header-based or pojoRequest=true with OrganizationRepresentation).
updateOrganization Update an existing organization (POJO request).
deleteOrganization Delete an organization by ID.
getOrganization Retrieve an organization by ID.
listOrganizations List all organizations in a realm (optional FIRST_RESULT / MAX_RESULTS paging).
searchOrganizations Search organizations by free-text (name / alias / domain), with optional paging.
addOrganizationMember Add an existing realm user as a member of an organization.
removeOrganizationMember Remove a user from an organization.
listOrganizationMembers List members of an organization (optional paging).
linkOrganizationIdentityProvider Link an existing realm IdP to an organization.
unlinkOrganizationIdentityProvider Unlink an IdP from an organization.
listOrganizationIdentityProviders List IdPs linked to an organization.

New headers on KeycloakConstants

ORGANIZATION_ID, ORGANIZATION_NAME, ORGANIZATION_ALIAS, ORGANIZATION_DESCRIPTION, ORGANIZATION_REDIRECT_URL, ORGANIZATION_DOMAIN, ORGANIZATION_SEARCH. Member operations re-use the existing USER_ID, IdP-link operations re-use IDP_ALIAS, and paging operations re-use FIRST_RESULT / MAX_RESULTS.

Implementation

KeycloakProducer follows the existing switch-on-operation pattern. Every new method validates required headers (MISSING_REALM_NAME, MISSING_ORGANIZATION_ID, MISSING_ORGANIZATION_NAME, MISSING_ORGANIZATION_MEMBER_ID, MISSING_ORGANIZATION_IDP_ALIAS) and returns either the JAX-RS Response, a representation POJO, a List<...>, or a fixed success string — matching the conventions used by existing operations.

Tests

  • KeycloakProducerTest adds Mockito-based unit tests for all 12 operations plus missing-name / missing-id validation.
  • KeycloakTestInfraIT exercises the full lifecycle (create → list → get → search → add-member → list-members → remove-member → link-IdP → list-IdPs → unlink-IdP → cleanup) against the testcontainers-based Keycloak from camel-test-infra-keycloak, with a dedicated cleanup step ordered before the existing IdP/realm teardown.
  • A pre-step at @Order(49) enables the Organizations feature on the test realm via updateRealm with organizationsEnabled=true. Organizations is a per-realm opt-in in Keycloak 26, so without this the /organizations endpoint returns HTTP 404 and the lifecycle tests cannot run.

Documentation

keycloak-component.adoc is updated:

  • New Organization Management entry in the Supported Operations summary.
  • New === Organization Operations section with end-to-end Java examples covering all 12 operations.

Regenerated artifacts

A follow-up commit adds the regenerated camel-catalog and camel-endpointdsl outputs for the new operations and headers (CI was rightly flagging these as missing).

How to test

cd components/camel-keycloak
mvn clean install                          # unit tests
mvn verify -Pit                            # integration tests (testcontainers)

All 91 unit tests pass locally (28 of them in KeycloakProducerTest, including the 11 new organization tests).

Notes

  • No new dependencies. The Organizations API is already provided by keycloak-admin-client 26.0.8 currently on the classpath.
  • No public API signatures are changed; only additions to the operations enum and constants.

Claude Code on behalf of Andrea Cosentino

…oak 26+)

Wires the Keycloak 26 Organizations primitive (OrganizationsResource /
OrganizationResource) into the existing camel-keycloak component:

* New KeycloakOperations enum values: createOrganization, updateOrganization,
  deleteOrganization, getOrganization, listOrganizations, searchOrganizations,
  addOrganizationMember, removeOrganizationMember, listOrganizationMembers,
  linkOrganizationIdentityProvider, unlinkOrganizationIdentityProvider,
  listOrganizationIdentityProviders.
* New KeycloakConstants headers: ORGANIZATION_ID, ORGANIZATION_NAME,
  ORGANIZATION_ALIAS, ORGANIZATION_DESCRIPTION, ORGANIZATION_REDIRECT_URL,
  ORGANIZATION_DOMAIN and ORGANIZATION_SEARCH.
* Producer logic in KeycloakProducer follows the existing
  switch-on-operation pattern, with header-driven and pojoRequest variants
  for create/update, paging support for list/search/listMembers, and
  consistent missing-input validation messages.

Unit tests cover happy-path mocking for all 12 operations plus
missing-name / missing-id validation. The testcontainers-based
KeycloakTestInfraIT exercises the full create / list / get / search /
member-add / member-list / member-remove /
link-idp / list-idps / unlink-idp / delete lifecycle against a real
Keycloak server, and adds a dedicated cleanup step ordered before the
existing IdP/realm cleanup. keycloak-component.adoc is updated with the
new operations in the Supported Operations summary and a new
"Organization Operations" section with end-to-end Java examples.

Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@oscerd oscerd requested review from gzurowski and orpiske May 11, 2026 07:53
@github-actions
Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

Add the regenerated camel-catalog and camel-endpointdsl artifacts for
the new Organizations operations and headers introduced in the previous
commit. CI flags these as uncommitted changes when they are not part of
the PR.

Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
The Keycloak 26 Organizations API is a per-realm feature: even when the
server has the feature compiled in, every realm must opt in via
`organizationsEnabled=true` on its `RealmRepresentation`, otherwise the
`/admin/realms/{realm}/organizations` endpoint returns HTTP 404.

`KeycloakTestInfraIT.testCreateRealm` creates the test realm with
defaults (no organizations), so the 12 organization tests added in
CAMEL-23452 hit a 404 on `listOrganizations` / `searchOrganizations`
and produce a null `Location` header on `createOrganization`, which
cascades into `testOrgId should be set` failures across the remaining
member / IdP-link tests.

Fix:
* Add a `direct:updateRealm` route configured with `pojoRequest=true`.
* Add `testEnableOrganizationsOnRealm` ordered at @order(49), i.e. after
  realm/user/role/group/client/IdP setup and immediately before the
  organization tests. It sends a `RealmRepresentation` with
  `organizationsEnabled=true` through the existing `updateRealm`
  operation.

With this opt-in step, the full organization test lifecycle succeeds
against the testcontainers-based Keycloak 26 image used by
`camel-test-infra-keycloak`.

Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • catalog/camel-catalog
  • components/camel-keycloak
  • dsl/camel-endpointdsl
All tested modules (10 modules)
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Endpoint DSL
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Keycloak
  • Camel :: Launcher :: Container
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

@oscerd oscerd merged commit 873ea8e into apache:main May 11, 2026
7 checks passed
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.

3 participants