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,7 +536,11 @@ export const AddMapper = () => {
</FormGroup> </FormGroup>
</> </>
)} )}
{isAttributeImporter && ( {(isSAMLAttributeImporter ||
isOIDCAttributeImporter ||
isOIDCclaimToRole) && (
<>
{isSAMLAttributeImporter ? (
<> <>
<FormGroup <FormGroup
label={t("mapperAttributeName")} label={t("mapperAttributeName")}
@ -618,12 +612,61 @@ export const AddMapper = () => {
} }
/> />
</FormGroup> </FormGroup>
</>
) : (
<FormGroup <FormGroup
label={t("mapperUserAttributeName")} label={t("claim")}
labelIcon={ labelIcon={
<HelpItem <HelpItem
id="user-attribute-name-help-icon" id="claim"
helpText="identity-providers-help:userAttributeName" 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")} 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",