-
Notifications
You must be signed in to change notification settings - Fork 0
Automated Test: feature-groups-authz-implementation #325
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| */ | ||
| package org.keycloak.services.resources.admin.permissions; | ||
|
|
||
| import org.keycloak.authorization.AdminPermissionsSchema; | ||
| import org.keycloak.models.AdminRoles; | ||
| import org.keycloak.models.GroupModel; | ||
|
|
||
| import java.util.Map; | ||
|
|
@@ -26,41 +28,121 @@ | |
| * @version $Revision: 1 $ | ||
| */ | ||
| public interface GroupPermissionEvaluator { | ||
|
|
||
| /** | ||
| * Returns {@code true} if the caller has at least one of {@link AdminRoles#QUERY_GROUPS}, | ||
| * {@link AdminRoles#MANAGE_USERS} or {@link AdminRoles#VIEW_USERS} roles. | ||
| * <p/> | ||
| * For V2 only: Also if it has a permission to {@link AdminPermissionsSchema#VIEW} or | ||
| * {@link AdminPermissionsSchema#MANAGE} groups. | ||
| */ | ||
| boolean canList(); | ||
|
|
||
| /** | ||
| * Throws ForbiddenException if {@link #canList()} returns {@code false}. | ||
| */ | ||
| void requireList(); | ||
|
|
||
| /** | ||
| * Returns {@code true} if the caller has {@link AdminRoles#MANAGE_USERS} role. | ||
| * <p/> | ||
| * Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the group. | ||
| */ | ||
| boolean canManage(GroupModel group); | ||
|
|
||
| /** | ||
| * Throws ForbiddenException if {@link #canManage(GroupModel)} returns {@code false}. | ||
| */ | ||
| void requireManage(GroupModel group); | ||
|
|
||
| /** | ||
| * Returns {@code true} if the caller has one of {@link AdminRoles#MANAGE_USERS} or | ||
| * {@link AdminRoles#VIEW_USERS} roles. | ||
| * <p/> | ||
| * Or if it has a permission to {@link AdminPermissionsSchema#VIEW} or | ||
| * {@link AdminPermissionsSchema#MANAGE} the group. | ||
| */ | ||
| boolean canView(GroupModel group); | ||
|
|
||
| /** | ||
| * Throws ForbiddenException if {@link #canView(GroupModel)} returns {@code false}. | ||
| */ | ||
| void requireView(GroupModel group); | ||
|
|
||
| /** | ||
| * Returns {@code true} if the caller has {@link AdminRoles#MANAGE_USERS} role. | ||
| * <p/> | ||
| * For V2 only: Also if it has permission to {@link AdminPermissionsSchema#VIEW} or | ||
| * {@link AdminPermissionsSchema#MANAGE} groups. | ||
| */ | ||
| boolean canManage(); | ||
|
Comment on lines
+72
to
78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Javadoc for The Javadoc states that 🤖 Prompt for AI Agents |
||
|
|
||
| /** | ||
| * Throws ForbiddenException if {@link #canManage()} returns {@code false}. | ||
| */ | ||
| void requireManage(); | ||
|
|
||
| /** | ||
| * Returns {@code true} if the caller has one of {@link AdminRoles#MANAGE_USERS} or | ||
| * {@link AdminRoles#VIEW_USERS} roles. | ||
| * <p/> | ||
| * Or if it has a permission to {@link AdminPermissionsSchema#VIEW} or | ||
| * {@link AdminPermissionsSchema#MANAGE} groups. | ||
| */ | ||
| boolean canView(); | ||
|
|
||
| /** | ||
| * Throws ForbiddenException if {@link #canView()} returns {@code false}. | ||
| */ | ||
| void requireView(); | ||
|
|
||
| boolean getGroupsWithViewPermission(GroupModel group); | ||
|
|
||
| /** | ||
| * Throws ForbiddenException if {@link #canViewMembers(GroupModel)} returns {@code false}. | ||
| */ | ||
| void requireViewMembers(GroupModel group); | ||
|
|
||
| /** | ||
| * Returns {@code true} if {@link UserPermissionEvaluator#canManage()} evaluates to {@code true}. | ||
| * <p/> | ||
| * Or if it has a permission to {@link AdminPermissionsSchema#MANAGE_MEMBERS} of the group. | ||
| */ | ||
| boolean canManageMembers(GroupModel group); | ||
|
|
||
| /** | ||
| * Returns {@code true} if the caller has one of {@link AdminRoles#MANAGE_USERS} role. | ||
| * <p/> | ||
| * Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the group or | ||
| * {@link AdminPermissionsSchema#MANAGE_MEMBERSHIP} of the group. | ||
| */ | ||
| boolean canManageMembership(GroupModel group); | ||
|
|
||
|
|
||
| /** | ||
| * Returns {@code true} if {@link UserPermissionEvaluator#canView()} evaluates to {@code true}. | ||
| * <p/> | ||
| * Or if it has a permission to {@link AdminPermissionsSchema#VIEW_MEMBERS} or | ||
| * {@link AdminPermissionsSchema#MANAGE_MEMBERS} of the group. | ||
| */ | ||
| boolean canViewMembers(GroupModel group); | ||
|
|
||
|
|
||
| /** | ||
| * Throws ForbiddenException if {@link #canManageMembership(GroupModel)} returns {@code false}. | ||
| */ | ||
| void requireManageMembership(GroupModel group); | ||
|
|
||
| /** | ||
| * Throws ForbiddenException if {@link #canManageMembership(GroupModel)} returns {@code false}. | ||
| */ | ||
| void requireManageMembers(GroupModel group); | ||
|
Comment on lines
+132
to
135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Javadoc references wrong method:
📝 Proposed fix /**
- * Throws ForbiddenException if {`@link` `#canManageMembership`(GroupModel)} returns {`@code` false}.
+ * Throws ForbiddenException if {`@link` `#canManageMembers`(GroupModel)} returns {`@code` false}.
*/
void requireManageMembers(GroupModel group);🤖 Prompt for AI Agents |
||
|
|
||
| /** | ||
| * Returns Map with information what access the caller for the provided group has. | ||
| */ | ||
| Map<String, Boolean> getAccess(GroupModel group); | ||
|
|
||
| Set<String> getGroupsWithViewPermission(); | ||
| /** | ||
| * If {@link UserPermissionEvaluator#canView()} evaluates to {@code true}, returns empty set. | ||
| * | ||
| * @return Stream of IDs of groups with view permission. | ||
| */ | ||
| Set<String> getGroupIdsWithViewPermission(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pagination before permission filtering may return fewer results than
max.The
canViewfilter is applied aftersearchGroupsByAttributeshas already applied pagination (firstResult,maxResults). If some groups are filtered out, the page will be smaller thanmaxResults. This is pre-existing behavior across all three search paths, but worth noting since the V2 per-group permission model makes it more likely that individual groups are filtered out (compared to a global admin role check that either allows all or none).🤖 Prompt for AI Agents