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";
|
2021-01-11 18:56:19 +00:00
|
|
|
import { useAdminClient, asyncStateFetch } 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-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();
|
2021-01-05 13:39:27 +00:00
|
|
|
const [key, setKey] = useState(0);
|
|
|
|
const refresh = () => setKey(new Date().getTime());
|
2020-11-10 20:26:20 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2021-01-11 18:56:19 +00:00
|
|
|
return asyncStateFetch(
|
2021-01-05 13:39:27 +00:00
|
|
|
() => {
|
|
|
|
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
|
|
|
|
};
|
|
|
|
return adminClient.components.find(testParams);
|
|
|
|
},
|
|
|
|
(userFederations) => {
|
|
|
|
setUserFederations(userFederations);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}, [key]);
|
2020-11-10 20:26:20 +00:00
|
|
|
|
|
|
|
const ufAddProviderDropdownItems = [
|
|
|
|
<DropdownItem key="itemLDAP">LDAP</DropdownItem>,
|
|
|
|
<DropdownItem key="itemKerberos">Kerberos</DropdownItem>,
|
|
|
|
];
|
|
|
|
|
|
|
|
const learnMoreLinkProps = {
|
2021-01-05 13:39:27 +00:00
|
|
|
title: t("common:learnMore"),
|
2020-11-10 20:26:20 +00:00
|
|
|
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 });
|
2021-01-05 13:39:27 +00:00
|
|
|
refresh();
|
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 (
|
2020-11-18 15:06:56 +00:00
|
|
|
<GalleryItem
|
|
|
|
key={index}
|
|
|
|
className="keycloak-admin--user-federation__gallery-item"
|
|
|
|
>
|
2020-11-10 20:26:20 +00:00
|
|
|
<KeycloakCard
|
2020-11-12 12:55:52 +00:00
|
|
|
id={userFederation.id!}
|
2020-11-10 20:26:20 +00:00
|
|
|
dropdownItems={ufCardDropdownItems}
|
2020-12-16 07:02:41 +00:00
|
|
|
providerId={userFederation.providerId!}
|
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-24 20:45:12 +00:00
|
|
|
userFederation.config!["enabled"][0] !== "false"
|
2020-11-10 20:26:20 +00:00
|
|
|
? `${t("common:enabled")}`
|
|
|
|
: `${t("common:disabled")}`
|
|
|
|
}
|
2020-11-16 19:09:39 +00:00
|
|
|
labelColor={
|
2020-11-24 20:45:12 +00:00
|
|
|
userFederation.config!["enabled"][0] !== "false" ? "blue" : "gray"
|
2020-11-16 19:09:39 +00:00
|
|
|
}
|
2020-11-10 20:26:20 +00:00
|
|
|
/>
|
|
|
|
</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
|
|
|
|
? {
|
2020-11-16 19:09:39 +00:00
|
|
|
lowerDropdownItems: ufAddProviderDropdownItems,
|
2020-11-10 20:26:20 +00:00
|
|
|
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
|
|
|
};
|