Identity providers(mappers): update "create" form fields for all OIDC mapper types (#1286)

* correct form fields for UsernameTemplateImporter

wip tests

add username template importer type functionality

add create/edit functionality for username template importer SAML provider type

changes to helpText and title text

fix help text for mapper types

correct form fields for UsernameTemplateImporter

add fields

PR feedback and fix tests

fix test

add all saml mapper type fields

wip SAML mapper type fields

first draf SAML mapper type fields

tests

oidc changes with forms

tests

remove unused func

* fix tests

* remove unused vars
This commit is contained in:
Jenny 2021-10-04 11:34:02 -04:00 committed by GitHub
parent 9af18e11e2
commit ed7ba908ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 346 additions and 130 deletions

View file

@ -197,7 +197,7 @@ describe("Identity provider test", () => {
addMapperPage.addMapper();
addMapperPage.addAttrImporterMapper("Attribute Importer");
addMapperPage.addSAMLAttrImporterMapper("Attribute Importer");
masthead.checkNotificationMessage(createMapperSuccessMsg);
});
@ -244,6 +244,34 @@ describe("Identity provider test", () => {
masthead.checkNotificationMessage(createMapperSuccessMsg);
});
it("should add OIDC mapper of type Attribute Importer", () => {
sidebarPage.goToIdentityProviders();
listingPage.goToItemDetails("oidc");
addMapperPage.goToMappersTab();
addMapperPage.emptyStateAddMapper();
addMapperPage.addOIDCAttrImporterMapper("OIDC Attribute Importer");
masthead.checkNotificationMessage(createMapperSuccessMsg);
});
it("should add OIDC mapper of type Claim To Role", () => {
sidebarPage.goToIdentityProviders();
listingPage.goToItemDetails("oidc");
addMapperPage.goToMappersTab();
addMapperPage.addMapper();
addMapperPage.addOIDCClaimToRoleMapper("OIDC Claim to Role");
masthead.checkNotificationMessage(createMapperSuccessMsg);
});
it("should edit Username Template Importer mapper", () => {
sidebarPage.goToIdentityProviders();

View file

@ -9,7 +9,7 @@ export default class AddMapperPage {
private mapperRoleInput = "mapper-role-input";
private attributeName = "attribute-name";
private attributeFriendlyName = "attribute-friendly-name";
private attributeValue = "attribute-value";
private claimInput = "claim";
private userAttribute = "user-attribute";
private userAttributeName = "user-attribute-name";
private userAttributeValue = "user-attribute-value";
@ -184,7 +184,7 @@ export default class AddMapperPage {
return this;
}
addAttrImporterMapper(name: string) {
addSAMLAttrImporterMapper(name: string) {
cy.get(this.mapperNameInput).clear();
cy.get(this.mapperNameInput).clear().type(name);
@ -203,7 +203,33 @@ export default class AddMapperPage {
cy.findByTestId(this.attributeName).type("attribute name");
cy.findByTestId(this.attributeFriendlyName).clear();
cy.findByTestId(this.attributeFriendlyName).type("friendly name");
cy.findByTestId(this.attributeFriendlyName).type("attribute friendly name");
cy.findByTestId(this.userAttributeName).clear();
cy.findByTestId(this.userAttributeName).type("user attribute name");
this.saveNewMapper();
return this;
}
addOIDCAttrImporterMapper(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("Attribute Importer")
.click();
cy.findByTestId(this.claimInput).clear();
cy.findByTestId(this.claimInput).type("claim");
cy.findByTestId(this.userAttributeName).clear();
cy.findByTestId(this.userAttributeName).type("user attribute name");
@ -338,4 +364,59 @@ export default class AddMapperPage {
return this;
}
addOIDCAttributeImporterMapper(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("Attribute Importer")
.click();
cy.findByTestId(this.claimInput).clear();
cy.findByTestId(this.claimInput).type("claim");
cy.findByTestId(this.userAttributeName).clear();
cy.findByTestId(this.userAttributeName).type("user attribute name");
this.saveNewMapper();
return this;
}
addOIDCClaimToRoleMapper(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("Claim To Role").click();
cy.get(this.attributesKeyInput).clear();
cy.get(this.attributesKeyInput).type("key");
cy.get(this.attributesValueInput).clear();
cy.get(this.attributesValueInput).type("value");
this.toggleSwitch(this.regexAttributeValuesSwitch);
cy.findByTestId(this.mapperRoleInput).clear();
cy.findByTestId(this.mapperRoleInput).type("admin");
this.saveNewMapper();
return this;
}
}

View file

@ -172,12 +172,21 @@ export const AddMapper = () => {
const formValues = form.getValues();
const isAdvancedAttrToRole =
const isSAMLAdvancedAttrToRole =
formValues.identityProviderMapper === "saml-advanced-role-idp-mapper";
const isAttributeImporter =
const isOIDCclaimToRole =
formValues.identityProviderMapper === "oidc-role-idp-mapper";
const isOIDCAdvancedClaimToRole =
formValues.identityProviderMapper === "oidc-advanced-role-idp-mapper";
const isSAMLAttributeImporter =
formValues.identityProviderMapper === "saml-user-attribute-idp-mapper";
const isOIDCAttributeImporter =
formValues.identityProviderMapper === "oidc-user-attribute-idp-mapper";
const isHardcodedAttribute =
form.getValues().identityProviderMapper ===
"hardcoded-attribute-idp-mapper";
@ -192,9 +201,12 @@ export const AddMapper = () => {
const isSAMLAttributeToRole =
formValues.identityProviderMapper === "saml-role-idp-mapper";
const isUsernameTemplateImporter =
const isSAMLUsernameTemplateImporter =
formValues.identityProviderMapper === "saml-username-idp-mapper";
const isOIDCUsernameTemplateImporter =
formValues.identityProviderMapper === "oidc-username-idp-mapper";
const toggleModal = () => {
setRolesModalOpen(!rolesModalOpen);
};
@ -263,15 +275,35 @@ export const AddMapper = () => {
/>
{isSAMLorOIDC ? (
<>
{isAdvancedAttrToRole && (
{(isSAMLAdvancedAttrToRole || isOIDCAdvancedClaimToRole) && (
<>
<FormGroup
label={t("common:attributes")}
label={
isSAMLAdvancedAttrToRole
? t("common:attributes")
: t("claims")
}
labelIcon={
<HelpItem
helpText="identity-providers-help:attributes"
forLabel={t("attributes")}
forID={t(`common:helpLabel`, { label: t("attributes") })}
helpText={
isSAMLAdvancedAttrToRole
? "identity-providers-help:attributes"
: "identity-providers-help:claims"
}
forLabel={
isSAMLAdvancedAttrToRole
? t("common:attributes")
: t("common:claims")
}
forID={
isSAMLAdvancedAttrToRole
? t(`common:helpLabel`, {
label: t("attributes"),
})
: t(`common:helpLabel`, {
label: t("claim"),
})
}
/>
}
fieldId="kc-gui-order"
@ -313,7 +345,8 @@ export const AddMapper = () => {
</FormGroup>
</>
)}
{isUsernameTemplateImporter && (
{(isSAMLUsernameTemplateImporter ||
isOIDCUsernameTemplateImporter) && (
<>
<FormGroup
label={t("template")}
@ -408,50 +441,7 @@ export const AddMapper = () => {
</FormGroup>
</>
)}
{(isAdvancedAttrToRole ||
isHardcodedRole ||
isSAMLAttributeToRole) && (
<FormGroup
label={t("common:role")}
labelIcon={
<HelpItem
id="name-help-icon"
helpText="identity-providers-help:role"
forLabel={t("identity-providers-help:role")}
forID={t(`identity-providers:helpLabel`, {
label: t("role"),
})}
/>
}
fieldId="kc-role"
validated={
errors.config?.role
? ValidatedOptions.error
: ValidatedOptions.default
}
helperTextInvalid={t("common:required")}
>
<TextInput
ref={register()}
type="text"
id="kc-role"
data-testid="mapper-role-input"
name="config.role"
value={selectedRole[0]?.name}
validated={
errors.config?.role
? ValidatedOptions.error
: ValidatedOptions.default
}
/>
<Button
data-testid="select-role-button"
onClick={() => toggleModal()}
>
{t("selectRole")}
</Button>
</FormGroup>
)}
{(isHardcodedAttribute || isHardcodedUserSessionAttribute) && (
<>
<FormGroup
@ -546,7 +536,11 @@ export const AddMapper = () => {
</FormGroup>
</>
)}
{isAttributeImporter && (
{(isSAMLAttributeImporter ||
isOIDCAttributeImporter ||
isOIDCclaimToRole) && (
<>
{isSAMLAttributeImporter ? (
<>
<FormGroup
label={t("mapperAttributeName")}
@ -618,12 +612,61 @@ export const AddMapper = () => {
}
/>
</FormGroup>
</>
) : (
<FormGroup
label={t("mapperUserAttributeName")}
label={t("claim")}
labelIcon={
<HelpItem
id="user-attribute-name-help-icon"
helpText="identity-providers-help:userAttributeName"
id="claim"
helpText="identity-providers-help:claim"
forLabel={t("claim")}
forID={t(`common:helpLabel`, {
label: t("claim"),
})}
/>
}
fieldId="kc-friendly-name"
validated={
errors.name
? ValidatedOptions.error
: ValidatedOptions.default
}
helperTextInvalid={t("common:required")}
>
<TextInput
ref={register()}
type="text"
defaultValue={currentMapper?.config["claim"]}
data-testid="claim"
id="kc-claim"
name={"config.claim"}
validated={
errors.name
? ValidatedOptions.error
: ValidatedOptions.default
}
/>
</FormGroup>
)}
<FormGroup
label={
isOIDCclaimToRole
? t("claimValue")
: t("mapperUserAttributeName")
}
labelIcon={
<HelpItem
id={
isOIDCclaimToRole
? "claim-value-help-icon"
: "user-attribute-name-help-icon"
}
helpText={
isOIDCclaimToRole
? "identity-providers-help:claimValue"
: "identity-providers-help:userAttributeName"
}
forLabel={t("mapperUserAttributeName")}
forID={t(`common:helpLabel`, {
label: t("mapperUserAttributeName"),
@ -641,10 +684,24 @@ export const AddMapper = () => {
<TextInput
ref={register()}
type="text"
defaultValue={currentMapper?.config["attribute-value"]}
data-testid="user-attribute-name"
id="kc-user-attribute-name"
name="config.attribute-value"
defaultValue={
isOIDCclaimToRole
? currentMapper?.config["claim-value"]
: currentMapper?.config["attribute-value"]
}
data-testid={
isOIDCclaimToRole ? "claim-value" : "user-attribute-name"
}
id={
isOIDCclaimToRole
? "kc-claim-value"
: "kc-user-attribute-name"
}
name={
isOIDCclaimToRole
? "config.claim"
: "config.user-attribute"
}
validated={
errors.name
? ValidatedOptions.error
@ -654,6 +711,52 @@ export const AddMapper = () => {
</FormGroup>
</>
)}
{(isSAMLAdvancedAttrToRole ||
isHardcodedRole ||
isSAMLAttributeToRole ||
isOIDCAdvancedClaimToRole ||
isOIDCclaimToRole) && (
<FormGroup
label={t("common:role")}
labelIcon={
<HelpItem
id="name-help-icon"
helpText="identity-providers-help:role"
forLabel={t("identity-providers-help:role")}
forID={t(`identity-providers:helpLabel`, {
label: t("role"),
})}
/>
}
fieldId="kc-role"
validated={
errors.config?.role
? ValidatedOptions.error
: ValidatedOptions.default
}
helperTextInvalid={t("common:required")}
>
<TextInput
ref={register()}
type="text"
id="kc-role"
data-testid="mapper-role-input"
name="config.role"
value={selectedRole[0]?.name}
validated={
errors.config?.role
? ValidatedOptions.error
: ValidatedOptions.default
}
/>
<Button
data-testid="select-role-button"
onClick={() => toggleModal()}
>
{t("selectRole")}
</Button>
</FormGroup>
)}
</>
) : (
<>

View file

@ -134,7 +134,8 @@ export default {
"Destination field for the mapper. LOCAL (default) means that the changes are applied to the username stored in local database upon user import. BROKER_ID and BROKER_USERNAME means that the changes are stored into the ID or username used for federation user lookup, respectively.",
userSessionAttribute: "Name of user session attribute you want to hardcode",
userAttribute: "Name of user attribute you want to hardcode",
claim:
"Name of claim to search for in token. You can reference nested claims by using a '.', i.e. 'address.locality'. To use dot (.) literally, escape it with backslash. (\\.)",
userAttributeValue: "Value you want to hardcode",
attributeName:
"Name of attribute to search for in assertion. You can leave this blank and specify a friendly name instead.",

View file

@ -71,6 +71,9 @@ export default {
subjectNameId: "Subject NameID",
attributeName: "Attribute [Name]",
attributeFriendlyName: "Attribute [Friendly Name]",
claim: "Claim",
claimValue: "Claim Value",
claims: "Claims",
mapperAttributeName: "Attribute Name",
mapperUserAttributeName: "User Attribute Name",
mapperAttributeFriendlyName: "Friendly name",