2021-09-02 20:14:43 +00:00
|
|
|
import { Breadcrumb, BreadcrumbItem, Spinner } from "@patternfly/react-core";
|
2021-08-26 08:39:35 +00:00
|
|
|
import type ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation";
|
|
|
|
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
2021-09-29 08:51:47 +00:00
|
|
|
import React, { useState } from "react";
|
2021-07-21 09:30:18 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { Link } from "react-router-dom";
|
2021-04-29 06:28:59 +00:00
|
|
|
import { useAdminClient, useFetch } from "../context/auth/AdminClient";
|
2021-01-13 19:59:45 +00:00
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { KEY_PROVIDER_TYPE } from "../util";
|
2021-08-10 13:07:59 +00:00
|
|
|
import { toRealmSettings } from "./routes/RealmSettings";
|
2021-09-02 20:14:43 +00:00
|
|
|
import { RealmSettingsTabs } from "./RealmSettingsTabs";
|
2021-10-21 18:40:02 +00:00
|
|
|
import { toClientPolicies } from "./routes/ClientPolicies";
|
2021-01-13 19:59:45 +00:00
|
|
|
|
2021-07-20 18:47:05 +00:00
|
|
|
export const EditProviderCrumb = () => {
|
|
|
|
const { t } = useTranslation("realm-settings");
|
|
|
|
const { realm } = useRealm();
|
|
|
|
|
|
|
|
return (
|
2021-08-26 12:15:28 +00:00
|
|
|
<Breadcrumb>
|
|
|
|
<BreadcrumbItem
|
|
|
|
render={(props) => (
|
|
|
|
<Link {...props} to={toRealmSettings({ realm, tab: "keys" })}>
|
|
|
|
{t("keys")}
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<BreadcrumbItem>{t("providers")}</BreadcrumbItem>
|
|
|
|
<BreadcrumbItem isActive>{t("editProvider")}</BreadcrumbItem>
|
|
|
|
</Breadcrumb>
|
2021-07-20 18:47:05 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-10-21 18:40:02 +00:00
|
|
|
export const ToClientPolicies = () => {
|
|
|
|
const { t } = useTranslation("realm-settings");
|
|
|
|
const { realm } = useRealm();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BreadcrumbItem
|
|
|
|
render={(props) => (
|
|
|
|
<Link {...props} to={toClientPolicies({ realm })}>
|
|
|
|
{t("clientPolicies")}
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const EditPolicyCrumb = () => {
|
|
|
|
const { t } = useTranslation("realm-settings");
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Breadcrumb>
|
|
|
|
<ToClientPolicies />
|
|
|
|
<BreadcrumbItem isActive>{t("policyDetails")}</BreadcrumbItem>
|
|
|
|
</Breadcrumb>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const NewPolicyCrumb = () => {
|
|
|
|
const { t } = useTranslation("realm-settings");
|
|
|
|
const { realm } = useRealm();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Breadcrumb>
|
|
|
|
<BreadcrumbItem
|
|
|
|
render={(props) => (
|
|
|
|
<Link {...props} to={toClientPolicies({ realm })}>
|
|
|
|
{t("clientPolicies")}
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<BreadcrumbItem isActive>{t("createPolicy")}</BreadcrumbItem>
|
|
|
|
</Breadcrumb>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-08-20 16:15:12 +00:00
|
|
|
const sortByPriority = (components: ComponentRepresentation[]) => {
|
|
|
|
const sortedComponents = [...components].sort((a, b) => {
|
|
|
|
const priorityA = Number(a.config?.priority);
|
|
|
|
const priorityB = Number(b.config?.priority);
|
|
|
|
|
|
|
|
return (
|
|
|
|
(!isNaN(priorityB) ? priorityB : 0) - (!isNaN(priorityA) ? priorityA : 0)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return sortedComponents;
|
|
|
|
};
|
|
|
|
|
2021-10-29 16:11:06 +00:00
|
|
|
export default function RealmSettingsSection() {
|
2021-01-13 19:59:45 +00:00
|
|
|
const adminClient = useAdminClient();
|
2021-09-02 20:14:43 +00:00
|
|
|
const { realm: realmName } = useRealm();
|
2021-04-30 19:08:12 +00:00
|
|
|
const [realm, setRealm] = useState<RealmRepresentation>();
|
2021-07-05 11:24:10 +00:00
|
|
|
const [realmComponents, setRealmComponents] =
|
|
|
|
useState<ComponentRepresentation[]>();
|
2021-09-27 17:15:36 +00:00
|
|
|
const [key, setKey] = useState(0);
|
|
|
|
|
|
|
|
const refresh = () => {
|
|
|
|
setKey(key + 1);
|
|
|
|
};
|
|
|
|
|
2021-04-29 06:28:59 +00:00
|
|
|
useFetch(
|
2021-05-27 07:01:55 +00:00
|
|
|
async () => {
|
|
|
|
const realm = await adminClient.realms.findOne({ realm: realmName });
|
|
|
|
const realmComponents = await adminClient.components.find({
|
2021-08-20 16:15:12 +00:00
|
|
|
type: KEY_PROVIDER_TYPE,
|
2021-05-27 07:01:55 +00:00
|
|
|
realm: realmName,
|
|
|
|
});
|
|
|
|
|
2021-10-14 21:08:42 +00:00
|
|
|
return { realm, realmComponents };
|
2021-05-27 07:01:55 +00:00
|
|
|
},
|
2021-10-14 21:08:42 +00:00
|
|
|
({ realm, realmComponents }) => {
|
2021-08-20 16:15:12 +00:00
|
|
|
setRealmComponents(sortByPriority(realmComponents));
|
2021-07-09 14:23:49 +00:00
|
|
|
setRealm(realm);
|
2021-04-29 06:28:59 +00:00
|
|
|
},
|
2021-09-29 08:51:47 +00:00
|
|
|
[key]
|
2021-04-29 06:28:59 +00:00
|
|
|
);
|
2021-01-13 19:59:45 +00:00
|
|
|
|
2021-10-14 21:08:42 +00:00
|
|
|
if (!realm || !realmComponents) {
|
2021-08-23 19:00:42 +00:00
|
|
|
return (
|
|
|
|
<div className="pf-u-text-align-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-01-13 19:59:45 +00:00
|
|
|
return (
|
2021-09-02 20:14:43 +00:00
|
|
|
<RealmSettingsTabs
|
|
|
|
realm={realm}
|
2021-09-27 17:15:36 +00:00
|
|
|
refresh={refresh}
|
2021-09-02 20:14:43 +00:00
|
|
|
realmComponents={realmComponents}
|
|
|
|
/>
|
2021-01-13 19:59:45 +00:00
|
|
|
);
|
2021-10-29 16:11:06 +00:00
|
|
|
}
|