diff --git a/cypress/integration/identity_providers.spec.ts b/cypress/integration/identity_providers.spec.ts index e467cd17aa..6749ea5a88 100644 --- a/cypress/integration/identity_providers.spec.ts +++ b/cypress/integration/identity_providers.spec.ts @@ -133,7 +133,7 @@ describe("Identity provider test", () => { addMapperPage.goToMappersTab(); - addMapperPage.clickAdd(); + addMapperPage.emptyStateAddMapper(); addMapperPage.fillSocialMapper("facebook mapper"); @@ -149,13 +149,43 @@ describe("Identity provider test", () => { addMapperPage.goToMappersTab(); - addMapperPage.clickAdd(); + addMapperPage.emptyStateAddMapper(); addMapperPage.fillSAMLorOIDCMapper("SAML mapper"); masthead.checkNotificationMessage(createMapperSuccessMsg); }); + it("should add SAML mapper of type Username Template Importer", () => { + sidebarPage.goToIdentityProviders(); + + listingPage.goToItemDetails("saml"); + + addMapperPage.goToMappersTab(); + + addMapperPage.addMapper(); + + addMapperPage.addUsernameTemplateImporterMapper( + "SAML Username Template Importer Mapper" + ); + + masthead.checkNotificationMessage(createMapperSuccessMsg); + }); + + it("should edit Username Template Importer mapper", () => { + sidebarPage.goToIdentityProviders(); + + listingPage.goToItemDetails("saml"); + + addMapperPage.goToMappersTab(); + + listingPage.goToItemDetails("SAML Username Template Importer Mapper"); + + addMapperPage.editUsernameTemplateImporterMapper(); + + masthead.checkNotificationMessage(saveMapperSuccessMsg); + }); + it("should edit facebook mapper", () => { sidebarPage.goToIdentityProviders(); diff --git a/cypress/support/pages/admin_console/manage/identity_providers/AddMapperPage.ts b/cypress/support/pages/admin_console/manage/identity_providers/AddMapperPage.ts index 4b26a8e572..a054e131a6 100644 --- a/cypress/support/pages/admin_console/manage/identity_providers/AddMapperPage.ts +++ b/cypress/support/pages/admin_console/manage/identity_providers/AddMapperPage.ts @@ -3,6 +3,7 @@ export default class AddMapperPage { private noMappersAddMapperButton = "no-mappers-empty-action"; private idpMapperSelectToggle = "#identityProviderMapper"; private idpMapperSelect = "idp-mapper-select"; + private addMapperButton = "#add-mapper-button"; private mapperNameInput = "#kc-name"; private mapperRoleInput = "mapper-role-input"; @@ -13,6 +14,9 @@ export default class AddMapperPage { private syncmodeSelectToggle = "#syncMode"; private attributesKeyInput = 'input[name="config.attributes[0].key"]'; private attributesValueInput = 'input[name="config.attributes[0].value"]'; + private template = "template"; + private target = "#target"; + private targetDropdown = "#target-dropdown"; private selectRoleButton = "select-role-button"; private radio = "[type=radio]"; private addAssociatedRolesModalButton = "add-associated-roles-button"; @@ -22,11 +26,16 @@ export default class AddMapperPage { return this; } - clickAdd() { + emptyStateAddMapper() { cy.findByTestId(this.noMappersAddMapperButton).click(); return this; } + addMapper() { + cy.get(this.addMapperButton).click(); + return this; + } + clickCreateDropdown() { cy.contains("Add provider").click(); return this; @@ -94,7 +103,7 @@ export default class AddMapperPage { cy.get(this.idpMapperSelectToggle).click(); cy.findByTestId(this.idpMapperSelect) - .contains("Hardcoded User Session Attribute") + .contains("Advanced Attribute To Role") .click(); cy.get(this.attributesKeyInput).clear(); @@ -114,6 +123,49 @@ export default class AddMapperPage { return this; } + addUsernameTemplateImporterMapper(name: string) { + cy.get(this.mapperNameInput).clear(); + + cy.get(this.mapperNameInput).clear().type(name); + + cy.get(this.syncmodeSelectToggle).click(); + + cy.findByTestId("inherit").click(); + + cy.get(this.idpMapperSelectToggle).click(); + + cy.findByTestId(this.idpMapperSelect) + .contains("Username Template Importer") + .click(); + + cy.findByTestId(this.template).clear(); + cy.findByTestId(this.template).type("Template"); + + cy.get(this.target).click(); + + cy.get(this.targetDropdown).contains("LOCAL").click(); + + this.saveNewMapper(); + + return this; + } + + editUsernameTemplateImporterMapper() { + cy.get(this.syncmodeSelectToggle).click(); + + cy.findByTestId("legacy").click(); + + cy.findByTestId(this.template).type("_edited"); + + cy.get(this.target).click(); + + cy.get(this.targetDropdown).contains("BROKER_ID").click(); + + this.saveNewMapper(); + + return this; + } + editSocialMapper() { cy.get(this.syncmodeSelectToggle).click(); diff --git a/src/identity-providers/add/AddMapper.tsx b/src/identity-providers/add/AddMapper.tsx index 459490b2f2..46f6463df4 100644 --- a/src/identity-providers/add/AddMapper.tsx +++ b/src/identity-providers/add/AddMapper.tsx @@ -147,6 +147,10 @@ export const AddMapper = () => { ); } + if (mapper.config?.attribute) { + form.setValue("config.attributes", value.attribute); + } + if (mapper.config?.attributes) { form.setValue("config.attributes", JSON.parse(value.attributes)); } @@ -164,6 +168,8 @@ export const AddMapper = () => { const syncModes = ["inherit", "import", "legacy", "force"]; const [syncModeOpen, setSyncModeOpen] = useState(false); + const targetOptions = ["local", "brokerId", "brokerUsername"]; + const [targetOptionsOpen, setTargetOptionsOpen] = useState(false); const [mapperTypeOpen, setMapperTypeOpen] = useState(false); const [selectedRole, setSelectedRole] = useState([]); @@ -171,6 +177,8 @@ export const AddMapper = () => { setRolesModalOpen(!rolesModalOpen); }; + const formValues = form.getValues(); + return ( { {isSAMLorOIDC ? ( <> - {" "} - - } - fieldId="kc-gui-order" - > - - - - } - fieldId="regexAttributeValues" - > - ( - onChange("" + value)} + {formValues.identityProviderMapper === + "saml-advanced-role-idp-mapper" && ( + <> + + } + fieldId="kc-gui-order" + > + - )} - /> - - - } - fieldId="kc-role" - validated={ - errors.config?.role - ? ValidatedOptions.error - : ValidatedOptions.default - } - helperTextInvalid={t("common:required")} - > - + + } + fieldId="regexAttributeValues" + > + ( + onChange("" + value)} + /> + )} + /> + + + )} + {formValues.identityProviderMapper === + "saml-username-idp-mapper" && ( + <> + + } + fieldId="kc-user-session-attribute" + validated={ + errors.name + ? ValidatedOptions.error + : ValidatedOptions.default + } + helperTextInvalid={t("common:required")} + > + + + + } + fieldId="kc-target" + validated={ + errors.name + ? ValidatedOptions.error + : ValidatedOptions.default + } + helperTextInvalid={t("common:required")} + > + ( + + )} + /> + + + )} + {[ + "saml-advanced-role-idp-mapper", + "oidc-hardcoded-role-idp-mapper", + "saml-role-idp-mapper", + ].includes(formValues.identityProviderMapper!) && ( + + } + fieldId="kc-role" validated={ errors.config?.role ? ValidatedOptions.error : ValidatedOptions.default } - /> - - {" "} + + + + )} + {[ + "hardcoded-user-session-attribute-idp-mapper", + "hardcoded-attribute-idp-mapper", + ].includes(formValues.identityProviderMapper!) && ( + <> + + } + fieldId="kc-user-session-attribute" + validated={ + errors.name + ? ValidatedOptions.error + : ValidatedOptions.default + } + helperTextInvalid={t("common:required")} + > + + + + } + fieldId="kc-user-session-attribute-value" + validated={ + errors.name + ? ValidatedOptions.error + : ValidatedOptions.default + } + helperTextInvalid={t("common:required")} + > + + + + )} ) : ( <> @@ -527,6 +721,7 @@ export const AddMapper = () => { )} +