Skip to content

Commit

Permalink
Encode role name parameter in the location header uri
Browse files Browse the repository at this point in the history
The role is encoded to avoid template resolution by the URIBuilder. This fix avoids the exception when creating roles with names containing {patterns}.

Closes #27514

Signed-off-by: graziang <g.graziano94@gmail.com>
  • Loading branch information
graziang authored and mposolda committed Mar 6, 2024
1 parent 82af0b6 commit 39299ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.jboss.resteasy.reactive.NoCache;
import jakarta.ws.rs.NotFoundException;
import org.keycloak.common.util.Encode;
import org.keycloak.events.admin.OperationType;
import org.keycloak.events.admin.ResourceType;
import org.keycloak.models.ClientModel;
Expand Down Expand Up @@ -202,7 +203,7 @@ public Response createRole(final RoleRepresentation rep) {

adminEvent.operation(OperationType.CREATE).resourcePath(uriInfo, role.getName()).representation(rep).success();

return Response.created(uriInfo.getAbsolutePathBuilder().path(role.getName()).build()).build();
return Response.created(uriInfo.getAbsolutePathBuilder().path(Encode.encodePathSegmentAsIs(role.getName())).build()).build();
} catch (ModelDuplicateException e) {
throw ErrorResponse.exists("Role with name " + rep.getName() + " already exists");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public void createRoleWithSameName() {
rolesRsc.create(role);
}

@Test
public void createRoleWithNamePattern() {
RoleRepresentation role = RoleBuilder.create().name("role-a-{pattern}").build();
rolesRsc.create(role);
}

@Test
public void testRemoveRole() {
RoleRepresentation role2 = makeRole("role2");
Expand Down

0 comments on commit 39299ee

Please sign in to comment.