From cf7fd375d03f5d51ab6a554eced617cc498c8b74 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Tue, 10 Dec 2024 07:34:50 -0300 Subject: [PATCH] Better path parameter names for organization and member APIs Closes #35745 Signed-off-by: Pedro Igor --- .../resource/OrganizationMemberResource.java | 24 +++++++++---------- .../admin/resource/OrganizationsResource.java | 14 +++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationMemberResource.java b/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationMemberResource.java index 572df303a086..818601fd7a5c 100644 --- a/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationMemberResource.java +++ b/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationMemberResource.java @@ -154,7 +154,7 @@ public Stream search( return provider.getMembersStream(organization, filters, exact, first, max).map(this::toRepresentation); } - @Path("{id}") + @Path("{member-id}") @GET @Produces(MediaType.APPLICATION_JSON) @NoCache @@ -162,26 +162,26 @@ public Stream search( @Operation( summary = "Returns the member of the organization with the specified id", description = "Searches for a" + "user with the given id. If one is found, and is currently a member of the organization, returns it. Otherwise," + "an error response with status NOT_FOUND is returned") - public MemberRepresentation get(@PathParam("id") String id) { - if (StringUtil.isBlank(id)) { + public MemberRepresentation get(@PathParam("member-id") String memberId) { + if (StringUtil.isBlank(memberId)) { throw ErrorResponse.error("id cannot be null", Status.BAD_REQUEST); } - return toRepresentation(getMember(id)); + return toRepresentation(getMember(memberId)); } - @Path("{id}") + @Path("{member-id}") @DELETE @Tag(name = KeycloakOpenAPI.Admin.Tags.ORGANIZATIONS) @Operation(summary = "Removes the user with the specified id from the organization", description = "Breaks the association " + "between the user and organization. The user itself is deleted in case the membership is managed, otherwise the user is not deleted. " + "If no user is found, or if they are not a member of the organization, an error response is returned") - public Response delete(@PathParam("id") String id) { - if (StringUtil.isBlank(id)) { + public Response delete(@PathParam("member-id") String memberId) { + if (StringUtil.isBlank(memberId)) { throw ErrorResponse.error("id cannot be null", Status.BAD_REQUEST); } - UserModel member = getMember(id); + UserModel member = getMember(memberId); if (provider.removeMember(organization, member)) { adminEvent.operation(OperationType.DELETE).resource(ResourceType.ORGANIZATION_MEMBERSHIP) @@ -196,18 +196,18 @@ public Response delete(@PathParam("id") String id) { throw ErrorResponse.error("Not a member of the organization", Status.BAD_REQUEST); } - @Path("{id}/organizations") + @Path("{member-id}/organizations") @GET @Produces(MediaType.APPLICATION_JSON) @NoCache @Tag(name = KeycloakOpenAPI.Admin.Tags.ORGANIZATIONS) @Operation(summary = "Returns the organizations associated with the user that has the specified id") - public Stream getOrganizations(@PathParam("id") String id) { - if (StringUtil.isBlank(id)) { + public Stream getOrganizations(@PathParam("member-id") String memberId) { + if (StringUtil.isBlank(memberId)) { throw ErrorResponse.error("id cannot be null", Status.BAD_REQUEST); } - UserModel member = getUser(id); + UserModel member = getUser(memberId); return provider.getByMember(member).map(ModelToRepresentation::toRepresentation); } diff --git a/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationsResource.java b/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationsResource.java index f19b85ffb010..c73e447211dd 100644 --- a/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationsResource.java +++ b/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationsResource.java @@ -151,16 +151,16 @@ public Stream search( /** * Base path for the admin REST API for one particular organization. */ - @Path("{id}") - public OrganizationResource get(@PathParam("id") String id) { + @Path("{org-id}") + public OrganizationResource get(@PathParam("org-id") String orgId) { auth.realm().requireManageRealm(); Organizations.checkEnabled(provider); - if (StringUtil.isBlank(id)) { + if (StringUtil.isBlank(orgId)) { throw ErrorResponse.error("Id cannot be null.", Response.Status.BAD_REQUEST); } - OrganizationModel organizationModel = provider.getById(id); + OrganizationModel organizationModel = provider.getById(orgId); if (organizationModel == null) { throw ErrorResponse.error("Organization not found.", Response.Status.NOT_FOUND); @@ -171,13 +171,13 @@ public OrganizationResource get(@PathParam("id") String id) { return new OrganizationResource(session, organizationModel, adminEvent); } - @Path("members/{id}/organizations") + @Path("members/{member-id}/organizations") @GET @Produces(MediaType.APPLICATION_JSON) @NoCache @Tag(name = KeycloakOpenAPI.Admin.Tags.ORGANIZATIONS) @Operation(summary = "Returns the organizations associated with the user that has the specified id") - public Stream getOrganizations(@PathParam("id") String id) { - return new OrganizationMemberResource(session, null, adminEvent).getOrganizations(id); + public Stream getOrganizations(@PathParam("member-id") String memberId) { + return new OrganizationMemberResource(session, null, adminEvent).getOrganizations(memberId); } }