Skip to content

Commit

Permalink
getParentRoles
Browse files Browse the repository at this point in the history
  • Loading branch information
axel authored and axel committed Nov 28, 2023
1 parent 9f92866 commit b29471e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion server-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ you may not use this file except in compliance with the License.tt
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,21 +33,11 @@
import org.keycloak.representations.idm.ManagementPermissionReference;
import org.keycloak.representations.idm.RoleRepresentation;
import org.keycloak.services.ErrorResponse;
import org.keycloak.services.ErrorResponseException;
import org.keycloak.services.resources.KeycloakOpenAPI;
import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator;
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;
Expand Down Expand Up @@ -270,6 +260,29 @@ public void deleteComposites(final @Parameter(description = "Role id") @PathPara
auth.roles().requireManage(role);
deleteComposites(adminEvent, session.getContext().getUri(), roles, role);
}

/**
* 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<RoleRepresentation> 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 Authoirzation permissions have been initialized or not and a reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.keycloak.events.admin.OperationType;
import org.keycloak.events.admin.ResourceType;
import org.keycloak.models.*;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.models.utils.ModelToRepresentation;
import org.keycloak.models.utils.RoleUtils;
import org.keycloak.representations.idm.GroupRepresentation;
Expand Down Expand Up @@ -58,7 +57,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.keycloak.services.ErrorResponseException;

/**
* @resource Roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.Set;
import java.util.stream.Stream;

import java.util.Collections;
import java.util.stream.Collectors;

/**
Expand Down

0 comments on commit b29471e

Please sign in to comment.