Repository navigation
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Adds support for attaching realm/client roles to organization invitations so roles are granted atomically when an invite is accepted, removing the need for post-acceptance event listeners.
Changes:
- Extend invite endpoints/admin clients/representations to accept and expose invitation roles (by role id).
- Persist invitation role ids via new
ORG_INVITATION_ROLEtable and JPA mapping. - Grant recorded roles during invite acceptance flows (action token, registration, IdP join) and add integration tests.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/base/src/test/java/org/keycloak/tests/organization/authz/OrganizationAdminRolesPermissionsTest.java | Adds coverage to ensure attaching roles to invitations requires map-role permission. |
| tests/base/src/test/java/org/keycloak/tests/organization/admin/OrganizationInvitationRoleTest.java | New end-to-end integration tests covering role grant, unknown/deleted roles, and resend behavior. |
| services/src/main/java/org/keycloak/organization/utils/Organizations.java | Adds helper to grant roles from an invitation during acceptance. |
| services/src/main/java/org/keycloak/organization/authentication/authenticators/broker/IdpAddOrganizationMemberAuthenticator.java | Grants invitation roles when accepting via broker flow. |
| services/src/main/java/org/keycloak/organization/admin/resource/OrganizationMemberResource.java | Extends invite endpoints to accept repeated roles form param. |
| services/src/main/java/org/keycloak/organization/admin/resource/OrganizationInvitationResource.java | Resolves/authorizes role ids, persists them on invitations, returns roles in representations, and preserves roles on resend. |
| services/src/main/java/org/keycloak/authentication/forms/RegistrationUserCreation.java | Grants invitation roles when invite is accepted via registration flow. |
| services/src/main/java/org/keycloak/authentication/actiontoken/inviteorg/InviteOrgActionTokenHandler.java | Grants invitation roles when invite is accepted via action token. |
| server-spi/src/main/java/org/keycloak/models/OrganizationInvitationModel.java | Extends invitation model contract with role id getters/setters. |
| model/jpa/src/main/resources/META-INF/jpa-changelog-26.8.0.xml | Adds Liquibase changelog for ORG_INVITATION_ROLE table. |
| model/jpa/src/main/java/org/keycloak/models/jpa/entities/OrganizationInvitationEntity.java | Implements role id persistence via @ElementCollection. |
| js/libs/keycloak-admin-client/src/defs/organizationInvitationRepresentation.ts | Adds roles field to JS admin client types. |
| integration/admin-client-core/src/main/java/org/keycloak/admin/client/resource/OrganizationMembersResource.java | Adds admin-client overloads that accept role ids. |
| docs/documentation/server_admin/topics/organizations/managing-members.adoc | Documents roles form parameter behavior and permission requirements. |
| docs/documentation/release_notes/topics/26_8_0.adoc | Adds release note entry for invitation role grants. |
| core/src/main/java/org/keycloak/representations/idm/OrganizationInvitationRepresentation.java | Adds roles to invitation representation. |
Note
Copilot is running an experiment and ran this review at Lite.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Suppressed comments (1)
services/src/main/java/org/keycloak/organization/authentication/authenticators/broker/IdpAddOrganizationMemberAuthenticator.java:1
- This introduces an extra
getById(...)lookup during IdP login flows. Ifinvitationis already anOrganizationInvitationModelinstance (not just an ID holder), you can pass it directly tograntInvitationRoles(...)to avoid a redundant DB read per acceptance.
/*
Note
Copilot is running an experiment and ran this review at Lite.
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.cluster.ClientScopeInvalidationClusterTest#crudWithoutFailoverorg.keycloak.testsuite.cluster.ClientScopeInvalidationClusterTest#crudWithFailoverorg.keycloak.testsuite.adapter.servlet.SAMLServletAdapterTest#salesPostEmptyConsumerPostURLKeycloak CI - Adapter IT Strict Cookies |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.
Note
Copilot is running an experiment and ran this review at Lite.
There was a problem hiding this comment.
🟡 Changes recommended
The new SPI methods break minor-release compatibility, and the database column rejects valid federated role IDs.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 19/19 changed files
- Comments generated: 2
- Review effort level: Balanced (auto)
Note
Copilot is running an experiment and ran this review at Balanced.
There was a problem hiding this comment.
🟡 Changes recommended
The IdP acceptance path can grant roles to a different same-email account without the required user-specific authorization.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 18/18 changed files
- Comments generated: 1
- Review effort level: Balanced (auto)
Note
Copilot is running an experiment and ran this review at Balanced.
cd15c59 to
88d73b5
Compare
88d73b5 to
cd637e2
Compare
cd637e2 to
b0a9d1c
Compare
b0a9d1c to
d04f09b
Compare
d04f09b to
93c3d3c
Compare
There was a problem hiding this comment.
🟡 Changes recommended
LDAP-backed role grants can survive failed invitation acceptance, breaking atomicity, while invitation responses expose role metadata without role-view permission checks.
2 open issues
2 resolved since last review
Review effort: Balanced
Organization invitations can now carry realm and client roles. The invite-user and invite-existing-user endpoints take an optional repeated roles parameter with role ids, and invitation representations expose the roles they grant. Attaching roles needs the same permissions as mapping them directly: each role goes through the map-role check and the invitee through the map-roles check, so an administrator cannot attach a role they could not grant, nor grant roles to a user they are not allowed to map roles to. Someone invited to register has no account yet, so that check falls back to users in general. Unknown and blank role ids are rejected. The ids are stored in a new ORG_INVITATION_ROLE table, mapped like the scope mappings of a client, with the foreign key to ORG_INVITATION cascading on delete. Deleting a role removes its rows next to the other role references, and the role id column is as wide as the one used for user role mappings so that federated ids fit. The roles are granted right after the membership is added, from the invitation link, the registration flow and an identity provider, so both commit together. Resending an invitation keeps its roles and checks the permissions again, against the administrator resending it. Closes keycloak#45238 Signed-off-by: Alexis Rico <sferadev@gmail.com>
93c3d3c to
3f775db
Compare


Closes #45238
This lets an organization invitation carry realm and client roles, granted when the invitee joins. Right now the only way to do this is an
INVITE_ORGevent listener that looks the invitation up again and maps the roles outside the transaction that adds the member, which is what we run today.invite-userandinvite-existing-usertake an optional, repeatedrolesform parameter with role ids:Invitation representations now include
roles. Without the parameter nothing changes. The admin client gets matchinginviteUser/inviteExistingUseroverloads, and the JS admin client type getsroles.Attaching roles needs the same permissions as mapping them directly:
auth.roles().requireMapRole(role)for each role andauth.users().requireMapRoles(user)for the invitee, checked before the invitation is created or the email is sent. So an admin can't attach a role they couldn't grant (e.g.manage-orgs-admininviting someone asrealm-admingets a 403), or grant roles to a user they can't map roles to. Someone invited to register has no user yet, so that check falls back to map-roles on users in general. Unknown role ids return 400.The ids are stored in a new
ORG_INVITATION_ROLEtable, mapped likeSCOPE_MAPPINGon clients, with the FK toORG_INVITATIONcascading on delete. There's no FK toKEYCLOAK_ROLE; deleting a role removes its rows inJpaRealmProvider.preRemove, next to the scope mapping cleanup. The roles are granted right after the membership is added inInviteOrgActionTokenHandler,RegistrationUserCreationandIdpAddOrganizationMemberAuthenticator, so both commit together. Resending an invitation keeps its roles.Not included: organization roles (waiting on #50606), groups and invitation attributes (#48842), and the admin console, which I'd rather do in a follow-up.
Tests: new
OrganizationInvitationRoleTest(link, registration, unknown role, deleted role, resend), a permission case inOrganizationAdminRolesPermissionsTest, andOrganizationIn 8000 vitationRoleFgapTestfor the user-level check with FGAP v2. Those pass locally, and so do the existingOrganizationInvitationLinkTestandOrganizationInvitationManagementTest.A few things I wasn't sure about:
roles? I went with ids to avoid realm/client name clashes.rolesmove into the JSON body once Add custom attributes support to organization invitations #48842 lands?I used an AI coding assistant while working on this, and I've reviewed the change and will handle the review myself.