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,6 +203,7 @@ export const RoleMappingForm = () => {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
{clients && (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={t("common:role")}
|
label={t("common:role")}
|
||||||
labelIcon={
|
labelIcon={
|
||||||
|
@ -198,7 +213,7 @@ export const RoleMappingForm = () => {
|
||||||
forID="role"
|
forID="role"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
validated={errors["config.role"] ? "error" : "default"}
|
validated={errors.config?.role ? "error" : "default"}
|
||||||
helperTextInvalid={t("common:required")}
|
helperTextInvalid={t("common:required")}
|
||||||
fieldId="role"
|
fieldId="role"
|
||||||
>
|
>
|
||||||
|
@ -261,6 +276,7 @@ export const RoleMappingForm = () => {
|
||||||
onChange(value);
|
onChange(value);
|
||||||
setRoleOpen(false);
|
setRoleOpen(false);
|
||||||
}}
|
}}
|
||||||
|
maxHeight={200}
|
||||||
onClear={() => onChange("")}
|
onClear={() => onChange("")}
|
||||||
>
|
>
|
||||||
{roleSelectOptions()}
|
{roleSelectOptions()}
|
||||||
|
@ -270,6 +286,7 @@ export const RoleMappingForm = () => {
|
||||||
</SplitItem>
|
</SplitItem>
|
||||||
</Split>
|
</Split>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
)}
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={t("newRoleName")}
|
label={t("newRoleName")}
|
||||||
labelIcon={
|
labelIcon={
|
||||||
|
|
Loading…
Reference in a new issue