Skip to content

Add Groups resource type and scopes to authorization schema - #5

Open
ShashankFC wants to merge 1 commit into
feature-groups-authz-baselinefrom
feature-groups-authz-implementation
Open

Add Groups resource type and scopes to authorization schema#5
ShashankFC wants to merge 1 commit into
feature-groups-authz-baselinefrom
feature-groups-authz-implementation

Conversation

@ShashankFC

Copy link
Copy Markdown
Contributor

Test 6

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced group-based access control with granular permissions for viewing members, managing membership, and managing groups.
  • Tests

    • Added comprehensive test coverage for group resource-type authorization and permission evaluation scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.


Replicated from ai-code-review-evaluation/keycloak-coderabbit#6

…ation implementation

Closes #35562

Signed-off-by: vramik <vramik@redhat.com>
@ShashankFC
ShashankFC requested a review from Copilot January 30, 2026 10:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements group-based access control by adding the Groups resource type to the authorization schema and introducing granular permission scopes for managing group operations.

Changes:

  • Added new Groups resource type with five scopes: view, manage, view-members, manage-members, and manage-membership
  • Implemented GroupPermissionsV2 class to evaluate group permissions using the new scopes
  • Refactored user and group permission evaluators to integrate group-based authorization logic

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java Adds Groups resource type with new scopes for group permissions
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java New V2 implementation for evaluating group permissions
services/src/main/java/org/keycloak/services/resources/admin/permissions/MgmtPermissionsV2.java Integrates GroupPermissionsV2 into management permissions
services/src/main/java/org/keycloak/services/resources/admin/permissions/UserPermissionsV2.java Updates user permissions to delegate group membership checks
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissions.java Refactors method signatures and simplifies permission checks
services/src/main/java/org/keycloak/services/resources/admin/permissions/UserPermissions.java Removes redundant methods and updates permission evaluation
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionEvaluator.java Updates interface with comprehensive documentation
services/src/main/java/org/keycloak/services/resources/admin/permissions/UserPermissionEvaluator.java Adds detailed documentation for permission methods
services/src/main/java/org/keycloak/services/resources/admin/permissions/RolePermissions.java Updates to use refactored permission check method
services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Updates to use renamed getGroupIdsWithViewPermission method
services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java Simplifies group filtering logic
services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java Removes unnecessary variable initialization
rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java Updates to use renamed getGroupIdsWithViewPermission method
server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java Removes duplicate helper method
services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java Fixes event listener registration structure
test-framework/core/src/main/java/org/keycloak/testframework/util/ApiUtil.java Refactors to use try-with-resources for proper resource cleanup
tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/GroupResourceTypeEvaluationTest.java Adds comprehensive tests for group permission evaluation
tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/RealmAdminPermissionsConfig.java Adds QUERY_GROUPS role to test configuration
tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/UserResourceTypeEvaluationTest.java Removes unused import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

private final String groupName = "top_group";
private final GroupRepresentation topGroup = new GroupRepresentation();;

@BeforeEach // cannot use @BeforeAll, realm is not initializaed yet

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'initializaed' to 'initialized' in the comment.

Suggested change
@BeforeEach // cannot use @BeforeAll, realm is not initializaed yet
@BeforeEach // cannot use @BeforeAll, realm is not initialized yet

Copilot uses AI. Check for mistakes.
//create group permission to allow manage membership for the group
createGroupPermission(topGroup, Set.of(MANAGE_MEMBERSHIP), policy);


Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary blank line. Remove trailing whitespace for consistency.

Suggested change

Copilot uses AI. Check for mistakes.
return true;
}

return hasPermission(null, AdminPermissionsSchema.VIEW, AdminPermissionsSchema.MANAGE);

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The canManage() method is checking for VIEW and MANAGE permissions, but should only check for MANAGE permission. This is inconsistent with the pattern used in canManage(GroupModel group) on line 79 which correctly checks only MANAGE.

Suggested change
return hasPermission(null, AdminPermissionsSchema.VIEW, AdminPermissionsSchema.MANAGE);
return hasPermission(null, AdminPermissionsSchema.MANAGE);

Copilot uses AI. Check for mistakes.
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.

3 participants