Skip to content

refactor: adding a roles service for v2 - #55049

Open
shawkins wants to merge 2 commits into
keycloak:mainfrom
shawkins:iss47631
Open

shawkins wants to merge 2 commits into
keycloak:mainfrom
shawkins:iss47631

Conversation

@shawkins

Copy link
Copy Markdown
Contributor

closes: #47631

Adds a common role service. Since the role classes hold very little state, this is just directly passing the values to the methods. If we want a better way to transfer state, then we could consider adding directly creatable versions of the model classes (like we are already doing for client models) or a service specific representation.

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 unpaginated by-name endpoint now uses a search overload that adds a database query containing all composite IDs on every request, even when the role cache is warm.

1 open issue
What changed in this PR

Extracts shared role-management logic from the v1 REST resources so the v2 client API can manage roles without depending on v1 resources, supporting #47631.

Changes:

  • Introduces a shared RoleService for role operations and permission checks.
  • Migrates v1 resources and v2 client role reconciliation to the service, keeping admin-event handling with callers.
  • Adds regression coverage for role errors, composite permissions, and v2 client events.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​admin/​realm/​RealmRolesCRUDTest.java Tests duplicate names, rename conflicts, and unknown composites.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​admin/​authz/​fgap/​RoleResourceTypeEvaluationTest.java Tests composite-mapping permissions during role creation.
services/​src/​main/​java/​org/​keycloak/​services/​ServiceException.java Adds shared service errors with suggested HTTP statuses.
services/​src/​main/​java/​org/​keycloak/​services/​roles/​RoleService.java Centralizes role operations and authorization checks.
services/​src/​main/​java/​org/​keycloak/​services/​resources/​admin/​RoleResource.java Adds shared helpers and v1 error translation.
services/​src/​main/​java/​org/​keycloak/​services/​resources/​admin/​RoleContainerResource.java Delegates name-based role operations to the service.
services/​src/​main/​java/​org/​keycloak/​services/​resources/​admin/​RoleByIdResource.java Delegates ID-based role operations to the service.
rest/​admin-v2/​tests/​src/​test/​java/​org/​keycloak/​tests/​admin/​client/​v2/​AdminEventV2Test.java Verifies role changes emit only a client event.
rest/​admin-v2/​services/​src/​main/​java/​org/​keycloak/​services/​RolesService.java Removes the wrapper around v1 role resources.
rest/​admin-v2/​services/​src/​main/​java/​org/​keycloak/​services/​client/​scim/​ClientResourceTypeProvider.java Uses the shared service for declarative client roles.

Review effort: Balanced

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

When search is omitted, the roles-by-ID endpoint paginates an unordered HashSet stream, producing arbitrary pages instead of the name-ordered results expected by existing tests.

1 open issue
1 resolved since last review

Review effort: Balanced

@shawkins
shawkins marked this pull request as ready for review November 11, 2026 17:11
@shawkins
shawkins requested review from a team as code owners November 11, 2026 17:11
@shawkins
shawkins requested review from Pepo48 and vmuzikar and a balanced review from Copilot November 11, 2026 17:11

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 whitespace-only search now returns all composites when pagination is omitted but remains filtered when pagination is supplied, so the cache optimization changes existing search semantics.

1 open issue
1 resolved since last review

Review effort: Balanced

closes: keycloak#47631

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 17:40

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 nonempty composite-role search without pagination incorrectly returns all visible composites instead of matching roles, breaking the existing search assertion.

1 open issue
1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Steven Hawkins <shawkins@redhat.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 17:47

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 were identified for the shared role-management service refactor.

No open issues 🎉

1 resolved since last review

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.

Provide API for roles management

2 participants