2020-11-10 20:26:20 +00:00
|
|
|
import React, { useContext, useEffect, useState } from "react";
|
2020-10-15 05:50:47 +00:00
|
|
|
import {
|
2020-11-10 20:26:20 +00:00
|
|
|
AlertVariant,
|
|
|
|
ButtonVariant,
|
2020-10-15 05:50:47 +00:00
|
|
|
Card,
|
|
|
|
CardTitle,
|
2020-11-10 20:26:20 +00:00
|
|
|
DropdownItem,
|
2020-10-15 05:50:47 +00:00
|
|
|
Gallery,
|
2020-11-10 20:26:20 +00:00
|
|
|
GalleryItem,
|
2020-10-15 05:50:47 +00:00
|
|
|
PageSection,
|
|
|
|
Split,
|
|
|
|
SplitItem,
|
|
|
|
Text,
|
|
|
|
TextContent,
|
|
|
|
TextVariants,
|
|
|
|
} from "@patternfly/react-core";
|
2020-11-10 20:26:20 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
import ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation";
|
2020-11-10 20:26:20 +00:00
|
|
|
import { KeycloakCard } from "../components/keycloak-card/KeycloakCard";
|
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
2020-10-15 05:50:47 +00:00
|
|
|
import { DatabaseIcon } from "@patternfly/react-icons";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2020-11-10 20:26:20 +00:00
|
|
|
import { RealmContext } from "../context/realm-context/RealmContext";
|
2020-11-12 12:55:52 +00:00
|
|
|
import { useAdminClient } from "../context/auth/AdminClient";
|
2020-11-10 20:26:20 +00:00
|
|
|
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
|
|
|
|
import "./user-federation.css";
|
2020-09-09 09:07:17 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
type Config = {
|
|
|
|
enabled: string[];
|
|
|
|
};
|
|
|
|
|
2020-09-10 18:04:03 +00:00
|
|
|
export const UserFederationSection = () => {
|
2020-11-10 20:26:20 +00:00
|
|
|
const [userFederations, setUserFederations] = useState<
|
2020-11-12 12:55:52 +00:00
|
|
|
ComponentRepresentation[]
|
2020-11-10 20:26:20 +00:00
|
|
|
>();
|
|
|
|
const { addAlert } = useAlerts();
|
2020-11-12 12:55:52 +00:00
|
|
|
const { t } = useTranslation("user-federation");
|
|
|
|
const { realm } = useContext(RealmContext);
|
|
|
|
const adminClient = useAdminClient();
|
2020-11-10 20:26:20 +00:00
|
|
|
|
|
|
|
const loader = async () => {
|
|
|
|
const testParams: { [name: string]: string | number } = {
|
|
|
|
parentId: realm,
|
|
|
|
type: "org.keycloak.storage.UserStorageProvider", // MF note that this is providerType in the output, but API call is still type
|
|
|
|
};
|
2020-11-12 12:55:52 +00:00
|
|
|
const userFederations = await adminClient.components.find(testParams);
|
|
|
|
setUserFederations(userFederations);
|
2020-11-10 20:26:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
loader();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const ufAddProviderDropdownItems = [
|
|
|
|
<DropdownItem key="itemLDAP">LDAP</DropdownItem>,
|
|
|
|
<DropdownItem key="itemKerberos">Kerberos</DropdownItem>,
|
|
|
|
];
|
|
|
|
|
|
|
|
const learnMoreLinkProps = {
|
|
|
|
title: `${t("common:learnMore")}`,
|
|
|
|
href:
|
|
|
|
"https://www.keycloak.org/docs/latest/server_admin/index.html#_user-storage-federation",
|
2020-10-15 05:50:47 +00:00
|
|
|
};
|
|
|
|
|
2020-11-10 20:26:20 +00:00
|
|
|
let cards;
|
|
|
|
|
|
|
|
const [currentCard, setCurrentCard] = useState("");
|
|
|
|
const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({
|
|
|
|
titleKey: t("userFedDeleteConfirmTitle"),
|
|
|
|
messageKey: t("userFedDeleteConfirm"),
|
|
|
|
continueButtonLabel: "common:delete",
|
|
|
|
continueButtonVariant: ButtonVariant.danger,
|
|
|
|
onConfirm: async () => {
|
|
|
|
try {
|
2020-11-12 12:55:52 +00:00
|
|
|
await adminClient.components.del({ id: currentCard });
|
|
|
|
await loader();
|
2020-11-10 20:26:20 +00:00
|
|
|
addAlert(t("userFedDeletedSuccess"), AlertVariant.success);
|
|
|
|
} catch (error) {
|
|
|
|
addAlert(t("userFedDeleteError", { error }), AlertVariant.danger);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const toggleDeleteForCard = (id: string) => {
|
|
|
|
setCurrentCard(id);
|
|
|
|
toggleDeleteDialog();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (userFederations) {
|
|
|
|
cards = userFederations.map((userFederation, index) => {
|
|
|
|
const ufCardDropdownItems = [
|
|
|
|
<DropdownItem
|
|
|
|
key={`${index}-cardDelete`}
|
|
|
|
onClick={() => {
|
2020-11-12 12:55:52 +00:00
|
|
|
toggleDeleteForCard(userFederation.id!);
|
2020-11-10 20:26:20 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t("common:delete")}
|
|
|
|
</DropdownItem>,
|
|
|
|
];
|
|
|
|
return (
|
|
|
|
<GalleryItem key={index}>
|
|
|
|
<KeycloakCard
|
2020-11-12 12:55:52 +00:00
|
|
|
id={userFederation.id!}
|
2020-11-10 20:26:20 +00:00
|
|
|
dropdownItems={ufCardDropdownItems}
|
2020-11-12 12:55:52 +00:00
|
|
|
title={userFederation.name!}
|
2020-11-10 20:26:20 +00:00
|
|
|
footerText={
|
|
|
|
userFederation.providerId === "ldap" ? "LDAP" : "Kerberos"
|
|
|
|
}
|
|
|
|
labelText={
|
2020-11-12 12:55:52 +00:00
|
|
|
(userFederation.config as Config)!.enabled[0] !== "false"
|
2020-11-10 20:26:20 +00:00
|
|
|
? `${t("common:enabled")}`
|
|
|
|
: `${t("common:disabled")}`
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</GalleryItem>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-15 05:50:47 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ViewHeader
|
2020-11-10 20:26:20 +00:00
|
|
|
titleKey="userFederation"
|
|
|
|
subKey="user-federation:userFederationExplanation"
|
|
|
|
subKeyLinkProps={learnMoreLinkProps}
|
|
|
|
{...(userFederations && userFederations.length > 0
|
|
|
|
? {
|
|
|
|
lowerDropdownItems: { ufAddProviderDropdownItems },
|
|
|
|
lowerDropdownMenuTitle: "user-federation:addNewProvider",
|
|
|
|
}
|
|
|
|
: {})}
|
2020-10-15 05:50:47 +00:00
|
|
|
/>
|
|
|
|
<PageSection>
|
2020-11-10 20:26:20 +00:00
|
|
|
{userFederations && userFederations.length > 0 ? (
|
|
|
|
<>
|
|
|
|
<DeleteConfirm />
|
|
|
|
<Gallery hasGutter>{cards}</Gallery>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<TextContent>
|
|
|
|
<Text component={TextVariants.p}>{t("getStarted")}</Text>
|
|
|
|
</TextContent>
|
|
|
|
<TextContent>
|
|
|
|
<Text className="pf-u-mt-lg" component={TextVariants.h2}>
|
|
|
|
{t("providers")}
|
|
|
|
</Text>
|
|
|
|
</TextContent>
|
|
|
|
<hr className="pf-u-mb-lg" />
|
|
|
|
<Gallery hasGutter>
|
|
|
|
<Card isHoverable>
|
|
|
|
<CardTitle>
|
|
|
|
<Split hasGutter>
|
|
|
|
<SplitItem>
|
|
|
|
<DatabaseIcon size="lg" />
|
|
|
|
</SplitItem>
|
|
|
|
<SplitItem isFilled>{t("addKerberos")}</SplitItem>
|
|
|
|
</Split>
|
|
|
|
</CardTitle>
|
|
|
|
</Card>
|
|
|
|
<Card isHoverable>
|
|
|
|
<CardTitle>
|
|
|
|
<Split hasGutter>
|
|
|
|
<SplitItem>
|
|
|
|
<DatabaseIcon size="lg" />
|
|
|
|
</SplitItem>
|
|
|
|
<SplitItem isFilled>{t("addLdap")}</SplitItem>
|
|
|
|
</Split>
|
|
|
|
</CardTitle>
|
|
|
|
</Card>
|
|
|
|
</Gallery>
|
|
|
|
</>
|
|
|
|
)}
|
2020-10-15 05:50:47 +00:00
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
2020-09-09 09:07:17 +00:00
|
|
|
};
|