Skip to content

Commit

Permalink
Persist admin event only when roles is non-empty
Browse files Browse the repository at this point in the history
Currently, an adminEvent is created regardless of if the roles passed to the
role-mapping API is empty. The event should only be created when the list
`roles` is non-empty.

Closes keycloak#33195

Signed-off-by: Venkatesh Kannan <[email protected]>
  • Loading branch information
venkatesh2090 authored and pedroigor committed Nov 29, 2024
1 parent babd656 commit cb28f35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public void addClientRoleMapping(List<RoleRepresentation> roles) {
throw new ErrorResponseException("invalid_request", "Could not add user role or group mappings!", Response.Status.BAD_REQUEST);
}

adminEvent.operation(OperationType.CREATE).resourcePath(uriInfo).representation(roles).success();
if (!roles.isEmpty()) {
adminEvent.operation(OperationType.CREATE).resourcePath(uriInfo).representation(roles).success();
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ public void addRealmRoleMappings(@Parameter(description = "Roles to add") List<R
throw new ErrorResponseException("invalid_request", "Could not add user role mappings!", Response.Status.BAD_REQUEST);
}

adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri()).representation(roles).success();
if (!roles.isEmpty()) {
adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri()).representation(roles).success();
}
}

/**
Expand Down

0 comments on commit cb28f35

Please sign in to comment.