2021-01-26 19:39:01 +00:00
|
|
|
import React, { useState } from "react";
|
2021-08-09 08:47:34 +00:00
|
|
|
import { Link } from "react-router-dom";
|
2021-01-26 19:39:01 +00:00
|
|
|
import { Trans, useTranslation } from "react-i18next";
|
2022-03-07 17:36:52 +00:00
|
|
|
import { sortBy } from "lodash-es";
|
2021-01-26 19:39:01 +00:00
|
|
|
import {
|
|
|
|
AlertVariant,
|
|
|
|
Button,
|
|
|
|
ButtonVariant,
|
|
|
|
Label,
|
|
|
|
PageSection,
|
|
|
|
Tab,
|
|
|
|
TabTitleText,
|
2021-08-09 08:47:34 +00:00
|
|
|
ToolbarItem,
|
2021-01-26 19:39:01 +00:00
|
|
|
} from "@patternfly/react-core";
|
2020-09-09 09:07:17 +00:00
|
|
|
|
2021-08-26 08:39:35 +00:00
|
|
|
import type AuthenticationFlowRepresentation from "@keycloak/keycloak-admin-client/lib/defs/authenticationFlowRepresentation";
|
2021-01-26 19:39:01 +00:00
|
|
|
import { useAdminClient } from "../context/auth/AdminClient";
|
|
|
|
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
|
|
|
|
import { KeycloakTabs } from "../components/keycloak-tabs/KeycloakTabs";
|
|
|
|
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
|
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
|
|
|
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
|
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
|
|
|
import { toUpperCase } from "../util";
|
2021-11-30 13:07:44 +00:00
|
|
|
import useToggle from "../utils/useToggle";
|
2021-01-26 19:39:01 +00:00
|
|
|
import { DuplicateFlowModal } from "./DuplicateFlowModal";
|
2021-08-09 08:47:34 +00:00
|
|
|
import { toCreateFlow } from "./routes/CreateFlow";
|
|
|
|
import { toFlow } from "./routes/Flow";
|
2021-10-19 15:30:57 +00:00
|
|
|
import { RequiredActions } from "./RequiredActions";
|
2021-12-01 09:24:46 +00:00
|
|
|
import { Policies } from "./policies/Policies";
|
2022-03-07 17:36:52 +00:00
|
|
|
import helpUrls from "../help-urls";
|
|
|
|
import { BindFlowDialog } from "./BindFlowDialog";
|
2022-05-02 14:51:05 +00:00
|
|
|
import { UsedBy } from "./components/UsedBy";
|
2021-01-26 19:39:01 +00:00
|
|
|
|
|
|
|
import "./authentication-section.css";
|
|
|
|
|
2021-08-09 08:47:34 +00:00
|
|
|
type UsedBy = "specificClients" | "default" | "specificProviders";
|
2021-01-26 19:39:01 +00:00
|
|
|
|
2022-05-02 14:51:05 +00:00
|
|
|
export type AuthenticationType = AuthenticationFlowRepresentation & {
|
2021-01-26 19:39:01 +00:00
|
|
|
usedBy: { type?: UsedBy; values: string[] };
|
|
|
|
};
|
|
|
|
|
2022-03-07 17:36:52 +00:00
|
|
|
export const REALM_FLOWS = [
|
2021-01-26 19:39:01 +00:00
|
|
|
"browserFlow",
|
|
|
|
"registrationFlow",
|
|
|
|
"directGrantFlow",
|
|
|
|
"resetCredentialsFlow",
|
|
|
|
"clientAuthenticationFlow",
|
|
|
|
"dockerAuthenticationFlow",
|
|
|
|
];
|
|
|
|
|
2021-10-29 16:11:06 +00:00
|
|
|
export default function AuthenticationSection() {
|
2021-01-26 19:39:01 +00:00
|
|
|
const { t } = useTranslation("authentication");
|
|
|
|
const adminClient = useAdminClient();
|
|
|
|
const { realm } = useRealm();
|
|
|
|
const [key, setKey] = useState(0);
|
2022-03-07 17:36:52 +00:00
|
|
|
const refresh = () => setKey(key + 1);
|
2021-07-28 12:01:42 +00:00
|
|
|
const { addAlert, addError } = useAlerts();
|
2021-01-26 19:39:01 +00:00
|
|
|
|
|
|
|
const [selectedFlow, setSelectedFlow] = useState<AuthenticationType>();
|
2022-03-07 17:36:52 +00:00
|
|
|
const [open, toggleOpen] = useToggle();
|
|
|
|
const [bindFlowOpen, toggleBindFlow] = useToggle();
|
2021-01-26 19:39:01 +00:00
|
|
|
|
|
|
|
const loader = async () => {
|
2022-05-02 14:51:05 +00:00
|
|
|
const [allClients, allIdps, realmRep, flows] = await Promise.all([
|
2022-03-07 17:36:52 +00:00
|
|
|
adminClient.clients.find(),
|
|
|
|
adminClient.identityProviders.find(),
|
|
|
|
adminClient.realms.findOne({ realm }),
|
|
|
|
adminClient.authenticationManagement.getFlows(),
|
|
|
|
]);
|
2021-09-30 08:58:48 +00:00
|
|
|
if (!realmRep) {
|
|
|
|
throw new Error(t("common:notFound"));
|
|
|
|
}
|
|
|
|
|
2021-01-26 19:39:01 +00:00
|
|
|
const defaultFlows = Object.entries(realmRep)
|
2022-03-07 17:36:52 +00:00
|
|
|
.filter((entry) => REALM_FLOWS.includes(entry[0]))
|
2021-01-26 19:39:01 +00:00
|
|
|
.map((entry) => entry[1]);
|
|
|
|
|
2022-03-07 17:36:52 +00:00
|
|
|
for (const flow of flows as AuthenticationType[]) {
|
2021-01-26 19:39:01 +00:00
|
|
|
flow.usedBy = { values: [] };
|
2022-05-02 14:51:05 +00:00
|
|
|
const clients = allClients.filter(
|
2021-01-26 19:39:01 +00:00
|
|
|
(client) =>
|
|
|
|
client.authenticationFlowBindingOverrides &&
|
|
|
|
(client.authenticationFlowBindingOverrides["direct_grant"] ===
|
|
|
|
flow.id ||
|
|
|
|
client.authenticationFlowBindingOverrides["browser"] === flow.id)
|
|
|
|
);
|
2022-05-02 14:51:05 +00:00
|
|
|
if (clients.length > 0) {
|
2021-08-09 08:47:34 +00:00
|
|
|
flow.usedBy.type = "specificClients";
|
2022-05-02 14:51:05 +00:00
|
|
|
flow.usedBy.values = clients.map(({ clientId }) => clientId!);
|
2021-01-26 19:39:01 +00:00
|
|
|
}
|
|
|
|
|
2022-05-02 14:51:05 +00:00
|
|
|
const idps = allIdps.filter(
|
2021-01-26 19:39:01 +00:00
|
|
|
(idp) =>
|
|
|
|
idp.firstBrokerLoginFlowAlias === flow.alias ||
|
|
|
|
idp.postBrokerLoginFlowAlias === flow.alias
|
|
|
|
);
|
2022-05-02 14:51:05 +00:00
|
|
|
if (idps.length > 0) {
|
2021-08-09 08:47:34 +00:00
|
|
|
flow.usedBy.type = "specificProviders";
|
2022-05-02 14:51:05 +00:00
|
|
|
flow.usedBy.values = idps.map(({ alias }) => alias!);
|
2021-01-26 19:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const isDefault = defaultFlows.includes(flow.alias);
|
|
|
|
if (isDefault) {
|
|
|
|
flow.usedBy.type = "default";
|
2022-05-02 14:51:05 +00:00
|
|
|
flow.usedBy.values.push(flow.alias!);
|
2021-01-26 19:39:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:36:52 +00:00
|
|
|
return sortBy(flows as AuthenticationType[], (flow) => flow.usedBy.type);
|
2021-01-26 19:39:01 +00:00
|
|
|
};
|
2022-03-07 17:36:52 +00:00
|
|
|
|
2021-01-26 19:39:01 +00:00
|
|
|
const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({
|
|
|
|
titleKey: "authentication:deleteConfirmFlow",
|
|
|
|
children: (
|
|
|
|
<Trans i18nKey="authentication:deleteConfirmFlowMessage">
|
|
|
|
{" "}
|
|
|
|
<strong>{{ flow: selectedFlow ? selectedFlow.alias : "" }}</strong>.
|
|
|
|
</Trans>
|
|
|
|
),
|
|
|
|
continueButtonLabel: "common:delete",
|
|
|
|
continueButtonVariant: ButtonVariant.danger,
|
|
|
|
onConfirm: async () => {
|
|
|
|
try {
|
|
|
|
await adminClient.authenticationManagement.deleteFlow({
|
|
|
|
flowId: selectedFlow!.id!,
|
|
|
|
});
|
|
|
|
refresh();
|
|
|
|
addAlert(t("deleteFlowSuccess"), AlertVariant.success);
|
|
|
|
} catch (error) {
|
2021-07-28 12:01:42 +00:00
|
|
|
addError("authentication:deleteFlowError", error);
|
2021-01-26 19:39:01 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-05-02 14:51:05 +00:00
|
|
|
const UsedByRenderer = (authType: AuthenticationType) => (
|
|
|
|
<UsedBy authType={authType} />
|
2021-01-26 19:39:01 +00:00
|
|
|
);
|
|
|
|
|
2021-08-09 08:47:34 +00:00
|
|
|
const AliasRenderer = ({
|
|
|
|
id,
|
|
|
|
alias,
|
|
|
|
usedBy,
|
|
|
|
builtIn,
|
|
|
|
}: AuthenticationType) => (
|
2021-01-26 19:39:01 +00:00
|
|
|
<>
|
2021-08-09 08:47:34 +00:00
|
|
|
<Link
|
|
|
|
to={toFlow({
|
|
|
|
realm,
|
|
|
|
id: id!,
|
|
|
|
usedBy: usedBy.type || "notInUse",
|
|
|
|
builtIn: builtIn ? "builtIn" : undefined,
|
|
|
|
})}
|
|
|
|
key={`link-${id}`}
|
|
|
|
>
|
2021-01-26 19:39:01 +00:00
|
|
|
{toUpperCase(alias!)}
|
|
|
|
</Link>{" "}
|
|
|
|
{builtIn && <Label key={`label-${id}`}>{t("buildIn")}</Label>}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DeleteConfirm />
|
|
|
|
{open && (
|
|
|
|
<DuplicateFlowModal
|
|
|
|
name={selectedFlow ? selectedFlow.alias! : ""}
|
|
|
|
description={selectedFlow?.description!}
|
2021-11-30 13:07:44 +00:00
|
|
|
toggleDialog={toggleOpen}
|
2021-01-26 19:39:01 +00:00
|
|
|
onComplete={() => {
|
|
|
|
refresh();
|
2022-03-07 17:36:52 +00:00
|
|
|
toggleOpen();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{bindFlowOpen && (
|
|
|
|
<BindFlowDialog
|
|
|
|
onClose={() => {
|
|
|
|
toggleBindFlow();
|
|
|
|
refresh();
|
2021-01-26 19:39:01 +00:00
|
|
|
}}
|
2022-03-07 17:36:52 +00:00
|
|
|
flowAlias={selectedFlow?.alias!}
|
2021-01-26 19:39:01 +00:00
|
|
|
/>
|
|
|
|
)}
|
2021-12-21 15:32:53 +00:00
|
|
|
<ViewHeader
|
|
|
|
titleKey="authentication:title"
|
|
|
|
subKey="authentication:authenticationExplain"
|
|
|
|
helpUrl={helpUrls.authenticationUrl}
|
|
|
|
divider={false}
|
|
|
|
/>
|
2021-03-31 13:16:58 +00:00
|
|
|
<PageSection variant="light" className="pf-u-p-0">
|
2021-01-26 19:39:01 +00:00
|
|
|
<KeycloakTabs isBox>
|
|
|
|
<Tab
|
|
|
|
eventKey="flows"
|
|
|
|
title={<TabTitleText>{t("flows")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<KeycloakDataTable
|
|
|
|
key={key}
|
|
|
|
loader={loader}
|
|
|
|
ariaLabelKey="authentication:title"
|
2021-10-14 14:54:07 +00:00
|
|
|
searchPlaceholderKey="authentication:searchForFlow"
|
2021-08-09 08:47:34 +00:00
|
|
|
toolbarItem={
|
|
|
|
<ToolbarItem>
|
|
|
|
<Button
|
2021-10-01 10:52:45 +00:00
|
|
|
component={(props) => (
|
|
|
|
<Link {...props} to={toCreateFlow({ realm })} />
|
|
|
|
)}
|
2021-08-09 08:47:34 +00:00
|
|
|
>
|
|
|
|
{t("createFlow")}
|
|
|
|
</Button>
|
|
|
|
</ToolbarItem>
|
|
|
|
}
|
2021-01-26 19:39:01 +00:00
|
|
|
actionResolver={({ data }) => {
|
|
|
|
const defaultActions = [
|
|
|
|
{
|
|
|
|
title: t("duplicate"),
|
|
|
|
onClick: () => {
|
2022-03-07 17:36:52 +00:00
|
|
|
toggleOpen();
|
2021-01-26 19:39:01 +00:00
|
|
|
setSelectedFlow(data);
|
|
|
|
},
|
|
|
|
},
|
2022-03-07 17:36:52 +00:00
|
|
|
...(data.providerId !== "client-flow"
|
|
|
|
? [
|
|
|
|
{
|
|
|
|
title: t("bindFlow"),
|
|
|
|
onClick: () => {
|
|
|
|
toggleBindFlow();
|
|
|
|
setSelectedFlow(data);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: []),
|
2021-01-26 19:39:01 +00:00
|
|
|
];
|
|
|
|
// remove delete when it's in use or default flow
|
|
|
|
if (data.builtIn || data.usedBy.values.length > 0) {
|
|
|
|
return defaultActions;
|
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
title: t("common:delete"),
|
|
|
|
onClick: () => {
|
|
|
|
setSelectedFlow(data);
|
|
|
|
toggleDeleteDialog();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...defaultActions,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
name: "alias",
|
|
|
|
displayKey: "authentication:flowName",
|
|
|
|
cellRenderer: AliasRenderer,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "usedBy",
|
|
|
|
displayKey: "authentication:usedBy",
|
2022-05-02 14:51:05 +00:00
|
|
|
cellRenderer: UsedByRenderer,
|
2021-01-26 19:39:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "description",
|
|
|
|
displayKey: "common:description",
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
emptyState={
|
|
|
|
<ListEmptyState
|
|
|
|
message={t("emptyEvents")}
|
|
|
|
instructions={t("emptyEventsInstructions")}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Tab>
|
2021-10-19 15:30:57 +00:00
|
|
|
<Tab
|
|
|
|
id="requiredActions"
|
|
|
|
eventKey="requiredActions"
|
|
|
|
title={<TabTitleText>{t("requiredActions")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<RequiredActions />
|
|
|
|
</Tab>
|
2021-12-01 09:24:46 +00:00
|
|
|
<Tab
|
|
|
|
id="policies"
|
|
|
|
eventKey="policies"
|
|
|
|
title={<TabTitleText>{t("policies")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<Policies />
|
|
|
|
</Tab>
|
2021-01-26 19:39:01 +00:00
|
|
|
</KeycloakTabs>
|
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
2021-10-29 16:11:06 +00:00
|
|
|
}
|