Fix missing response content type and more explicit error handling

Closes #36410

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Alexander Schwartz 2025-01-13 21:14:59 +01:00 committed by Alexander Schwartz
parent b997d0506f
commit f392675d41
2 changed files with 10 additions and 2 deletions

View File

@ -43,6 +43,7 @@ import { emptyFormatter } from "../../util";
import { useConfirmDialog } from "../confirm-dialog/ConfirmDialog";
import { BruteUser, findUsers } from "../role-mapping/resource";
import { UserDataTableToolbarItems } from "./UserDataTableToolbarItems";
import { NetworkError } from "@keycloak/keycloak-admin-client";
export type UserFilter = {
exact: boolean;
@ -141,8 +142,13 @@ export function UserDataTable() {
fetchRealmInfo(adminClient),
adminClient.users.getProfile(),
]);
} catch {
return [{}, {}] as [UiRealmInfo, UserProfileConfig];
} catch (error) {
if (error instanceof NetworkError && error?.response?.status === 403) {
// "User Profile" attributes not available for Users Attribute search, when admin user does not have view- or manage-realm realm-management role
return [{}, {}] as [UiRealmInfo, UserProfileConfig];
} else {
throw error;
}
}
},
([uiRealmInfo, profile]) => {

View File

@ -19,6 +19,7 @@
package org.keycloak.admin.ui.rest;
import jakarta.ws.rs.Produces;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.media.Content;
@ -81,6 +82,7 @@ public class UIRealmResource {
@Operation(summary = "Gets information about the realm, viewable by all realm admins")
@APIResponse(responseCode = "200", description = "", content = {
@Content(schema = @Schema(implementation = UIRealmInfo.class, type = SchemaType.OBJECT))})
@Produces(MediaType.APPLICATION_JSON)
public UIRealmInfo getInfo() {
auth.requireAnyAdminRole();