2021-03-31 21:31:24 +00:00
import { SAMLPropertyMapping , PropertymappingsApi } from "authentik-api" ;
2021-04-03 17:26:43 +00:00
import { t } from "@lingui/macro" ;
2021-05-11 10:12:31 +00:00
import { customElement } from "lit-element" ;
2021-03-31 21:31:24 +00:00
import { html , TemplateResult } from "lit-html" ;
import { DEFAULT_CONFIG } from "../../api/Config" ;
import { ifDefined } from "lit-html/directives/if-defined" ;
import "../../elements/forms/HorizontalFormElement" ;
2021-04-01 13:39:59 +00:00
import "../../elements/CodeMirror" ;
2021-05-11 09:48:34 +00:00
import { ModelForm } from "../../elements/forms/ModelForm" ;
2021-03-31 21:31:24 +00:00
@customElement ( "ak-property-mapping-saml-form" )
2021-05-11 09:48:34 +00:00
export class PropertyMappingLDAPForm extends ModelForm < SAMLPropertyMapping , string > {
loadInstance ( pk : string ) : Promise < SAMLPropertyMapping > {
2021-05-16 12:43:42 +00:00
return new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsSamlRetrieve ( {
2021-05-11 09:48:34 +00:00
pmUuid : pk ,
2021-03-31 21:31:24 +00:00
} ) ;
}
getSuccessMessage ( ) : string {
2021-05-11 09:48:34 +00:00
if ( this . instance ) {
2021-04-03 17:26:43 +00:00
return t ` Successfully updated mapping. ` ;
2021-03-31 21:31:24 +00:00
} else {
2021-04-03 17:26:43 +00:00
return t ` Successfully created mapping. ` ;
2021-03-31 21:31:24 +00:00
}
}
send = ( data : SAMLPropertyMapping ) : Promise < SAMLPropertyMapping > = > {
2021-05-11 09:48:34 +00:00
if ( this . instance ) {
2021-03-31 21:31:24 +00:00
return new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsSamlUpdate ( {
2021-05-11 09:48:34 +00:00
pmUuid : this.instance.pk || "" ,
2021-08-03 15:52:21 +00:00
sAMLPropertyMappingRequest : data ,
2021-03-31 21:31:24 +00:00
} ) ;
} else {
return new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsSamlCreate ( {
2021-08-03 15:52:21 +00:00
sAMLPropertyMappingRequest : data ,
2021-03-31 21:31:24 +00:00
} ) ;
}
} ;
renderForm ( ) : TemplateResult {
return html ` <form class="pf-c-form pf-m-horizontal">
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Name ` } ? required = $ { true } name = "name" >
< input
type = "text"
value = "${ifDefined(this.instance?.name)}"
class = "pf-c-form-control"
required
/ >
2021-03-31 21:31:24 +00:00
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` SAML Attribute Name ` }
2021-03-31 21:31:24 +00:00
? required = $ { true }
2021-08-03 15:52:21 +00:00
name = "samlName"
>
< input
type = "text"
value = "${ifDefined(this.instance?.samlName)}"
class = "pf-c-form-control"
required
/ >
2021-03-31 21:31:24 +00:00
< p class = "pf-c-form__helper-text" >
2021-04-03 17:26:43 +00:00
$ { t ` Attribute name used for SAML Assertions. Can be a URN OID, a schema reference, or a any other string. If this property mapping is used for NameID Property, this field is discarded. ` }
2021-03-31 21:31:24 +00:00
< / p >
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Friendly Name ` } name = "friendlyName" >
< input
type = "text"
value = "${ifDefined(this.instance?.friendlyName || " ")}"
class = "pf-c-form-control"
/ >
2021-03-31 21:31:24 +00:00
< p class = "pf-c-form__helper-text" >
2021-04-03 17:26:43 +00:00
$ { t ` Optionally set the 'FriendlyName' value of the Assertion attribute. ` }
2021-03-31 21:31:24 +00:00
< / p >
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Expression ` } ? required = $ { true } name = "expression" >
2021-05-11 09:48:34 +00:00
< ak - codemirror mode = "python" value = "${ifDefined(this.instance?.expression)}" >
2021-03-31 21:31:24 +00:00
< / a k - c o d e m i r r o r >
< p class = "pf-c-form__helper-text" >
2021-04-03 18:42:08 +00:00
$ { t ` Expression using Python. ` }
2021-08-03 15:52:21 +00:00
< a
target = "_blank"
href = "https://goauthentik.io/docs/property-mappings/expression/"
>
2021-04-03 18:42:08 +00:00
$ { t ` See documentation for a list of all variables. ` }
< / a >
2021-03-31 21:31:24 +00:00
< / p >
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< / form > ` ;
}
}