multiple issues with this mapper (#1155)
This commit is contained in:
parent
528d22ce30
commit
71d881ccd0
1 changed files with 105 additions and 88 deletions
|
@ -31,16 +31,21 @@ export const RoleMappingForm = () => {
|
||||||
const { realm } = useRealm();
|
const { realm } = useRealm();
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { addAlert } = useAlerts();
|
const { addAlert, addError } = useAlerts();
|
||||||
|
|
||||||
const { t } = useTranslation("client-scopes");
|
const { t } = useTranslation("client-scopes");
|
||||||
const { register, handleSubmit, control, errors } = useForm();
|
const { register, handleSubmit, control, errors } =
|
||||||
|
useForm<ProtocolMapperRepresentation>({
|
||||||
|
defaultValues: {
|
||||||
|
protocolMapper: "oidc-role-name-mapper",
|
||||||
|
},
|
||||||
|
});
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
|
|
||||||
const [roleOpen, setRoleOpen] = useState(false);
|
const [roleOpen, setRoleOpen] = useState(false);
|
||||||
|
|
||||||
const [clientsOpen, setClientsOpen] = useState(false);
|
const [clientsOpen, setClientsOpen] = useState(false);
|
||||||
const [clients, setClients] = useState<ClientRepresentation[]>([]);
|
const [clients, setClients] = useState<ClientRepresentation[]>();
|
||||||
const [selectedClient, setSelectedClient] = useState<ClientRepresentation>();
|
const [selectedClient, setSelectedClient] = useState<ClientRepresentation>();
|
||||||
const [clientRoles, setClientRoles] = useState<RoleRepresentation[]>([]);
|
const [clientRoles, setClientRoles] = useState<RoleRepresentation[]>([]);
|
||||||
|
|
||||||
|
@ -74,10 +79,9 @@ export const RoleMappingForm = () => {
|
||||||
|
|
||||||
useFetch(
|
useFetch(
|
||||||
async () => {
|
async () => {
|
||||||
const client = selectedClient as ClientRepresentation;
|
if (selectedClient && selectedClient.name !== "realmRoles") {
|
||||||
if (client && client.name !== "realmRoles") {
|
|
||||||
const clientRoles = await adminClient.clients.listRoles({
|
const clientRoles = await adminClient.clients.listRoles({
|
||||||
id: client.id!,
|
id: selectedClient.id!,
|
||||||
});
|
});
|
||||||
return clientRoles;
|
return clientRoles;
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,10 +94,20 @@ export const RoleMappingForm = () => {
|
||||||
|
|
||||||
const save = async (mapping: ProtocolMapperRepresentation) => {
|
const save = async (mapping: ProtocolMapperRepresentation) => {
|
||||||
try {
|
try {
|
||||||
await adminClient.clientScopes.addProtocolMapper({ id }, mapping);
|
await adminClient.clientScopes.addProtocolMapper(
|
||||||
|
{ id },
|
||||||
|
{
|
||||||
|
...mapping,
|
||||||
|
protocol: "openid-connect",
|
||||||
|
config: {
|
||||||
|
...mapping.config,
|
||||||
|
role: `${selectedClient?.clientId}.${mapping.config?.role.name}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
addAlert(t("mapperCreateSuccess"));
|
addAlert(t("mapperCreateSuccess"));
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
addAlert(t("mapperCreateError", error));
|
addError("client-scopes:mapperCreateError", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -189,87 +203,90 @@ export const RoleMappingForm = () => {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup
|
{clients && (
|
||||||
label={t("common:role")}
|
<FormGroup
|
||||||
labelIcon={
|
label={t("common:role")}
|
||||||
<HelpItem
|
labelIcon={
|
||||||
helpText="client-scopes-help:role"
|
<HelpItem
|
||||||
forLabel={t("common:role")}
|
helpText="client-scopes-help:role"
|
||||||
forID="role"
|
forLabel={t("common:role")}
|
||||||
/>
|
forID="role"
|
||||||
}
|
|
||||||
validated={errors["config.role"] ? "error" : "default"}
|
|
||||||
helperTextInvalid={t("common:required")}
|
|
||||||
fieldId="role"
|
|
||||||
>
|
|
||||||
<Split hasGutter>
|
|
||||||
<SplitItem>
|
|
||||||
<Select
|
|
||||||
toggleId="role"
|
|
||||||
onToggle={() => setClientsOpen(!clientsOpen)}
|
|
||||||
isOpen={clientsOpen}
|
|
||||||
variant={SelectVariant.typeahead}
|
|
||||||
typeAheadAriaLabel={t("selectASourceOfRoles")}
|
|
||||||
placeholderText={t("selectASourceOfRoles")}
|
|
||||||
isGrouped
|
|
||||||
onFilter={(evt) => {
|
|
||||||
const textInput = evt?.target.value || "";
|
|
||||||
if (textInput === "") {
|
|
||||||
return createSelectGroup(clients);
|
|
||||||
} else {
|
|
||||||
return createSelectGroup(
|
|
||||||
clients.filter((client) =>
|
|
||||||
client
|
|
||||||
.name!.toLowerCase()
|
|
||||||
.includes(textInput.toLowerCase())
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
selections={selectedClient}
|
|
||||||
onClear={() => setSelectedClient(undefined)}
|
|
||||||
onSelect={(_, value) => {
|
|
||||||
if (value) {
|
|
||||||
setSelectedClient(value as ClientRepresentation);
|
|
||||||
setClientsOpen(false);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{createSelectGroup(clients)}
|
|
||||||
</Select>
|
|
||||||
</SplitItem>
|
|
||||||
<SplitItem>
|
|
||||||
<Controller
|
|
||||||
name="config.role"
|
|
||||||
defaultValue=""
|
|
||||||
control={control}
|
|
||||||
rules={{ required: true }}
|
|
||||||
render={({ onChange, value }) => (
|
|
||||||
<Select
|
|
||||||
onToggle={() => setRoleOpen(!roleOpen)}
|
|
||||||
isOpen={roleOpen}
|
|
||||||
variant={SelectVariant.typeahead}
|
|
||||||
placeholderText={
|
|
||||||
selectedClient && selectedClient.name !== "realmRoles"
|
|
||||||
? t("clientRoles")
|
|
||||||
: t("selectARole")
|
|
||||||
}
|
|
||||||
isDisabled={!selectedClient}
|
|
||||||
typeAheadAriaLabel={t("selectARole")}
|
|
||||||
selections={value.name}
|
|
||||||
onSelect={(_, value) => {
|
|
||||||
onChange(value);
|
|
||||||
setRoleOpen(false);
|
|
||||||
}}
|
|
||||||
onClear={() => onChange("")}
|
|
||||||
>
|
|
||||||
{roleSelectOptions()}
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
</SplitItem>
|
}
|
||||||
</Split>
|
validated={errors.config?.role ? "error" : "default"}
|
||||||
</FormGroup>
|
helperTextInvalid={t("common:required")}
|
||||||
|
fieldId="role"
|
||||||
|
>
|
||||||
|
<Split hasGutter>
|
||||||
|
<SplitItem>
|
||||||
|
<Select
|
||||||
|
toggleId="role"
|
||||||
|
onToggle={() => setClientsOpen(!clientsOpen)}
|
||||||
|
isOpen={clientsOpen}
|
||||||
|
variant={SelectVariant.typeahead}
|
||||||
|
typeAheadAriaLabel={t("selectASourceOfRoles")}
|
||||||
|
placeholderText={t("selectASourceOfRoles")}
|
||||||
|
isGrouped
|
||||||
|
onFilter={(evt) => {
|
||||||
|
const textInput = evt?.target.value || "";
|
||||||
|
if (textInput === "") {
|
||||||
|
return createSelectGroup(clients);
|
||||||
|
} else {
|
||||||
|
return createSelectGroup(
|
||||||
|
clients.filter((client) =>
|
||||||
|
client
|
||||||
|
.name!.toLowerCase()
|
||||||
|
.includes(textInput.toLowerCase())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
selections={selectedClient}
|
||||||
|
onClear={() => setSelectedClient(undefined)}
|
||||||
|
onSelect={(_, value) => {
|
||||||
|
if (value) {
|
||||||
|
setSelectedClient(value as ClientRepresentation);
|
||||||
|
setClientsOpen(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{createSelectGroup(clients)}
|
||||||
|
</Select>
|
||||||
|
</SplitItem>
|
||||||
|
<SplitItem>
|
||||||
|
<Controller
|
||||||
|
name="config.role"
|
||||||
|
defaultValue=""
|
||||||
|
control={control}
|
||||||
|
rules={{ required: true }}
|
||||||
|
render={({ onChange, value }) => (
|
||||||
|
<Select
|
||||||
|
onToggle={() => setRoleOpen(!roleOpen)}
|
||||||
|
isOpen={roleOpen}
|
||||||
|
variant={SelectVariant.typeahead}
|
||||||
|
placeholderText={
|
||||||
|
selectedClient && selectedClient.name !== "realmRoles"
|
||||||
|
? t("clientRoles")
|
||||||
|
: t("selectARole")
|
||||||
|
}
|
||||||
|
isDisabled={!selectedClient}
|
||||||
|
typeAheadAriaLabel={t("selectARole")}
|
||||||
|
selections={value.name}
|
||||||
|
onSelect={(_, value) => {
|
||||||
|
onChange(value);
|
||||||
|
setRoleOpen(false);
|
||||||
|
}}
|
||||||
|
maxHeight={200}
|
||||||
|
onClear={() => onChange("")}
|
||||||
|
>
|
||||||
|
{roleSelectOptions()}
|
||||||
|
</Select>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</SplitItem>
|
||||||
|
</Split>
|
||||||
|
</FormGroup>
|
||||||
|
)}
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={t("newRoleName")}
|
label={t("newRoleName")}
|
||||||
labelIcon={
|
labelIcon={
|
||||||
|
|
Loading…
Reference in a new issue