From c72bc8cedb45a7af7d7be06607593a3b533db9e4 Mon Sep 17 00:00:00 2001 From: Axel Messinese Date: Thu, 7 Nov 2024 14:54:45 +0100 Subject: [PATCH] fixup --- .../resources/admin/RoleByIdResource.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/admin/RoleByIdResource.java b/services/src/main/java/org/keycloak/services/resources/admin/RoleByIdResource.java index 9bd9d9a11bf0..12a232beb551 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/RoleByIdResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/RoleByIdResource.java @@ -16,13 +16,13 @@ */ package org.keycloak.services.resources.admin; +import jakarta.ws.rs.*; import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.extensions.Extension; import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; import org.eclipse.microprofile.openapi.annotations.tags.Tag; import org.jboss.logging.Logger; import org.jboss.resteasy.annotations.cache.NoCache; -import jakarta.ws.rs.NotFoundException; import org.keycloak.events.admin.OperationType; import org.keycloak.events.admin.ResourceType; import org.keycloak.models.ClientModel; @@ -39,15 +39,6 @@ import org.keycloak.services.resources.admin.permissions.AdminPermissionManagement; import org.keycloak.services.resources.admin.permissions.AdminPermissions; -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.DELETE; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.PUT; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import java.util.List; @@ -303,6 +294,29 @@ public static ManagementPermissionReference toMgmtRef(RoleModel role, AdminPermi return ref; } + /** + * Get parents of the roles, thoses which have the given role as composite + * + * @param id Role id + * @param briefRepresentation if false, return a full representation of the roles with their attributes + * @return parents of the roles + */ + @Path("{role-id}/parents") + @GET + @NoCache + @Produces(MediaType.APPLICATION_JSON) + public Set getParentsRoles(final @PathParam("role-id") String id, + final @QueryParam("briefRepresentation") @DefaultValue("true") boolean briefRepresentation) { + RoleModel role = getRoleModel(id); + auth.roles().requireManage(role); + + if (role == null) { + throw new NotFoundException("Could not find role"); + } + + return getParentsRoles(role, briefRepresentation); + } + /** * Return object stating whether role Authorization permissions have been initialized or not and a reference *