2021-04-02 14:32:03 +00:00
|
|
|
import { AdminApi, EventMatcherPolicy, EventsApi, PoliciesApi } from "authentik-api";
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-05-11 10:19:35 +00:00
|
|
|
import { customElement } from "lit-element";
|
2021-04-02 14:32:03 +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";
|
|
|
|
import "../../../elements/forms/FormGroup";
|
|
|
|
import { until } from "lit-html/directives/until";
|
2021-04-03 22:36:53 +00:00
|
|
|
import { first } from "../../../utils";
|
2021-05-11 10:19:35 +00:00
|
|
|
import { ModelForm } from "../../../elements/forms/ModelForm";
|
2021-04-02 14:32:03 +00:00
|
|
|
|
|
|
|
@customElement("ak-policy-event-matcher-form")
|
2021-05-11 10:19:35 +00:00
|
|
|
export class EventMatcherPolicyForm extends ModelForm<EventMatcherPolicy, string> {
|
2021-04-02 14:32:03 +00:00
|
|
|
|
2021-05-11 10:19:35 +00:00
|
|
|
loadInstance(pk: string): Promise<EventMatcherPolicy> {
|
2021-05-16 12:43:42 +00:00
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherRetrieve({
|
2021-05-11 10:19:35 +00:00
|
|
|
policyUuid: pk,
|
2021-04-02 14:32:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-05-11 10:19:35 +00:00
|
|
|
if (this.instance) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated policy.`;
|
2021-04-02 14:32:03 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created policy.`;
|
2021-04-02 14:32:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: EventMatcherPolicy): Promise<EventMatcherPolicy> => {
|
2021-05-11 10:19:35 +00:00
|
|
|
if (this.instance) {
|
2021-04-02 14:32:03 +00:00
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherUpdate({
|
2021-05-11 10:19:35 +00:00
|
|
|
policyUuid: this.instance.pk || "",
|
2021-05-16 16:24:15 +00:00
|
|
|
eventMatcherPolicyRequest: data
|
2021-04-02 14:32:03 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherCreate({
|
2021-05-16 16:24:15 +00:00
|
|
|
eventMatcherPolicyRequest: data
|
2021-04-02 14:32:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
2021-04-10 10:37:08 +00:00
|
|
|
<div class="form-help-text">
|
|
|
|
${t`Matches an event against a set of criteria. If any of the configured values match, the policy passes.`}
|
|
|
|
</div>
|
2021-04-02 14:32:03 +00:00
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Name`}
|
2021-04-02 14:32:03 +00:00
|
|
|
?required=${true}
|
|
|
|
name="name">
|
2021-05-11 10:19:35 +00:00
|
|
|
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
|
2021-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="executionLogging">
|
|
|
|
<div class="pf-c-check">
|
2021-05-11 10:19:35 +00:00
|
|
|
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.executionLogging, false)}>
|
2021-04-02 14:32:03 +00:00
|
|
|
<label class="pf-c-check__label">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Execution logging`}
|
2021-04-02 14:32:03 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
2021-04-10 10:37:08 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged.`}
|
|
|
|
</p>
|
2021-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-group .expanded=${true}>
|
|
|
|
<span slot="header">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Policy-specific settings`}
|
2021-04-02 14:32:03 +00:00
|
|
|
</span>
|
|
|
|
<div slot="body" class="pf-c-form">
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Action`}
|
2021-04-02 14:32:03 +00:00
|
|
|
name="action">
|
|
|
|
<select class="pf-c-form-control">
|
2021-05-11 10:19:35 +00:00
|
|
|
<option value="" ?selected=${this.instance?.action === undefined}>---------</option>
|
2021-05-16 16:38:19 +00:00
|
|
|
${until(new EventsApi(DEFAULT_CONFIG).eventsEventsActionsList().then(actions => {
|
2021-04-02 14:32:03 +00:00
|
|
|
return actions.map(action => {
|
2021-05-11 10:19:35 +00:00
|
|
|
return html`<option value=${action.component} ?selected=${this.instance?.action === action.component}>${action.name}</option>`;
|
2021-04-02 14:32:03 +00:00
|
|
|
});
|
2021-04-03 22:24:06 +00:00
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
2021-04-02 14:32:03 +00:00
|
|
|
</select>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Match created events with this action type. When left empty, all action types will be matched.`}</p>
|
2021-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Client IP`}
|
2021-04-02 14:32:03 +00:00
|
|
|
name="clientIp">
|
2021-05-11 10:19:35 +00:00
|
|
|
<input type="text" value="${ifDefined(this.instance?.clientIp || "")}" class="pf-c-form-control">
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Matches Event's Client IP (strict matching, for network matching use an Expression Policy.`}</p>
|
2021-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`App`}
|
2021-04-02 14:32:03 +00:00
|
|
|
name="app">
|
|
|
|
<select class="pf-c-form-control">
|
2021-05-11 10:19:35 +00:00
|
|
|
<option value="" ?selected=${this.instance?.app === undefined}>---------</option>
|
2021-04-02 14:32:03 +00:00
|
|
|
${until(new AdminApi(DEFAULT_CONFIG).adminAppsList().then(apps => {
|
|
|
|
return apps.map(app => {
|
2021-05-11 10:19:35 +00:00
|
|
|
return html`<option value=${app.name} ?selected=${this.instance?.app === app.name}>${app.label}</option>`;
|
2021-04-02 14:32:03 +00:00
|
|
|
});
|
2021-04-03 22:24:06 +00:00
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
2021-04-02 14:32:03 +00:00
|
|
|
</select>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Match events created by selected application. When left empty, all applications are matched.`}</p>
|
2021-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</div>
|
|
|
|
</ak-form-group>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|