2021-05-16 16:24:15 +00:00
import { LDAPSource , SourcesApi , PropertymappingsApi , LDAPSourceRequest } from "authentik-api" ;
2021-04-03 17:26:43 +00:00
import { t } from "@lingui/macro" ;
2021-05-11 09:48:34 +00:00
import { customElement } from "lit-element" ;
2021-04-02 10:12:14 +00:00
import { html , TemplateResult } from "lit-html" ;
import { DEFAULT_CONFIG } from "../../../api/Config" ;
import "../../../elements/forms/FormGroup" ;
import "../../../elements/forms/HorizontalFormElement" ;
import { ifDefined } from "lit-html/directives/if-defined" ;
import { until } from "lit-html/directives/until" ;
2021-04-03 22:36:53 +00:00
import { first } from "../../../utils" ;
2021-05-11 09:48:34 +00:00
import { ModelForm } from "../../../elements/forms/ModelForm" ;
2021-04-02 10:12:14 +00:00
@customElement ( "ak-source-ldap-form" )
2021-05-11 09:48:34 +00:00
export class LDAPSourceForm extends ModelForm < LDAPSource , string > {
2021-04-02 10:12:14 +00:00
2021-05-11 09:48:34 +00:00
loadInstance ( pk : string ) : Promise < LDAPSource > {
2021-05-16 12:43:42 +00:00
return new SourcesApi ( DEFAULT_CONFIG ) . sourcesLdapRetrieve ( {
2021-05-11 09:48:34 +00:00
slug : pk ,
2021-04-02 10:12:14 +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 source. ` ;
2021-04-02 10:12:14 +00:00
} else {
2021-04-03 17:26:43 +00:00
return t ` Successfully created source. ` ;
2021-04-02 10:12:14 +00:00
}
}
send = ( data : LDAPSource ) : Promise < LDAPSource > = > {
2021-05-11 09:48:34 +00:00
if ( this . instance ) {
2021-04-04 18:07:46 +00:00
return new SourcesApi ( DEFAULT_CONFIG ) . sourcesLdapPartialUpdate ( {
2021-05-11 09:48:34 +00:00
slug : this.instance.slug ,
2021-05-16 16:24:15 +00:00
patchedLDAPSourceRequest : data
2021-04-02 10:12:14 +00:00
} ) ;
} else {
return new SourcesApi ( DEFAULT_CONFIG ) . sourcesLdapCreate ( {
2021-05-16 16:24:15 +00:00
lDAPSourceRequest : data as unknown as LDAPSourceRequest
2021-04-02 10:12:14 +00:00
} ) ;
}
} ;
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-04-02 10:12:14 +00:00
? required = $ { true }
name = "name" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${ifDefined(this.instance?.name)}" class = "pf-c-form-control" required >
2021-04-02 10:12:14 +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 ` Slug ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "slug" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${ifDefined(this.instance?.slug)}" class = "pf-c-form-control" required >
2021-04-02 10:12:14 +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 name = "enabled" >
< div class = "pf-c-check" >
2021-05-11 09:48:34 +00:00
< input type = "checkbox" class = "pf-c-check__input" ? checked = $ { first ( this.instance ? .enabled , true ) } >
2021-04-02 10:12:14 +00:00
< label class = "pf-c-check__label" >
2021-04-03 17:26:43 +00:00
$ { t ` Enabled ` }
2021-04-02 10:12:14 +00:00
< / label >
< / div >
< / 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 name = "syncUsers" >
< div class = "pf-c-check" >
2021-05-11 09:48:34 +00:00
< input type = "checkbox" class = "pf-c-check__input" ? checked = $ { first ( this.instance ? .syncUsers , true ) } >
2021-04-02 10:12:14 +00:00
< label class = "pf-c-check__label" >
2021-04-03 17:26:43 +00:00
$ { t ` Sync users ` }
2021-04-02 10:12:14 +00:00
< / label >
< / div >
< / 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 name = "syncUsersPassword" >
< div class = "pf-c-check" >
2021-05-11 09:48:34 +00:00
< input type = "checkbox" class = "pf-c-check__input" ? checked = $ { first ( this.instance ? .syncUsersPassword , true ) } >
2021-04-02 10:12:14 +00:00
< label class = "pf-c-check__label" >
2021-04-09 09:23:57 +00:00
$ { t ` User password writeback ` }
2021-04-02 10:12:14 +00:00
< / label >
< / div >
2021-04-09 09:23:57 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Login password is synced from LDAP into authentik automatically. Enable this option only to write password changes in authentik back to LDAP. ` } < / p >
2021-04-02 10:12:14 +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 name = "syncGroups" >
< div class = "pf-c-check" >
2021-05-11 09:48:34 +00:00
< input type = "checkbox" class = "pf-c-check__input" ? checked = $ { first ( this.instance ? .syncGroups , true ) } >
2021-04-02 10:12:14 +00:00
< label class = "pf-c-check__label" >
2021-04-03 17:26:43 +00:00
$ { t ` Sync groups ` }
2021-04-02 10:12:14 +00:00
< / label >
< / div >
< / 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 - group .expanded = $ { true } >
< span slot = "header" >
2021-04-03 17:26:43 +00:00
$ { t ` Connection settings ` }
2021-04-02 10:12:14 +00:00
< / span >
< div slot = "body" class = "pf-c-form" >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Server URI ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "serverUri" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${ifDefined(this.instance?.serverUri)}" class = "pf-c-form-control" required >
2021-04-02 10:12:14 +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 name = "startTls" >
< div class = "pf-c-check" >
2021-05-11 09:48:34 +00:00
< input type = "checkbox" class = "pf-c-check__input" ? checked = $ { first ( this.instance ? .startTls , true ) } >
2021-04-02 10:12:14 +00:00
< label class = "pf-c-check__label" >
2021-04-03 17:26:43 +00:00
$ { t ` Enable StartTLS ` }
2021-04-02 10:12:14 +00:00
< / label >
< / div >
< / 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 ` Bind CN ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "bindCn" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${ifDefined(this.instance?.bindCn)}" class = "pf-c-form-control" required >
2021-04-02 10:12:14 +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 ` Bind Password ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
2021-05-11 09:48:34 +00:00
? writeOnly = $ { this . instance !== undefined }
2021-04-02 10:12:14 +00:00
name = "bindPassword" >
2021-05-16 16:24:15 +00:00
< input type = "text" value = "" class = "pf-c-form-control" required >
2021-04-02 10:12:14 +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 ` Base DN ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "baseDn" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${ifDefined(this.instance?.baseDn)}" class = "pf-c-form-control" required >
2021-04-02 10:12:14 +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 >
< / div >
< / a k - f o r m - g r o u p >
< ak - form - group >
< span slot = "header" >
2021-04-03 17:26:43 +00:00
$ { t ` Advanced settings ` }
2021-04-02 10:12:14 +00:00
< / span >
< div slot = "body" class = "pf-c-form" >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` User Property Mappings ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "propertyMappings" >
< select class = "pf-c-form-control" multiple >
$ { until ( new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsLdapList ( {
2021-04-03 22:36:53 +00:00
ordering : "managed,object_field"
2021-04-02 10:12:14 +00:00
} ) . then ( mappings = > {
return mappings . results . map ( mapping = > {
let selected = false ;
2021-05-11 09:48:34 +00:00
if ( ! this . instance ? . propertyMappings ) {
2021-04-02 10:12:14 +00:00
selected = mapping . managed ? . startsWith ( "goauthentik.io/sources/ldap/default" ) || mapping . managed ? . startsWith ( "goauthentik.io/sources/ldap/ms" ) || false ;
} else {
2021-05-11 09:48:34 +00:00
selected = Array . from ( this . instance ? . propertyMappings ) . some ( su = > {
2021-04-02 10:12:14 +00:00
return su == mapping . pk ;
} ) ;
}
return html ` <option value= ${ ifDefined ( mapping . pk ) } ?selected= ${ selected } > ${ mapping . name } </option> ` ;
} ) ;
2021-04-03 22:24:06 +00:00
} ) , html ` <option> ${ t ` Loading... ` } </option> ` ) }
2021-04-02 10:12:14 +00:00
< / select >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Property mappings used to user creation. ` } < / p >
< p class = "pf-c-form__helper-text" > $ { t ` Hold control/command to select multiple items. ` } < / p >
2021-04-02 10:12:14 +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 ` Group Property Mappings ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "propertyMappingsGroup" >
< select class = "pf-c-form-control" multiple >
$ { until ( new PropertymappingsApi ( DEFAULT_CONFIG ) . propertymappingsLdapList ( {
ordering : "object_field"
} ) . then ( mappings = > {
return mappings . results . map ( mapping = > {
let selected = false ;
2021-05-11 09:48:34 +00:00
if ( ! this . instance ? . propertyMappingsGroup ) {
2021-04-02 10:12:14 +00:00
selected = mapping . managed === "goauthentik.io/sources/ldap/default-name" ;
} else {
2021-05-11 09:48:34 +00:00
selected = Array . from ( this . instance ? . propertyMappingsGroup ) . some ( su = > {
2021-04-02 10:12:14 +00:00
return su == mapping . pk ;
} ) ;
}
return html ` <option value= ${ ifDefined ( mapping . pk ) } ?selected= ${ selected } > ${ mapping . name } </option> ` ;
} ) ;
2021-04-03 22:24:06 +00:00
} ) , html ` <option> ${ t ` Loading... ` } </option> ` ) }
2021-04-02 10:12:14 +00:00
< / select >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Property mappings used to group creation. ` } < / p >
< p class = "pf-c-form__helper-text" > $ { t ` Hold control/command to select multiple items. ` } < / p >
2021-04-02 10:12:14 +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 ` Addition User DN ` }
2021-04-02 10:12:14 +00:00
name = "additionalUserDn" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${ifDefined(this.instance?.additionalUserDn)}" class = "pf-c-form-control" >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Additional user DN, prepended to the Base DN. ` } < / p >
2021-04-02 10:12:14 +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 ` Addition Group DN ` }
2021-04-02 10:12:14 +00:00
name = "additionalGroupDn" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${ifDefined(this.instance?.additionalGroupDn)}" class = "pf-c-form-control" >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Additional group DN, prepended to the Base DN. ` } < / p >
2021-04-02 10:12:14 +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 ` User object filter ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "userObjectFilter" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${this.instance?.userObjectFilter || " ( objectClass = person ) " } " class = "pf-c-form-control" required >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Consider Objects matching this filter to be Users. ` } < / p >
2021-04-02 10:12:14 +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 ` Group object filter ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "groupObjectFilter" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${this.instance?.groupObjectFilter || " ( objectClass = group ) " } " class = "pf-c-form-control" required >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Consider Objects matching this filter to be Groups. ` } < / p >
2021-04-02 10:12:14 +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 ` Group membership field ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "groupMembershipField" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${this.instance?.groupMembershipField || " member " } " class = "pf-c-form-control" required >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Field which contains members of a group. ` } < / p >
2021-04-02 10:12:14 +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 ` Object uniqueness field ` }
2021-04-02 10:12:14 +00:00
? required = $ { true }
name = "objectUniquenessField" >
2021-05-11 09:48:34 +00:00
< input type = "text" value = "${this.instance?.objectUniquenessField || " objectSid " } " class = "pf-c-form-control" required >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Field which contains a unique Identifier. ` } < / p >
2021-04-02 10:12:14 +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 >
< / div >
< / a k - f o r m - g r o u p >
< / form > ` ;
}
}