2022-01-23 20:21:19 +00:00
|
|
|
import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
|
2022-03-11 10:19:20 +00:00
|
|
|
import React, { useState, KeyboardEvent, useMemo, useRef } from "react";
|
2022-01-23 20:21:19 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectVariant,
|
|
|
|
SelectOption,
|
|
|
|
PageSection,
|
|
|
|
ActionGroup,
|
|
|
|
Button,
|
|
|
|
Switch,
|
|
|
|
ExpandableSection,
|
|
|
|
TextInput,
|
2022-02-17 16:03:18 +00:00
|
|
|
ButtonVariant,
|
|
|
|
InputGroup,
|
|
|
|
Toolbar,
|
|
|
|
ToolbarGroup,
|
|
|
|
ToolbarItem,
|
2022-03-11 10:19:20 +00:00
|
|
|
Divider,
|
2022-01-23 20:21:19 +00:00
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
|
|
|
|
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
|
|
|
import { FormPanel } from "../../components/scroll-form/FormPanel";
|
|
|
|
import type UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation";
|
|
|
|
import type RoleRepresentation from "@keycloak/keycloak-admin-client/lib/defs/roleRepresentation";
|
|
|
|
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
|
|
|
|
import type ResourceEvaluation from "@keycloak/keycloak-admin-client/lib/defs/resourceEvaluation";
|
|
|
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
2022-03-16 09:39:58 +00:00
|
|
|
import { KeyBasedAttributeInput } from "./KeyBasedAttributeInput";
|
2022-01-23 20:21:19 +00:00
|
|
|
import { defaultContextAttributes } from "../utils";
|
2022-02-17 16:03:18 +00:00
|
|
|
import type EvaluationResultRepresentation from "@keycloak/keycloak-admin-client/lib/defs/evaluationResultRepresentation";
|
2022-01-23 20:21:19 +00:00
|
|
|
import type ResourceRepresentation from "@keycloak/keycloak-admin-client/lib/defs/resourceRepresentation";
|
|
|
|
import type ScopeRepresentation from "@keycloak/keycloak-admin-client/lib/defs/scopeRepresentation";
|
2022-04-20 17:11:46 +00:00
|
|
|
import type { KeyValueType } from "../../components/key-value-form/key-value-convert";
|
2022-02-17 16:03:18 +00:00
|
|
|
import { TableComposable, Th, Thead, Tr } from "@patternfly/react-table";
|
|
|
|
import "./auth-evaluate.css";
|
|
|
|
import { AuthorizationEvaluateResource } from "./AuthorizationEvaluateResource";
|
|
|
|
import { SearchIcon } from "@patternfly/react-icons";
|
|
|
|
import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState";
|
2022-04-21 15:03:26 +00:00
|
|
|
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
|
2022-06-13 09:09:07 +00:00
|
|
|
import { useAccess } from "../../context/access/Access";
|
|
|
|
import { ForbiddenSection } from "../../ForbiddenSection";
|
2022-02-15 17:52:46 +00:00
|
|
|
|
|
|
|
interface EvaluateFormInputs
|
|
|
|
extends Omit<ResourceEvaluation, "context" | "resources"> {
|
|
|
|
alias: string;
|
|
|
|
authScopes: string[];
|
|
|
|
context: {
|
|
|
|
attributes: Record<string, string>[];
|
|
|
|
};
|
|
|
|
resources: Record<string, string>[];
|
2022-03-07 14:28:42 +00:00
|
|
|
client: ClientRepresentation;
|
|
|
|
user: UserRepresentation;
|
2022-02-15 17:52:46 +00:00
|
|
|
}
|
2022-01-23 20:21:19 +00:00
|
|
|
|
|
|
|
export type AttributeType = {
|
|
|
|
key: string;
|
|
|
|
name: string;
|
|
|
|
custom?: boolean;
|
|
|
|
values?: {
|
|
|
|
[key: string]: string;
|
|
|
|
}[];
|
|
|
|
};
|
|
|
|
|
|
|
|
type ClientSettingsProps = {
|
2022-03-07 14:28:42 +00:00
|
|
|
client: ClientRepresentation;
|
2022-01-23 20:21:19 +00:00
|
|
|
save: () => void;
|
|
|
|
};
|
|
|
|
|
2022-02-15 17:52:46 +00:00
|
|
|
export type AttributeForm = Omit<
|
|
|
|
EvaluateFormInputs,
|
|
|
|
"context" | "resources"
|
|
|
|
> & {
|
|
|
|
context: {
|
|
|
|
attributes?: KeyValueType[];
|
|
|
|
};
|
|
|
|
resources?: KeyValueType[];
|
|
|
|
};
|
|
|
|
|
2022-02-17 16:03:18 +00:00
|
|
|
type Props = ClientSettingsProps & EvaluationResultRepresentation;
|
|
|
|
|
2022-03-11 10:19:20 +00:00
|
|
|
enum ResultsFilter {
|
|
|
|
All = "ALL",
|
|
|
|
StatusDenied = "STATUS_DENIED",
|
|
|
|
StatusPermitted = "STATUS_PERMITTED",
|
|
|
|
}
|
|
|
|
|
|
|
|
function filterResults(
|
|
|
|
results: EvaluationResultRepresentation[],
|
|
|
|
filter: ResultsFilter
|
|
|
|
) {
|
|
|
|
switch (filter) {
|
|
|
|
case ResultsFilter.StatusPermitted:
|
|
|
|
return results.filter(({ status }) => status === "PERMIT");
|
|
|
|
case ResultsFilter.StatusDenied:
|
|
|
|
return results.filter(({ status }) => status === "DENY");
|
|
|
|
default:
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 14:28:42 +00:00
|
|
|
export const AuthorizationEvaluate = ({ client }: Props) => {
|
2022-02-15 17:52:46 +00:00
|
|
|
const form = useFormContext<EvaluateFormInputs>();
|
|
|
|
const { control, reset, trigger } = form;
|
2022-01-23 20:21:19 +00:00
|
|
|
const { t } = useTranslation("clients");
|
|
|
|
const adminClient = useAdminClient();
|
|
|
|
const realm = useRealm();
|
|
|
|
|
|
|
|
const [clientsDropdownOpen, setClientsDropdownOpen] = useState(false);
|
|
|
|
const [scopesDropdownOpen, setScopesDropdownOpen] = useState(false);
|
|
|
|
|
|
|
|
const [userDropdownOpen, setUserDropdownOpen] = useState(false);
|
|
|
|
const [roleDropdownOpen, setRoleDropdownOpen] = useState(false);
|
|
|
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
|
|
const [applyToResourceType, setApplyToResourceType] = useState(false);
|
|
|
|
const [resources, setResources] = useState<ResourceRepresentation[]>([]);
|
|
|
|
const [scopes, setScopes] = useState<ScopeRepresentation[]>([]);
|
2022-02-17 16:03:18 +00:00
|
|
|
const [evaluateResults, setEvaluateResults] = useState<
|
|
|
|
EvaluationResultRepresentation[]
|
|
|
|
>([]);
|
|
|
|
const [showEvaluateResults, setShowEvaluateResults] = useState(false);
|
2022-03-11 10:19:20 +00:00
|
|
|
const searchQueryRef = useRef("");
|
|
|
|
const [searchQuery, setSearchQuery] = useState("");
|
2022-02-17 16:03:18 +00:00
|
|
|
const [filterDropdownOpen, setFilterDropdownOpen] = useState(false);
|
|
|
|
const [key, setKey] = useState(0);
|
|
|
|
|
|
|
|
const refresh = () => {
|
2022-03-07 14:28:42 +00:00
|
|
|
setKey(key + 1);
|
2022-02-17 16:03:18 +00:00
|
|
|
};
|
|
|
|
|
2022-03-11 10:19:20 +00:00
|
|
|
const [filter, setFilter] = useState(ResultsFilter.All);
|
2022-01-23 20:21:19 +00:00
|
|
|
|
2022-03-07 14:28:42 +00:00
|
|
|
const [clients, setClients] = useState<ClientRepresentation[]>([]);
|
|
|
|
const [clientRoles, setClientRoles] = useState<RoleRepresentation[]>([]);
|
|
|
|
const [users, setUsers] = useState<UserRepresentation[]>([]);
|
|
|
|
|
2022-03-11 10:19:20 +00:00
|
|
|
const filteredResources = useMemo(
|
|
|
|
() =>
|
|
|
|
filterResults(evaluateResults, filter).filter(
|
|
|
|
({ resource }) => resource?.name?.includes(searchQuery) ?? false
|
|
|
|
),
|
|
|
|
[evaluateResults, filter, searchQuery]
|
|
|
|
);
|
|
|
|
|
2022-06-13 09:09:07 +00:00
|
|
|
const { hasAccess } = useAccess();
|
|
|
|
if (!hasAccess("view-users"))
|
|
|
|
return <ForbiddenSection permissionNeeded="view-users" />;
|
|
|
|
|
2022-03-07 14:28:42 +00:00
|
|
|
useFetch(
|
|
|
|
() =>
|
|
|
|
Promise.all([
|
|
|
|
adminClient.clients.find(),
|
|
|
|
adminClient.roles.find(),
|
|
|
|
adminClient.users.find(),
|
|
|
|
]),
|
|
|
|
([clients, roles, users]) => {
|
|
|
|
setClients(clients);
|
|
|
|
setClientRoles(roles);
|
|
|
|
setUsers(users);
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
2022-01-23 20:21:19 +00:00
|
|
|
useFetch(
|
2022-03-11 10:19:20 +00:00
|
|
|
() =>
|
2022-01-23 20:21:19 +00:00
|
|
|
Promise.all([
|
|
|
|
adminClient.clients.listResources({
|
2022-03-07 14:28:42 +00:00
|
|
|
id: client.id!,
|
2022-01-23 20:21:19 +00:00
|
|
|
}),
|
|
|
|
adminClient.clients.listAllScopes({
|
2022-03-07 14:28:42 +00:00
|
|
|
id: client.id!,
|
2022-01-23 20:21:19 +00:00
|
|
|
}),
|
|
|
|
]),
|
|
|
|
([resources, scopes]) => {
|
|
|
|
setResources(resources);
|
|
|
|
setScopes(scopes);
|
|
|
|
},
|
2022-03-11 10:19:20 +00:00
|
|
|
[key, filter]
|
2022-01-23 20:21:19 +00:00
|
|
|
);
|
|
|
|
|
2022-02-15 17:52:46 +00:00
|
|
|
const evaluate = async () => {
|
|
|
|
if (!(await trigger())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const formValues = form.getValues();
|
|
|
|
const keys = formValues.resources.map(({ key }) => key);
|
2022-01-23 20:21:19 +00:00
|
|
|
const resEval: ResourceEvaluation = {
|
|
|
|
roleIds: formValues.roleIds ?? [],
|
2022-03-07 14:28:42 +00:00
|
|
|
clientId: formValues.client.id!,
|
|
|
|
userId: formValues.user.id!,
|
2022-03-18 13:28:31 +00:00
|
|
|
resources: formValues.resources.filter((resource) =>
|
|
|
|
keys.includes(resource.name!)
|
|
|
|
),
|
2022-01-23 20:21:19 +00:00
|
|
|
entitlements: false,
|
2022-02-15 17:52:46 +00:00
|
|
|
context: {
|
|
|
|
attributes: Object.fromEntries(
|
|
|
|
formValues.context.attributes
|
|
|
|
.filter((item) => item.key || item.value !== "")
|
|
|
|
.map(({ key, value }) => [key, value])
|
|
|
|
),
|
|
|
|
},
|
2022-01-23 20:21:19 +00:00
|
|
|
};
|
2022-02-15 17:52:46 +00:00
|
|
|
|
2022-02-17 16:03:18 +00:00
|
|
|
const evaluation = await adminClient.clients.evaluateResource(
|
2022-03-07 14:28:42 +00:00
|
|
|
{ id: client.id!, realm: realm.realm },
|
2022-01-23 20:21:19 +00:00
|
|
|
resEval
|
|
|
|
);
|
2022-02-17 16:03:18 +00:00
|
|
|
|
|
|
|
setEvaluateResults(evaluation.results);
|
|
|
|
setShowEvaluateResults(true);
|
|
|
|
return evaluateResults;
|
|
|
|
};
|
|
|
|
|
2022-03-11 10:19:20 +00:00
|
|
|
const confirmSearchQuery = () => {
|
|
|
|
setSearchQuery(searchQueryRef.current);
|
2022-02-17 16:03:18 +00:00
|
|
|
};
|
|
|
|
|
2022-02-28 15:22:00 +00:00
|
|
|
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
2022-02-17 16:03:18 +00:00
|
|
|
if (e.key === "Enter") {
|
2022-03-11 10:19:20 +00:00
|
|
|
confirmSearchQuery();
|
2022-02-17 16:03:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleInputChange = (value: string) => {
|
2022-03-11 10:19:20 +00:00
|
|
|
searchQueryRef.current = value;
|
2022-01-23 20:21:19 +00:00
|
|
|
};
|
|
|
|
|
2022-02-17 16:03:18 +00:00
|
|
|
const noEvaluatedData = evaluateResults.length === 0;
|
|
|
|
const noFilteredData = filteredResources.length === 0;
|
|
|
|
|
|
|
|
return showEvaluateResults ? (
|
|
|
|
<PageSection>
|
|
|
|
<Toolbar>
|
|
|
|
<ToolbarGroup className="providers-toolbar">
|
|
|
|
<ToolbarItem>
|
|
|
|
<InputGroup>
|
|
|
|
<TextInput
|
|
|
|
name={"inputGroupName"}
|
|
|
|
id={"inputGroupName"}
|
|
|
|
type="search"
|
|
|
|
aria-label={t("common:search")}
|
|
|
|
placeholder={t("common:search")}
|
|
|
|
onChange={handleInputChange}
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
variant={ButtonVariant.control}
|
|
|
|
aria-label={t("common:search")}
|
2022-03-11 10:19:20 +00:00
|
|
|
onClick={() => confirmSearchQuery()}
|
2022-02-17 16:03:18 +00:00
|
|
|
>
|
|
|
|
<SearchIcon />
|
|
|
|
</Button>
|
|
|
|
</InputGroup>
|
|
|
|
</ToolbarItem>
|
|
|
|
<ToolbarItem>
|
|
|
|
<Select
|
|
|
|
width={300}
|
|
|
|
data-testid="filter-type-select"
|
|
|
|
isOpen={filterDropdownOpen}
|
|
|
|
className="kc-filter-type-select"
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
onToggle={() => setFilterDropdownOpen(!filterDropdownOpen)}
|
|
|
|
onSelect={(_, value) => {
|
2022-03-11 10:19:20 +00:00
|
|
|
setFilter(value as ResultsFilter);
|
2022-02-17 16:03:18 +00:00
|
|
|
setFilterDropdownOpen(false);
|
2022-03-11 10:19:20 +00:00
|
|
|
refresh();
|
2022-02-17 16:03:18 +00:00
|
|
|
}}
|
2022-03-11 10:19:20 +00:00
|
|
|
selections={filter}
|
2022-02-17 16:03:18 +00:00
|
|
|
>
|
2022-03-11 10:19:20 +00:00
|
|
|
<SelectOption
|
|
|
|
data-testid="all-results-option"
|
|
|
|
value={ResultsFilter.All}
|
|
|
|
isPlaceholder
|
|
|
|
>
|
|
|
|
{t("allResults")}
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption
|
|
|
|
data-testid="result-permit-option"
|
|
|
|
value={ResultsFilter.StatusPermitted}
|
|
|
|
>
|
|
|
|
{t("resultPermit")}
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption
|
|
|
|
data-testid="result-deny-option"
|
|
|
|
value={ResultsFilter.StatusDenied}
|
|
|
|
>
|
|
|
|
{t("resultDeny")}
|
|
|
|
</SelectOption>
|
2022-02-17 16:03:18 +00:00
|
|
|
</Select>
|
|
|
|
</ToolbarItem>
|
|
|
|
</ToolbarGroup>
|
|
|
|
</Toolbar>
|
2022-03-11 10:19:20 +00:00
|
|
|
{!noFilteredData && (
|
2022-02-17 16:03:18 +00:00
|
|
|
<TableComposable aria-label={t("evaluationResults")}>
|
|
|
|
<Thead>
|
|
|
|
<Tr>
|
|
|
|
<Th />
|
|
|
|
<Th>{t("resource")}</Th>
|
|
|
|
<Th>{t("overallResults")}</Th>
|
|
|
|
<Th>{t("scopes")}</Th>
|
|
|
|
<Th />
|
|
|
|
</Tr>
|
|
|
|
</Thead>
|
2022-03-11 10:19:20 +00:00
|
|
|
{filteredResources.map((resource, rowIndex) => (
|
2022-02-17 16:03:18 +00:00
|
|
|
<AuthorizationEvaluateResource
|
|
|
|
key={rowIndex}
|
|
|
|
rowIndex={rowIndex}
|
|
|
|
resource={resource}
|
|
|
|
evaluateResults={evaluateResults}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</TableComposable>
|
|
|
|
)}
|
2022-03-11 10:19:20 +00:00
|
|
|
{(noFilteredData || noEvaluatedData) && (
|
|
|
|
<>
|
|
|
|
<Divider />
|
2022-02-17 16:03:18 +00:00
|
|
|
<ListEmptyState
|
|
|
|
isSearchVariant
|
|
|
|
message={t("common:noSearchResults")}
|
|
|
|
instructions={t("common:noSearchResultsInstructions")}
|
|
|
|
/>
|
2022-03-11 10:19:20 +00:00
|
|
|
</>
|
|
|
|
)}
|
2022-02-17 16:03:18 +00:00
|
|
|
<ActionGroup className="kc-evaluated-options">
|
|
|
|
<Button
|
|
|
|
data-testid="authorization-eval"
|
|
|
|
id="back-btn"
|
|
|
|
onClick={() => setShowEvaluateResults(false)}
|
|
|
|
>
|
|
|
|
{t("common:back")}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
data-testid="authorization-reevaluate"
|
|
|
|
id="reevaluate-btn"
|
|
|
|
variant="secondary"
|
|
|
|
onClick={() => evaluate()}
|
|
|
|
>
|
|
|
|
{t("clients:reevaluate")}
|
|
|
|
</Button>
|
|
|
|
<Button data-testid="authorization-revert" variant="secondary">
|
|
|
|
{t("showAuthData")}
|
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
</PageSection>
|
|
|
|
) : (
|
2022-01-23 20:21:19 +00:00
|
|
|
<PageSection>
|
|
|
|
<FormPanel
|
|
|
|
className="kc-identity-information"
|
|
|
|
title={t("clients:identityInformation")}
|
|
|
|
>
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
2022-05-30 09:23:24 +00:00
|
|
|
role="view-clients"
|
2022-01-23 20:21:19 +00:00
|
|
|
onSubmit={form.handleSubmit(evaluate)}
|
|
|
|
>
|
|
|
|
<FormGroup
|
|
|
|
label={t("client")}
|
|
|
|
isRequired
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:client"
|
|
|
|
fieldLabelId="clients:client"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="client"
|
|
|
|
>
|
|
|
|
<Controller
|
2022-03-07 14:28:42 +00:00
|
|
|
name="client"
|
|
|
|
defaultValue={client}
|
2022-01-23 20:21:19 +00:00
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="client"
|
|
|
|
onToggle={setClientsDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
2022-03-07 14:28:42 +00:00
|
|
|
onChange(value);
|
2022-01-23 20:21:19 +00:00
|
|
|
setClientsDropdownOpen(false);
|
|
|
|
}}
|
2022-03-07 14:28:42 +00:00
|
|
|
selections={value.clientId}
|
2022-01-23 20:21:19 +00:00
|
|
|
variant={SelectVariant.typeahead}
|
|
|
|
aria-label={t("client")}
|
|
|
|
isOpen={clientsDropdownOpen}
|
|
|
|
>
|
|
|
|
{clients.map((client) => (
|
|
|
|
<SelectOption
|
2022-03-07 14:28:42 +00:00
|
|
|
selected={client.id === value.id}
|
2022-01-23 20:21:19 +00:00
|
|
|
key={client.clientId}
|
|
|
|
value={client}
|
|
|
|
>
|
|
|
|
{client.clientId}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("user")}
|
|
|
|
isRequired
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:userSelect"
|
|
|
|
fieldLabelId="clients:userSelect"
|
|
|
|
/>
|
|
|
|
}
|
2022-03-07 14:28:42 +00:00
|
|
|
fieldId="user"
|
2022-01-23 20:21:19 +00:00
|
|
|
>
|
|
|
|
<Controller
|
2022-03-07 14:28:42 +00:00
|
|
|
name="user"
|
2022-02-15 17:52:46 +00:00
|
|
|
rules={{
|
2022-03-07 14:28:42 +00:00
|
|
|
required: true,
|
2022-02-15 17:52:46 +00:00
|
|
|
}}
|
2022-01-23 20:21:19 +00:00
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="user"
|
|
|
|
placeholderText={t("selectAUser")}
|
|
|
|
onToggle={setUserDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
2022-03-07 14:28:42 +00:00
|
|
|
onChange(value);
|
2022-01-23 20:21:19 +00:00
|
|
|
setUserDropdownOpen(false);
|
|
|
|
}}
|
2022-03-07 14:28:42 +00:00
|
|
|
selections={value.username}
|
2022-01-23 20:21:19 +00:00
|
|
|
variant={SelectVariant.typeahead}
|
|
|
|
aria-label={t("user")}
|
|
|
|
isOpen={userDropdownOpen}
|
|
|
|
>
|
|
|
|
{users.map((user) => (
|
|
|
|
<SelectOption
|
2022-03-07 14:28:42 +00:00
|
|
|
selected={user.username === value.username}
|
2022-01-23 20:21:19 +00:00
|
|
|
key={user.username}
|
|
|
|
value={user}
|
|
|
|
>
|
|
|
|
{user.username}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("roles")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:roles"
|
|
|
|
fieldLabelId="clients:roles"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="realmRole"
|
|
|
|
>
|
|
|
|
<Controller
|
2022-02-15 17:52:46 +00:00
|
|
|
name="roleIds"
|
2022-01-23 20:21:19 +00:00
|
|
|
placeholderText={t("selectARole")}
|
|
|
|
control={control}
|
|
|
|
defaultValue={[]}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
variant={SelectVariant.typeaheadMulti}
|
|
|
|
toggleId="role"
|
|
|
|
onToggle={setRoleDropdownOpen}
|
|
|
|
selections={value}
|
|
|
|
onSelect={(_, v) => {
|
|
|
|
const option = v.toString();
|
|
|
|
if (value.includes(option)) {
|
|
|
|
onChange(value.filter((item: string) => item !== option));
|
|
|
|
} else {
|
|
|
|
onChange([...value, option]);
|
|
|
|
}
|
|
|
|
setRoleDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
onClear={(event) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
onChange([]);
|
|
|
|
}}
|
|
|
|
aria-label={t("realmRole")}
|
|
|
|
isOpen={roleDropdownOpen}
|
|
|
|
>
|
|
|
|
{clientRoles.map((role) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={role.name === value}
|
|
|
|
key={role.name}
|
|
|
|
value={role.name}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</FormAccess>
|
|
|
|
</FormPanel>
|
2022-05-23 08:52:06 +00:00
|
|
|
<FormPanel className="kc-permissions" title={t("common:permissions")}>
|
2022-05-30 09:23:24 +00:00
|
|
|
<FormAccess isHorizontal role="view-clients">
|
2022-01-23 20:21:19 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("applyToResourceType")}
|
|
|
|
fieldId="applyToResourceType"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:applyToResourceType"
|
|
|
|
fieldLabelId="clients:applyToResourceType"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
2022-03-07 14:28:42 +00:00
|
|
|
<Switch
|
|
|
|
id="applyToResource-switch"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={applyToResourceType}
|
|
|
|
onChange={setApplyToResourceType}
|
2022-01-23 20:21:19 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
|
2022-03-07 14:28:42 +00:00
|
|
|
{!applyToResourceType ? (
|
2022-01-23 20:21:19 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("resourcesAndAuthScopes")}
|
|
|
|
id="resourcesAndAuthScopes"
|
|
|
|
isRequired
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={t("clients-help:contextualAttributes")}
|
|
|
|
fieldLabelId={`resourcesAndAuthScopes`}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
helperTextInvalid={t("common:required")}
|
2022-02-17 16:03:18 +00:00
|
|
|
fieldId="resourcesAndAuthScopes"
|
2022-01-23 20:21:19 +00:00
|
|
|
>
|
2022-03-16 09:39:58 +00:00
|
|
|
<KeyBasedAttributeInput
|
2022-02-15 17:52:46 +00:00
|
|
|
selectableValues={resources.map<AttributeType>((item) => ({
|
|
|
|
name: item.name!,
|
|
|
|
key: item._id!,
|
|
|
|
}))}
|
2022-01-23 20:21:19 +00:00
|
|
|
resources={resources}
|
|
|
|
name="resources"
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2022-03-07 14:28:42 +00:00
|
|
|
) : (
|
2022-01-23 20:21:19 +00:00
|
|
|
<>
|
|
|
|
<FormGroup
|
|
|
|
label={t("resourceType")}
|
|
|
|
isRequired
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:resourceType"
|
|
|
|
fieldLabelId="clients:resourceType"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="client"
|
|
|
|
>
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2022-01-23 20:21:19 +00:00
|
|
|
type="text"
|
|
|
|
id="alias"
|
|
|
|
name="alias"
|
|
|
|
data-testid="alias"
|
|
|
|
ref={form.register({ required: true })}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("authScopes")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:scopesSelect"
|
|
|
|
fieldLabelId="clients:client"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="authScopes"
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="authScopes"
|
|
|
|
defaultValue={[]}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="authScopes"
|
|
|
|
onToggle={setScopesDropdownOpen}
|
|
|
|
onSelect={(_, v) => {
|
|
|
|
const option = v.toString();
|
|
|
|
if (value.includes(option)) {
|
|
|
|
onChange(
|
|
|
|
value.filter((item: string) => item !== option)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
onChange([...value, option]);
|
|
|
|
}
|
|
|
|
setScopesDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.typeaheadMulti}
|
|
|
|
aria-label={t("authScopes")}
|
|
|
|
isOpen={scopesDropdownOpen}
|
|
|
|
>
|
|
|
|
{scopes.map((scope) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={scope.name === value}
|
|
|
|
key={scope.id}
|
|
|
|
value={scope.name}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<ExpandableSection
|
|
|
|
toggleText={t("contextualInfo")}
|
|
|
|
onToggle={() => setIsExpanded(!isExpanded)}
|
|
|
|
isExpanded={isExpanded}
|
|
|
|
>
|
|
|
|
<FormGroup
|
|
|
|
label={t("contextualAttributes")}
|
|
|
|
id="contextualAttributes"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={t("clients-help:contextualAttributes")}
|
|
|
|
fieldLabelId={`contextualAttributes`}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
helperTextInvalid={t("common:required")}
|
2022-02-17 16:03:18 +00:00
|
|
|
fieldId="contextualAttributes"
|
2022-01-23 20:21:19 +00:00
|
|
|
>
|
2022-03-16 09:39:58 +00:00
|
|
|
<KeyBasedAttributeInput
|
2022-02-15 17:52:46 +00:00
|
|
|
selectableValues={defaultContextAttributes}
|
|
|
|
name="context.attributes"
|
2022-01-23 20:21:19 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</ExpandableSection>
|
|
|
|
</FormAccess>
|
2022-02-15 17:52:46 +00:00
|
|
|
<ActionGroup>
|
2022-02-17 16:03:18 +00:00
|
|
|
<Button
|
|
|
|
data-testid="authorization-eval"
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
|
|
isDisabled={form.getValues().resources?.every((e) => e.key === "")}
|
|
|
|
onClick={() => evaluate()}
|
|
|
|
>
|
2022-02-15 17:52:46 +00:00
|
|
|
{t("evaluate")}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
data-testid="authorization-revert"
|
|
|
|
variant="link"
|
|
|
|
onClick={() => reset()}
|
|
|
|
>
|
|
|
|
{t("common:revert")}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
data-testid="authorization-revert"
|
|
|
|
variant="primary"
|
|
|
|
onClick={() => reset()}
|
|
|
|
isDisabled
|
|
|
|
>
|
|
|
|
{t("lastEvaluation")}
|
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
2022-01-23 20:21:19 +00:00
|
|
|
</FormPanel>
|
|
|
|
</PageSection>
|
|
|
|
);
|
|
|
|
};
|