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-04-02 14:32:03 +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";
|
|
|
|
import "../../../elements/forms/FormGroup";
|
|
|
|
import { until } from "lit-html/directives/until";
|
2021-04-03 22:36:53 +00:00
|
|
|
import { first } from "../../../utils";
|
2021-04-02 14:32:03 +00:00
|
|
|
|
|
|
|
@customElement("ak-policy-event-matcher-form")
|
|
|
|
export class EventMatcherPolicyForm extends Form<EventMatcherPolicy> {
|
|
|
|
|
|
|
|
set policyUUID(value: string) {
|
|
|
|
new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherRead({
|
|
|
|
policyUuid: value,
|
|
|
|
}).then(policy => {
|
|
|
|
this.policy = policy;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@property({attribute: false})
|
|
|
|
policy?: EventMatcherPolicy;
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
|
|
|
if (this.policy) {
|
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> => {
|
|
|
|
if (this.policy) {
|
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherUpdate({
|
|
|
|
policyUuid: this.policy.pk || "",
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherCreate({
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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">
|
|
|
|
<input type="text" value="${ifDefined(this.policy?.name || "")}" class="pf-c-form-control" required>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="executionLogging">
|
|
|
|
<div class="pf-c-check">
|
2021-04-03 22:36:53 +00:00
|
|
|
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.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">
|
|
|
|
<option value="" ?selected=${this.policy?.action === undefined}>---------</option>
|
|
|
|
${until(new EventsApi(DEFAULT_CONFIG).eventsEventsActions().then(actions => {
|
|
|
|
return actions.map(action => {
|
2021-04-02 21:12:17 +00:00
|
|
|
return html`<option value=${action.component} ?selected=${this.policy?.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">
|
|
|
|
<input type="text" value="${ifDefined(this.policy?.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">
|
|
|
|
<option value="" ?selected=${this.policy?.app === undefined}>---------</option>
|
|
|
|
${until(new AdminApi(DEFAULT_CONFIG).adminAppsList().then(apps => {
|
|
|
|
return apps.map(app => {
|
|
|
|
return html`<option value=${app.name} ?selected=${this.policy?.app === app.name}>${app.label}</option>`;
|
|
|
|
});
|
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>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|