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-03-31 21:31:24 +00:00
import { customElement , property } from "lit-element" ;
import { html , TemplateResult } from "lit-html" ;
import { DEFAULT_CONFIG } from "../../api/Config" ;
import { Form } from "../../elements/forms/Form" ;
import { ifDefined } from "lit-html/directives/if-defined" ;
import "../../elements/forms/HorizontalFormElement" ;
2021-04-01 13:39:59 +00:00
import "../../elements/CodeMirror" ;
2021-03-31 21:31:24 +00:00
@customElement ( "ak-property-mapping-saml-form" )
export class PropertyMappingLDAPForm extends Form < SAMLPropertyMapping > {
set mappingUUID ( value : string ) {
new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsSamlRead ( {
pmUuid : value ,
} ) . then ( mapping = > {
this . mapping = mapping ;
} ) ;
}
@property ( { attribute : false } )
mapping? : SAMLPropertyMapping ;
getSuccessMessage ( ) : string {
if ( this . mapping ) {
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 > = > {
if ( this . mapping ) {
return new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsSamlUpdate ( {
pmUuid : this.mapping.pk || "" ,
data : data
} ) ;
} else {
return new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsSamlCreate ( {
data : data
} ) ;
}
} ;
renderForm ( ) : TemplateResult {
return html ` <form class="pf-c-form pf-m-horizontal">
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Name ` }
2021-03-31 21:31:24 +00:00
? required = $ { true }
name = "name" >
< input type = "text" value = "${ifDefined(this.mapping?.name)}" class = "pf-c-form-control" required >
< / 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 }
name = "samlName" >
< input type = "text" value = "${ifDefined(this.mapping?.samlName)}" class = "pf-c-form-control" required >
< 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 >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Friendly Name ` }
2021-03-31 21:31:24 +00:00
name = "friendlyName" >
2021-04-01 13:39:59 +00:00
< input type = "text" value = "${ifDefined(this.mapping?.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 >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Expression ` }
2021-03-31 21:31:24 +00:00
name = "expression" >
2021-04-01 13:39:59 +00:00
< ak - codemirror mode = "python" value = "${ifDefined(this.mapping?.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" >
Expression using Python . See < a href = "https://goauthentik.io/docs/property-mappings/expression/" > here < / a > for a list of all variables .
< / 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 > ` ;
}
}