Skip to content

Conversation

@everettbu
Copy link
Contributor

Test 6

…ation implementation

Closes #35562

Signed-off-by: vramik <[email protected]>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR implements Groups resource type and scopes in Keycloak's authorization schema as part of the Fine-Grained Admin Permissions (FGAP) V2 system. The changes introduce a new authorization paradigm that moves from traditional role-based permissions to a more granular resource-type and scope-based system.

Key architectural changes:

  • New Groups Resource Type: Added GROUPS_RESOURCE_TYPE to AdminPermissionsSchema with specific scopes (manage-membership, manage-members, view-members) alongside existing manage and view scopes
  • V2 Permission Classes: Introduced GroupPermissionsV2 and updated UserPermissionsV2 that extend existing permission classes but use the new schema-based authorization model
  • API Method Changes: Renamed methods like getGroupsWithViewPermission() to getGroupIdsWithViewPermission() to work with string IDs rather than full objects for better performance
  • Permission Evaluation Refactoring: Simplified permission checks by removing helper methods and inlining logic, moving from conditional checks to direct role evaluations combined with schema-based permissions

Integration changes:

  • Updated MgmtPermissionsV2 to include group permissions support through lazy-initialized GroupPermissionsV2
  • Modified resource classes (GroupsResource, UsersResource, GroupResource) to use the new permission evaluation methods
  • Enhanced test coverage with comprehensive GroupResourceTypeEvaluationTest that validates various group permission scenarios
  • Added extensive JavaDoc documentation explaining the dual authorization approach (traditional AdminRoles + new AdminPermissionsSchema)

The implementation follows established patterns from the existing Users and Clients resource types, ensuring consistency across the authorization system. The changes maintain backward compatibility while enabling more granular permission control for group management operations.

Confidence score: 3/5

  • This PR introduces significant authorization system changes that could impact security and access control if not properly implemented
  • There's a critical bug in AdminPermissionsSchema.getResourceName() method that doesn't handle the newly added Groups resource type, which could cause runtime exceptions
  • Several files have minor issues like syntax errors (double semicolon in test file) and logic inconsistencies (empty set return when all groups should be accessible)
  • Files that need more attention: AdminPermissionsSchema.java, GroupPermissionsV2.java, GroupResourceTypeEvaluationTest.java

19 files reviewed, 6 comments

Edit Code Review Bot Settings | Greptile

/**
* If {@link UserPermissionEvaluator#canView()} evaluates to {@code true}, returns empty set.
*
* @return Stream of IDs of groups with view permission.
Copy link

Choose a reason for hiding this comment

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

syntax: Documentation incorrectly states '@return Stream of IDs' but method signature returns Set<String>

Suggested change
* @return Stream of IDs of groups with view permission.
* @return Set of IDs of groups with view permission.

Keycloak realmAdminClient;

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

Choose a reason for hiding this comment

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

syntax: Double semicolon syntax error

Suggested change
private final GroupRepresentation topGroup = new GroupRepresentation();;
private final GroupRepresentation topGroup = new GroupRepresentation();

/**
* Returns {@code true} if the caller has {@link AdminRoles#MANAGE_USERS} role.
* <p/>
* Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the user or
Copy link

Choose a reason for hiding this comment

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

syntax: Missing space after 'or' in the JavaDoc comment

Suggested change
* Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the user or
* Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the user or

/**
* Returns {@code true} if the caller has {@link AdminRoles#MANAGE_USERS} role.
* <p/>
* Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the user or
Copy link

Choose a reason for hiding this comment

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

syntax: Missing space after 'or' in the JavaDoc comment

Suggested change
* Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the user or
* Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the user or

Comment on lines +106 to +107
public Set<String> getGroupIdsWithViewPermission() {
if (root.users().canView()) return Collections.emptySet();
Copy link

Choose a reason for hiding this comment

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

logic: Logic error: when users can view all groups globally, this should return all group IDs, not an empty set

return true;
}

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

Choose a reason for hiding this comment

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

logic: Inconsistent scope check: canManage() checks VIEW and MANAGE scopes, but should only check MANAGE scope

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.

2 participants