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.addMapper();
addMapperPage.addAttrImporterMapper("Attribute Importer"); addMapperPage.addSAMLAttrImporterMapper("Attribute Importer");
masthead.checkNotificationMessage(createMapperSuccessMsg); masthead.checkNotificationMessage(createMapperSuccessMsg);
}); });
@ -244,6 +244,34 @@ describe("Identity provider test", () => {
masthead.checkNotificationMessage(createMapperSuccessMsg); 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", () => { it("should edit Username Template Importer mapper", () => {
sidebarPage.goToIdentityProviders(); sidebarPage.goToIdentityProviders();

View file

@ -9,7 +9,7 @@ export default class AddMapperPage {
private mapperRoleInput = "mapper-role-input"; private mapperRoleInput = "mapper-role-input";
private attributeName = "attribute-name"; private attributeName = "attribute-name";
private attributeFriendlyName = "attribute-friendly-name"; private attributeFriendlyName = "attribute-friendly-name";
private attributeValue = "attribute-value"; private claimInput = "claim";
private userAttribute = "user-attribute"; private userAttribute = "user-attribute";
private userAttributeName = "user-attribute-name"; private userAttributeName = "user-attribute-name";
private userAttributeValue = "user-attribute-value"; private userAttributeValue = "user-attribute-value";
@ -184,7 +184,7 @@ export default class AddMapperPage {
return this; return this;
} }
addAttrImporterMapper(name: string) { addSAMLAttrImporterMapper(name: string) {
cy.get(this.mapperNameInput).clear(); cy.get(this.mapperNameInput).clear();
cy.get(this.mapperNameInput).clear().type(name); 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.attributeName).type("attribute name");
cy.findByTestId(this.attributeFriendlyName).clear(); 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).clear();
cy.findByTestId(this.userAttributeName).type("user attribute name"); cy.findByTestId(this.userAttributeName).type("user attribute name");
@ -338,4 +364,59 @@ export default class AddMapperPage {
return this; 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 formValues = form.getValues();
const isAdvancedAttrToRole = const isSAMLAdvancedAttrToRole =
formValues.identityProviderMapper === "saml-advanced-role-idp-mapper"; 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"; formValues.identityProviderMapper === "saml-user-attribute-idp-mapper";
const isOIDCAttributeImporter =
formValues.identityProviderMapper === "oidc-user-attribute-idp-mapper";
const isHardcodedAttribute = const isHardcodedAttribute =
form.getValues().identityProviderMapper === form.getValues().identityProviderMapper ===
"hardcoded-attribute-idp-mapper"; "hardcoded-attribute-idp-mapper";
@ -192,9 +201,12 @@ export const AddMapper = () => {
const isSAMLAttributeToRole = const isSAMLAttributeToRole =
formValues.identityProviderMapper === "saml-role-idp-mapper"; formValues.identityProviderMapper === "saml-role-idp-mapper";
const isUsernameTemplateImporter = const isSAMLUsernameTemplateImporter =
formValues.identityProviderMapper === "saml-username-idp-mapper"; formValues.identityProviderMapper === "saml-username-idp-mapper";
const isOIDCUsernameTemplateImporter =
formValues.identityProviderMapper === "oidc-username-idp-mapper";
const toggleModal = () => { const toggleModal = () => {
setRolesModalOpen(!rolesModalOpen); setRolesModalOpen(!rolesModalOpen);
}; };
@ -263,15 +275,35 @@ export const AddMapper = () => {
/> />
{isSAMLorOIDC ? ( {isSAMLorOIDC ? (
<> <>
{isAdvancedAttrToRole && ( {(isSAMLAdvancedAttrToRole || isOIDCAdvancedClaimToRole) && (
<> <>
<FormGroup <FormGroup
label={t("common:attributes")} label={
isSAMLAdvancedAttrToRole
? t("common:attributes")
: t("claims")
}
labelIcon={ labelIcon={
<HelpItem <HelpItem
helpText="identity-providers-help:attributes" helpText={
forLabel={t("attributes")} isSAMLAdvancedAttrToRole
forID={t(`common:helpLabel`, { label: t("attributes") })} ? "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" fieldId="kc-gui-order"
@ -313,7 +345,8 @@ export const AddMapper = () => {
</FormGroup> </FormGroup>
</> </>
)} )}
{isUsernameTemplateImporter && ( {(isSAMLUsernameTemplateImporter ||
isOIDCUsernameTemplateImporter) && (
<> <>
<FormGroup <FormGroup
label={t("template")} label={t("template")}
@ -408,50 +441,7 @@ export const AddMapper = () => {
</FormGroup> </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) && ( {(isHardcodedAttribute || isHardcodedUserSessionAttribute) && (
<> <>
<FormGroup <FormGroup
@ -546,84 +536,137 @@ export const AddMapper = () => {
</FormGroup> </FormGroup>
</> </>
)} )}
{isAttributeImporter && ( {(isSAMLAttributeImporter ||
isOIDCAttributeImporter ||
isOIDCclaimToRole) && (
<> <>
<FormGroup {isSAMLAttributeImporter ? (
label={t("mapperAttributeName")} <>
labelIcon={ <FormGroup
<HelpItem label={t("mapperAttributeName")}
id="user-session-attribute-help-icon" labelIcon={
helpText="identity-providers-help:attributeName" <HelpItem
forLabel={t("mapperAttributeName")} id="user-session-attribute-help-icon"
forID={t(`common:helpLabel`, { helpText="identity-providers-help:attributeName"
label: t("mapperAttributeName"), forLabel={t("mapperAttributeName")}
})} forID={t(`common:helpLabel`, {
/> label: t("mapperAttributeName"),
} })}
fieldId="kc-attribute-name" />
validated={ }
errors.name fieldId="kc-attribute-name"
? ValidatedOptions.error validated={
: ValidatedOptions.default errors.name
} ? ValidatedOptions.error
helperTextInvalid={t("common:required")} : ValidatedOptions.default
> }
<TextInput helperTextInvalid={t("common:required")}
ref={register()} >
type="text" <TextInput
defaultValue={currentMapper?.config["attribute-name"]} ref={register()}
id="kc-attribute-name" type="text"
data-testid="attribute-name" defaultValue={currentMapper?.config["attribute-name"]}
name="config.attribute-name" id="kc-attribute-name"
data-testid="attribute-name"
name="config.attribute-name"
validated={
errors.name
? ValidatedOptions.error
: ValidatedOptions.default
}
/>
</FormGroup>
<FormGroup
label={t("mapperAttributeFriendlyName")}
labelIcon={
<HelpItem
id="mapper-attribute-friendly-name"
helpText="identity-providers-help:friendlyName"
forLabel={t("mapperAttributeFriendlyName")}
forID={t(`common:helpLabel`, {
label: t("mapperAttributeFriendlyName"),
})}
/>
}
fieldId="kc-friendly-name"
validated={
errors.name
? ValidatedOptions.error
: ValidatedOptions.default
}
helperTextInvalid={t("common:required")}
>
<TextInput
ref={register()}
type="text"
defaultValue={
currentMapper?.config["attribute-friendly-name"]
}
data-testid="attribute-friendly-name"
id="kc-attribute-friendly-name"
name="config.attribute-friendly-name"
validated={
errors.name
? ValidatedOptions.error
: ValidatedOptions.default
}
/>
</FormGroup>
</>
) : (
<FormGroup
label={t("claim")}
labelIcon={
<HelpItem
id="claim"
helpText="identity-providers-help:claim"
forLabel={t("claim")}
forID={t(`common:helpLabel`, {
label: t("claim"),
})}
/>
}
fieldId="kc-friendly-name"
validated={ validated={
errors.name errors.name
? ValidatedOptions.error ? ValidatedOptions.error
: ValidatedOptions.default : ValidatedOptions.default
} }
/> helperTextInvalid={t("common:required")}
</FormGroup> >
<FormGroup <TextInput
label={t("mapperAttributeFriendlyName")} ref={register()}
labelIcon={ type="text"
<HelpItem defaultValue={currentMapper?.config["claim"]}
id="mapper-attribute-friendly-name" data-testid="claim"
helpText="identity-providers-help:friendlyName" id="kc-claim"
forLabel={t("mapperAttributeFriendlyName")} name={"config.claim"}
forID={t(`common:helpLabel`, { validated={
label: t("mapperAttributeFriendlyName"), errors.name
})} ? ValidatedOptions.error
: ValidatedOptions.default
}
/> />
} </FormGroup>
fieldId="kc-friendly-name" )}
validated={
errors.name
? ValidatedOptions.error
: ValidatedOptions.default
}
helperTextInvalid={t("common:required")}
>
<TextInput
ref={register()}
type="text"
defaultValue={
currentMapper?.config["attribute-friendly-name"]
}
data-testid="attribute-friendly-name"
id="kc-attribute-friendly-name"
name="config.attribute-friendly-name"
validated={
errors.name
? ValidatedOptions.error
: ValidatedOptions.default
}
/>
</FormGroup>
<FormGroup <FormGroup
label={t("mapperUserAttributeName")} label={
isOIDCclaimToRole
? t("claimValue")
: t("mapperUserAttributeName")
}
labelIcon={ labelIcon={
<HelpItem <HelpItem
id="user-attribute-name-help-icon" id={
helpText="identity-providers-help:userAttributeName" isOIDCclaimToRole
? "claim-value-help-icon"
: "user-attribute-name-help-icon"
}
helpText={
isOIDCclaimToRole
? "identity-providers-help:claimValue"
: "identity-providers-help:userAttributeName"
}
forLabel={t("mapperUserAttributeName")} forLabel={t("mapperUserAttributeName")}
forID={t(`common:helpLabel`, { forID={t(`common:helpLabel`, {
label: t("mapperUserAttributeName"), label: t("mapperUserAttributeName"),
@ -641,10 +684,24 @@ export const AddMapper = () => {
<TextInput <TextInput
ref={register()} ref={register()}
type="text" type="text"
defaultValue={currentMapper?.config["attribute-value"]} defaultValue={
data-testid="user-attribute-name" isOIDCclaimToRole
id="kc-user-attribute-name" ? currentMapper?.config["claim-value"]
name="config.attribute-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={ validated={
errors.name errors.name
? ValidatedOptions.error ? ValidatedOptions.error
@ -654,6 +711,52 @@ export const AddMapper = () => {
</FormGroup> </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.", "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", userSessionAttribute: "Name of user session attribute you want to hardcode",
userAttribute: "Name of user 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", userAttributeValue: "Value you want to hardcode",
attributeName: attributeName:
"Name of attribute to search for in assertion. You can leave this blank and specify a friendly name instead.", "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", subjectNameId: "Subject NameID",
attributeName: "Attribute [Name]", attributeName: "Attribute [Name]",
attributeFriendlyName: "Attribute [Friendly Name]", attributeFriendlyName: "Attribute [Friendly Name]",
claim: "Claim",
claimValue: "Claim Value",
claims: "Claims",
mapperAttributeName: "Attribute Name", mapperAttributeName: "Attribute Name",
mapperUserAttributeName: "User Attribute Name", mapperUserAttributeName: "User Attribute Name",
mapperAttributeFriendlyName: "Friendly name", mapperAttributeFriendlyName: "Friendly name",