Use cryptoInfo
to populate key type dropdowns (#3818)
This commit is contained in:
parent
0e04f088e2
commit
2ed958b4d0
4 changed files with 26 additions and 13 deletions
|
@ -4,7 +4,7 @@ import { Button, Modal, Form } from "@patternfly/react-core";
|
||||||
import { saveAs } from "file-saver";
|
import { saveAs } from "file-saver";
|
||||||
|
|
||||||
import KeyStoreConfig from "@keycloak/keycloak-admin-client/lib/defs/keystoreConfig";
|
import KeyStoreConfig from "@keycloak/keycloak-admin-client/lib/defs/keystoreConfig";
|
||||||
import { KeyForm } from "./GenerateKeyDialog";
|
import { KeyForm, getFileExtension } from "./GenerateKeyDialog";
|
||||||
import { useRealm } from "../../context/realm-context/RealmContext";
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
||||||
import { useAdminClient } from "../../context/auth/AdminClient";
|
import { useAdminClient } from "../../context/auth/AdminClient";
|
||||||
import { useAlerts } from "../../components/alert/Alerts";
|
import { useAlerts } from "../../components/alert/Alerts";
|
||||||
|
@ -39,7 +39,7 @@ export const ExportSamlKeyDialog = ({
|
||||||
);
|
);
|
||||||
saveAs(
|
saveAs(
|
||||||
new Blob([keyStore], { type: "application/octet-stream" }),
|
new Blob([keyStore], { type: "application/octet-stream" }),
|
||||||
`keystore.${config.format == "PKCS12" ? "p12" : "jks"}`
|
`keystore.${getFileExtension(config.format ?? "")}`
|
||||||
);
|
);
|
||||||
addAlert(t("samlKeysExportSuccess"));
|
addAlert(t("samlKeysExportSuccess"));
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import type KeyStoreConfig from "@keycloak/keycloak-admin-client/lib/defs/keysto
|
||||||
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
||||||
import { StoreSettings } from "./StoreSettings";
|
import { StoreSettings } from "./StoreSettings";
|
||||||
import { FileUpload } from "../../components/json-file-upload/patternfly/FileUpload";
|
import { FileUpload } from "../../components/json-file-upload/patternfly/FileUpload";
|
||||||
|
import { useServerInfo } from "../../context/server-info/ServerInfoProvider";
|
||||||
|
|
||||||
type GenerateKeyDialogProps = {
|
type GenerateKeyDialogProps = {
|
||||||
clientId: string;
|
clientId: string;
|
||||||
|
@ -39,6 +40,14 @@ type KeyFormProps = {
|
||||||
|
|
||||||
const CERT_PEM = "Certificate PEM" as const;
|
const CERT_PEM = "Certificate PEM" as const;
|
||||||
|
|
||||||
|
const extensions = new Map([
|
||||||
|
["PKCS12", "p12"],
|
||||||
|
["JKS", "jks"],
|
||||||
|
["BCFKS", "bcfks"],
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const getFileExtension = (format: string) => extensions.get(format);
|
||||||
|
|
||||||
export const KeyForm = ({
|
export const KeyForm = ({
|
||||||
isSaml = false,
|
isSaml = false,
|
||||||
hasPem = false,
|
hasPem = false,
|
||||||
|
@ -52,6 +61,8 @@ export const KeyForm = ({
|
||||||
const { control, watch } = useFormContext<KeyStoreConfig>();
|
const { control, watch } = useFormContext<KeyStoreConfig>();
|
||||||
const format = watch("format");
|
const format = watch("format");
|
||||||
|
|
||||||
|
const { cryptoInfo } = useServerInfo();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form className="pf-u-pt-lg">
|
<Form className="pf-u-pt-lg">
|
||||||
<FormGroup
|
<FormGroup
|
||||||
|
@ -81,7 +92,7 @@ export const KeyForm = ({
|
||||||
aria-label={t("archiveFormat")}
|
aria-label={t("archiveFormat")}
|
||||||
isOpen={openArchiveFormat}
|
isOpen={openArchiveFormat}
|
||||||
>
|
>
|
||||||
{["JKS", "PKCS12"]
|
{cryptoInfo?.supportedKeystoreTypes
|
||||||
.concat(hasPem ? CERT_PEM : [])
|
.concat(hasPem ? CERT_PEM : [])
|
||||||
.map((option) => (
|
.map((option) => (
|
||||||
<SelectOption
|
<SelectOption
|
||||||
|
|
|
@ -17,20 +17,13 @@ import {
|
||||||
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
||||||
import { StoreSettings } from "./StoreSettings";
|
import { StoreSettings } from "./StoreSettings";
|
||||||
import { FileUpload } from "../../components/json-file-upload/patternfly/FileUpload";
|
import { FileUpload } from "../../components/json-file-upload/patternfly/FileUpload";
|
||||||
|
import { useServerInfo } from "../../context/server-info/ServerInfoProvider";
|
||||||
|
|
||||||
type ImportKeyDialogProps = {
|
type ImportKeyDialogProps = {
|
||||||
toggleDialog: () => void;
|
toggleDialog: () => void;
|
||||||
save: (importFile: ImportFile) => void;
|
save: (importFile: ImportFile) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const baseFormats = ["JKS", "PKCS12"];
|
|
||||||
|
|
||||||
const formats = baseFormats.concat([
|
|
||||||
"Certificate PEM",
|
|
||||||
"Public Key PEM",
|
|
||||||
"JSON Web Key Set",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export type ImportFile = {
|
export type ImportFile = {
|
||||||
keystoreFormat: string;
|
keystoreFormat: string;
|
||||||
keyAlias: string;
|
keyAlias: string;
|
||||||
|
@ -53,6 +46,15 @@ export const ImportKeyDialog = ({
|
||||||
name: "keystoreFormat",
|
name: "keystoreFormat",
|
||||||
defaultValue: "JKS",
|
defaultValue: "JKS",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const baseFormats = useServerInfo().cryptoInfo?.supportedKeystoreTypes ?? [];
|
||||||
|
|
||||||
|
const formats = baseFormats.concat([
|
||||||
|
"Certificate PEM",
|
||||||
|
"Public Key PEM",
|
||||||
|
"JSON Web Key Set",
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
variant={ModalVariant.medium}
|
variant={ModalVariant.medium}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import { HelpItem } from "../../components/help-enabler/HelpItem";
|
||||||
import { FormAccess } from "../../components/form-access/FormAccess";
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
||||||
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
|
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
|
||||||
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
||||||
import { GenerateKeyDialog } from "./GenerateKeyDialog";
|
import { GenerateKeyDialog, getFileExtension } from "./GenerateKeyDialog";
|
||||||
import { useFetch, useAdminClient } from "../../context/auth/AdminClient";
|
import { useFetch, useAdminClient } from "../../context/auth/AdminClient";
|
||||||
import { useAlerts } from "../../components/alert/Alerts";
|
import { useAlerts } from "../../components/alert/Alerts";
|
||||||
import useToggle from "../../utils/useToggle";
|
import useToggle from "../../utils/useToggle";
|
||||||
|
@ -80,7 +80,7 @@ export const Keys = ({ clientId, save, hasConfigureAccess }: KeysProps) => {
|
||||||
);
|
);
|
||||||
saveAs(
|
saveAs(
|
||||||
new Blob([keyStore], { type: "application/octet-stream" }),
|
new Blob([keyStore], { type: "application/octet-stream" }),
|
||||||
`keystore.${config.format == "PKCS12" ? "p12" : "jks"}`
|
`keystore.${getFileExtension(config.format ?? "")}`
|
||||||
);
|
);
|
||||||
addAlert(t("generateSuccess"), AlertVariant.success);
|
addAlert(t("generateSuccess"), AlertVariant.success);
|
||||||
refresh();
|
refresh();
|
||||||
|
|
Loading…
Reference in a new issue