2021-04-02 10:12:14 +00:00
|
|
|
import { LDAPSource, SourcesApi, PropertymappingsApi } from "authentik-api";
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-04-02 10:12:14 +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 "../../../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-04-02 10:12:14 +00:00
|
|
|
|
|
|
|
@customElement("ak-source-ldap-form")
|
|
|
|
export class LDAPSourceForm extends Form<LDAPSource> {
|
|
|
|
|
|
|
|
set sourceSlug(value: string) {
|
|
|
|
new SourcesApi(DEFAULT_CONFIG).sourcesLdapRead({
|
|
|
|
slug: value,
|
|
|
|
}).then(source => {
|
|
|
|
this.source = source;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@property({attribute: false})
|
|
|
|
source?: LDAPSource;
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
|
|
|
if (this.source) {
|
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> => {
|
|
|
|
if (this.source) {
|
|
|
|
return new SourcesApi(DEFAULT_CONFIG).sourcesLdapUpdate({
|
|
|
|
slug: this.source.slug,
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new SourcesApi(DEFAULT_CONFIG).sourcesLdapCreate({
|
|
|
|
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-04-02 10:12:14 +00:00
|
|
|
?required=${true}
|
|
|
|
name="name">
|
|
|
|
<input type="text" value="${ifDefined(this.source?.name)}" class="pf-c-form-control" required>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${ifDefined(this.source?.slug)}" class="pf-c-form-control" required>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="enabled">
|
|
|
|
<div class="pf-c-check">
|
2021-04-03 22:36:53 +00:00
|
|
|
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.source?.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>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="syncUsers">
|
|
|
|
<div class="pf-c-check">
|
2021-04-03 22:36:53 +00:00
|
|
|
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.source?.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>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="syncUsersPassword">
|
|
|
|
<div class="pf-c-check">
|
2021-04-03 22:36:53 +00:00
|
|
|
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.source?.syncUsersPassword, 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' passwords`}
|
2021-04-02 10:12:14 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="syncGroups">
|
|
|
|
<div class="pf-c-check">
|
2021-04-03 22:36:53 +00:00
|
|
|
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.source?.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>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${ifDefined(this.source?.serverUri)}" class="pf-c-form-control" required>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="startTls">
|
|
|
|
<div class="pf-c-check">
|
2021-04-03 22:36:53 +00:00
|
|
|
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.source?.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>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${ifDefined(this.source?.bindCn)}" class="pf-c-form-control" required>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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}
|
|
|
|
name="bindPassword">
|
|
|
|
<input type="text" value="${ifDefined(this.source?.bindPassword)}" class="pf-c-form-control" required>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${ifDefined(this.source?.baseDn)}" class="pf-c-form-control" required>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</div>
|
|
|
|
</ak-form-group>
|
|
|
|
<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;
|
|
|
|
if (!this.source?.propertyMappings) {
|
|
|
|
selected = mapping.managed?.startsWith("goauthentik.io/sources/ldap/default") || mapping.managed?.startsWith("goauthentik.io/sources/ldap/ms") || false;
|
|
|
|
} else {
|
|
|
|
selected = Array.from(this.source?.propertyMappings).some(su => {
|
|
|
|
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
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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;
|
|
|
|
if (!this.source?.propertyMappingsGroup) {
|
|
|
|
selected = mapping.managed === "goauthentik.io/sources/ldap/default-name";
|
|
|
|
} else {
|
|
|
|
selected = Array.from(this.source?.propertyMappingsGroup).some(su => {
|
|
|
|
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
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${ifDefined(this.source?.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
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${ifDefined(this.source?.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
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${this.source?.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
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${this.source?.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
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${this.source?.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
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<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">
|
|
|
|
<input type="text" value="${this.source?.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
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</div>
|
|
|
|
</ak-form-group>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|