2021-08-03 15:52:21 +00:00
import {
FlowsApi ,
ProvidersApi ,
LDAPProvider ,
CoreApi ,
FlowsInstancesListDesignationEnum ,
CryptoApi ,
} from "authentik-api" ;
2021-04-26 10:03:44 +00:00
import { t } from "@lingui/macro" ;
2021-05-11 10:12:31 +00:00
import { customElement } from "lit-element" ;
2021-04-26 10:03:44 +00:00
import { html , TemplateResult } from "lit-html" ;
2021-07-26 16:47:59 +00:00
import { DEFAULT_CONFIG , tenant } from "../../../api/Config" ;
2021-05-11 09:48:34 +00:00
import { ModelForm } from "../../../elements/forms/ModelForm" ;
2021-04-26 10:03:44 +00:00
import { until } from "lit-html/directives/until" ;
import { ifDefined } from "lit-html/directives/if-defined" ;
import "../../../elements/forms/HorizontalFormElement" ;
import "../../../elements/forms/FormGroup" ;
import { first } from "../../../utils" ;
@customElement ( "ak-provider-ldap-form" )
2021-05-11 09:48:34 +00:00
export class LDAPProviderFormPage extends ModelForm < LDAPProvider , number > {
loadInstance ( pk : number ) : Promise < LDAPProvider > {
2021-05-16 12:43:42 +00:00
return new ProvidersApi ( DEFAULT_CONFIG ) . providersLdapRetrieve ( {
2021-05-11 09:48:34 +00:00
id : pk ,
2021-04-26 10:03:44 +00:00
} ) ;
}
getSuccessMessage ( ) : string {
2021-05-11 09:48:34 +00:00
if ( this . instance ) {
2021-04-26 10:03:44 +00:00
return t ` Successfully updated provider. ` ;
} else {
return t ` Successfully created provider. ` ;
}
}
send = ( data : LDAPProvider ) : Promise < LDAPProvider > = > {
2021-05-11 09:48:34 +00:00
if ( this . instance ) {
2021-04-26 10:03:44 +00:00
return new ProvidersApi ( DEFAULT_CONFIG ) . providersLdapUpdate ( {
2021-05-11 09:48:34 +00:00
id : this.instance.pk || 0 ,
2021-08-03 15:52:21 +00:00
lDAPProviderRequest : data ,
2021-04-26 10:03:44 +00:00
} ) ;
} else {
2021-08-21 16:48:02 +00:00
data . tlsServerName = "" ;
2021-04-26 10:03:44 +00:00
return new ProvidersApi ( DEFAULT_CONFIG ) . providersLdapCreate ( {
2021-08-03 15:52:21 +00:00
lDAPProviderRequest : data ,
2021-04-26 10:03:44 +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-04-26 10:03:44 +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
label = $ { t ` Bind flow ` }
? required = $ { true }
2021-08-03 15:52:21 +00:00
name = "authorizationFlow"
>
2021-04-26 10:03:44 +00:00
< select class = "pf-c-form-control" >
2021-08-03 15:52:21 +00:00
$ { until (
tenant ( ) . then ( ( t ) = > {
return new FlowsApi ( DEFAULT_CONFIG )
. flowsInstancesList ( {
ordering : "pk" ,
designation : FlowsInstancesListDesignationEnum.Authentication ,
} )
. then ( ( flows ) = > {
return flows . results . map ( ( flow ) = > {
let selected = flow . pk === t . flowAuthentication ;
if ( this . instance ? . authorizationFlow === flow . pk ) {
selected = true ;
}
return html ` <option
value = $ { ifDefined ( flow . pk ) }
? selected = $ { selected }
>
$ { flow . name } ( $ { flow . slug } )
< / option > ` ;
} ) ;
} ) ;
} ) ,
html ` <option> ${ t ` Loading... ` } </option> ` ,
) }
2021-04-26 10:03:44 +00:00
< / select >
2021-08-03 15:52:21 +00:00
< p class = "pf-c-form__helper-text" >
$ { t ` Flow used for users to authenticate. Currently only identification and password stages are supported. ` }
< / p >
2021-04-26 10:03:44 +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 >
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Group ` } name = "searchGroup" >
2021-04-26 21:25:03 +00:00
< select class = "pf-c-form-control" >
2021-08-03 15:52:21 +00:00
< option value = "" ? selected = $ { this.instance ? .searchGroup = = = undefined } >
-- -- -- -- -
< / option >
$ { until (
new CoreApi ( DEFAULT_CONFIG ) . coreGroupsList ( { } ) . then ( ( groups ) = > {
return groups . results . map ( ( group ) = > {
return html ` <option
value = $ { ifDefined ( group . pk ) }
? selected = $ { this . instance ? . searchGroup === group . pk }
>
$ { group . name }
< / option > ` ;
} ) ;
} ) ,
html ` <option> ${ t ` Loading... ` } </option> ` ,
) }
2021-04-26 21:25:03 +00:00
< / select >
2021-08-03 15:52:21 +00:00
< p class = "pf-c-form__helper-text" >
$ { t ` Users in the selected group can do search queries. If no group is selected, no LDAP Searches are allowed. ` }
< / p >
2021-04-26 21:25:03 +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 >
2021-04-26 10:03:44 +00:00
< ak - form - group .expanded = $ { true } >
2021-08-03 15:52:21 +00:00
< span slot = "header" > $ { t ` Protocol settings ` } < / span >
2021-04-26 10:03:44 +00:00
< div slot = "body" class = "pf-c-form" >
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Base DN ` } ? required = $ { true } name = "baseDn" >
< input
type = "text"
value = "${first(this.instance?.baseDn, " DC = ldap , DC = goauthentik , DC = io ")}"
class = "pf-c-form-control"
required
/ >
< p class = "pf-c-form__helper-text" >
$ { t ` LDAP DN under which bind requests and search requests can be made. ` }
< / p >
2021-04-26 10:03:44 +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 >
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Certificate ` } name = "certificate" >
2021-07-13 16:24:18 +00:00
< select class = "pf-c-form-control" >
2021-08-03 15:52:21 +00:00
< option value = "" ? selected = $ { this.instance ? .certificate = = = undefined } >
-- -- -- -- -
< / option >
$ { until (
new CryptoApi ( DEFAULT_CONFIG )
. cryptoCertificatekeypairsList ( {
ordering : "pk" ,
hasKey : true ,
} )
. then ( ( keys ) = > {
return keys . results . map ( ( key ) = > {
return html ` <option
value = $ { ifDefined ( key . pk ) }
? selected = $ { this . instance ? . certificate === key . pk }
>
$ { key . name }
< / option > ` ;
} ) ;
} ) ,
html ` <option> ${ t ` Loading... ` } </option> ` ,
) }
2021-07-13 16:24:18 +00:00
< / select >
2021-08-21 16:48:02 +00:00
< p class = "pf-c-form__helper-text" >
$ { t ` Due to protocol limitations, this certificate is only used when the outpost has a single provider. ` }
< / p >
< p class = "pf-c-form__helper-text" >
$ { t ` If multiple providers share an outpost, a self-signed certificate is used. ` }
< / p >
2021-07-13 16:24:18 +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 >
2021-07-14 07:17:01 +00:00
< ak - form - element - horizontal
label = $ { t ` UID start number ` }
? required = $ { true }
2021-08-03 15:52:21 +00:00
name = "uidStartNumber"
>
< input
type = "number"
value = "${first(this.instance?.uidStartNumber, 2000)}"
class = "pf-c-form-control"
required
/ >
< p class = "pf-c-form__helper-text" >
$ { t ` The start for uidNumbers, this number is added to the user.Pk to make sure that the numbers aren't too low for POSIX users. Default is 2000 to ensure that we don't collide with local users uidNumber ` }
< / p >
2021-07-14 07:17:01 +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
label = $ { t ` GID start number ` }
? required = $ { true }
2021-08-03 15:52:21 +00:00
name = "gidStartNumber"
>
< input
type = "number"
value = "${first(this.instance?.gidStartNumber, 4000)}"
class = "pf-c-form-control"
required
/ >
< p class = "pf-c-form__helper-text" >
$ { t ` The start for gidNumbers, this number is added to a number generated from the group.Pk to make sure that the numbers aren't too low for POSIX groups. Default is 4000 to ensure that we don't collide with local groups or users primary groups gidNumber ` }
< / p >
2021-07-14 07:17:01 +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 >
2021-04-26 10:03:44 +00:00
< / div >
< / a k - f o r m - g r o u p >
< / form > ` ;
}
}