2020-12-28 13:26:41 +00:00
|
|
|
import { gettext } from "django";
|
|
|
|
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
|
|
|
|
import { until } from "lit-html/directives/until";
|
|
|
|
import { Event, EventContext } from "../../api/Events";
|
|
|
|
import { Flow } from "../../api/Flows";
|
|
|
|
import { COMMON_STYLES } from "../../common/styles";
|
|
|
|
import "../../elements/Spinner";
|
2021-02-04 19:59:18 +00:00
|
|
|
import "../../elements/Expand";
|
2020-12-28 13:26:41 +00:00
|
|
|
import { SpinnerSize } from "../../elements/Spinner";
|
|
|
|
|
|
|
|
@customElement("ak-event-info")
|
|
|
|
export class EventInfo extends LitElement {
|
|
|
|
|
|
|
|
@property({attribute: false})
|
|
|
|
event?: Event;
|
|
|
|
|
|
|
|
static get styles(): CSSResult[] {
|
|
|
|
return COMMON_STYLES.concat(
|
|
|
|
css`
|
|
|
|
code {
|
|
|
|
display: block;
|
|
|
|
white-space: pre-wrap;
|
|
|
|
}
|
2021-01-05 10:52:18 +00:00
|
|
|
.pf-l-flex {
|
|
|
|
justify-content: space-between;
|
|
|
|
}
|
|
|
|
.pf-l-flex__item {
|
|
|
|
min-width: 25%;
|
|
|
|
}
|
2020-12-28 13:26:41 +00:00
|
|
|
`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getModelInfo(context: EventContext): TemplateResult {
|
2021-01-14 17:13:52 +00:00
|
|
|
if (context === null) {
|
|
|
|
return html`<span>-</span>`;
|
|
|
|
}
|
2020-12-28 13:26:41 +00:00
|
|
|
return html`<ul class="pf-c-list">
|
|
|
|
<li>${gettext("UID")}: ${context.pk as string}</li>
|
|
|
|
<li>${gettext("Name")}: ${context.name as string}</li>
|
|
|
|
<li>${gettext("App")}: ${context.app as string}</li>
|
|
|
|
<li>${gettext("Model Name")}: ${context.model_name as string}</li>
|
|
|
|
</ul>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultResponse(): TemplateResult {
|
|
|
|
return html`<div class="pf-l-flex">
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Context")}</h3>
|
2021-01-16 16:02:31 +00:00
|
|
|
<code>${JSON.stringify(this.event?.context, null, 4)}</code>
|
2020-12-28 13:26:41 +00:00
|
|
|
</div>
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("User")}</h3>
|
2021-01-16 16:02:31 +00:00
|
|
|
<code>${JSON.stringify(this.event?.user, null, 4)}</code>
|
2020-12-28 13:26:41 +00:00
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
render(): TemplateResult {
|
|
|
|
if (!this.event) {
|
|
|
|
return html`<ak-spinner size=${SpinnerSize.Medium}></ak-spinner>`;
|
|
|
|
}
|
|
|
|
switch (this.event?.action) {
|
|
|
|
case "model_created":
|
|
|
|
case "model_updated":
|
|
|
|
case "model_deleted":
|
|
|
|
return html`
|
2021-02-08 10:51:38 +00:00
|
|
|
<h3>${gettext("Affected model:")}</h3>
|
2020-12-28 13:26:41 +00:00
|
|
|
${this.getModelInfo(this.event.context.model as EventContext)}
|
|
|
|
`;
|
|
|
|
case "authorize_application":
|
|
|
|
return html`<div class="pf-l-flex">
|
|
|
|
<div class="pf-l-flex__item">
|
2021-02-08 10:51:38 +00:00
|
|
|
<h3>${gettext("Authorized application:")}</h3>
|
2020-12-28 13:26:41 +00:00
|
|
|
${this.getModelInfo(this.event.context.authorized_application as EventContext)}
|
|
|
|
</div>
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Using flow")}</h3>
|
|
|
|
<span>${until(Flow.list({
|
2021-02-04 19:48:16 +00:00
|
|
|
flow_uuid: this.event.context.flow as string,
|
|
|
|
}).then(resp => {
|
|
|
|
return html`<a href="#/flows/${resp.results[0].slug}">${resp.results[0].name}</a>`;
|
|
|
|
}), html`<ak-spinner size=${SpinnerSize.Medium}></ak-spinner>`)}
|
|
|
|
</span>
|
2020-12-28 13:26:41 +00:00
|
|
|
</div>
|
2021-02-08 10:51:38 +00:00
|
|
|
</div>
|
|
|
|
<ak-expand>${this.defaultResponse()}</ak-expand>`;
|
2020-12-28 13:26:41 +00:00
|
|
|
case "login_failed":
|
|
|
|
return html`
|
|
|
|
<h3>${gettext(`Attempted to log in as ${this.event.context.username}`)}</h3>
|
2021-02-04 19:59:18 +00:00
|
|
|
<ak-expand>${this.defaultResponse()}</ak-expand>`;
|
2021-02-09 17:18:36 +00:00
|
|
|
case "secret_view":
|
2020-12-28 13:26:41 +00:00
|
|
|
return html`
|
2021-02-08 10:51:38 +00:00
|
|
|
<h3>${gettext("Token:")}</h3>
|
2021-02-04 19:59:18 +00:00
|
|
|
${this.getModelInfo(this.event.context.token as EventContext)}`;
|
2020-12-28 13:26:41 +00:00
|
|
|
case "property_mapping_exception":
|
|
|
|
return html`<div class="pf-l-flex">
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Exception")}</h3>
|
2021-01-14 20:58:10 +00:00
|
|
|
<code>${this.event.context.message || this.event.context.error}</code>
|
2020-12-28 13:26:41 +00:00
|
|
|
</div>
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Expression")}</h3>
|
|
|
|
<code>${this.event.context.expression}</code>
|
|
|
|
</div>
|
2021-02-04 19:59:18 +00:00
|
|
|
</div>
|
|
|
|
<ak-expand>${this.defaultResponse()}</ak-expand>`;
|
2021-01-14 17:13:52 +00:00
|
|
|
case "policy_exception":
|
|
|
|
return html`<div class="pf-l-flex">
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Binding")}</h3>
|
|
|
|
${this.getModelInfo(this.event.context.binding as EventContext)}
|
|
|
|
</div>
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Request")}</h3>
|
|
|
|
<ul class="pf-c-list">
|
|
|
|
<li>${gettext("Object")}: ${this.getModelInfo((this.event.context.request as EventContext).obj as EventContext)}</li>
|
2021-01-16 16:02:31 +00:00
|
|
|
<li><span>${gettext("Context")}: <code>${JSON.stringify((this.event.context.request as EventContext).context, null, 4)}</code></span></li>
|
2021-01-14 17:13:52 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Exception")}</h3>
|
2021-01-14 20:58:10 +00:00
|
|
|
<code>${this.event.context.message || this.event.context.error}</code>
|
2021-01-14 17:13:52 +00:00
|
|
|
</div>
|
2021-02-04 19:59:18 +00:00
|
|
|
</div>
|
|
|
|
<ak-expand>${this.defaultResponse()}</ak-expand>`;
|
2020-12-31 10:21:52 +00:00
|
|
|
case "policy_execution":
|
2020-12-31 10:34:30 +00:00
|
|
|
return html`<div class="pf-l-flex">
|
2021-01-05 10:52:18 +00:00
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Binding")}</h3>
|
|
|
|
${this.getModelInfo(this.event.context.binding as EventContext)}
|
|
|
|
</div>
|
2020-12-31 10:21:52 +00:00
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Request")}</h3>
|
|
|
|
<ul class="pf-c-list">
|
2021-01-05 10:52:18 +00:00
|
|
|
<li>${gettext("Object")}: ${this.getModelInfo((this.event.context.request as EventContext).obj as EventContext)}</li>
|
2021-01-16 16:02:31 +00:00
|
|
|
<li><span>${gettext("Context")}: <code>${JSON.stringify((this.event.context.request as EventContext).context, null, 4)}</code></span></li>
|
2020-12-31 10:21:52 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Result")}</h3>
|
|
|
|
<ul class="pf-c-list">
|
|
|
|
<li>${gettext("Passing")}: ${(this.event.context.result as EventContext).passing}</li>
|
|
|
|
<li>${gettext("Messages")}:
|
|
|
|
<ul class="pf-c-list">
|
|
|
|
${((this.event.context.result as EventContext).messages as string[]).map(msg => {
|
2021-02-04 19:59:18 +00:00
|
|
|
return html`<li>${msg}</li>`;
|
|
|
|
})}
|
2020-12-31 10:21:52 +00:00
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2021-02-04 19:59:18 +00:00
|
|
|
</div>
|
|
|
|
<ak-expand>${this.defaultResponse()}</ak-expand>`;
|
2020-12-28 13:26:41 +00:00
|
|
|
case "configuration_error":
|
2021-02-04 19:59:18 +00:00
|
|
|
return html`<h3>${this.event.context.message}</h3>
|
|
|
|
<ak-expand>${this.defaultResponse()}</ak-expand>`;
|
2020-12-28 13:26:41 +00:00
|
|
|
case "update_available":
|
|
|
|
return html`<h3>${gettext("New version available!")}</h3>
|
|
|
|
<a target="_blank" href="https://github.com/BeryJu/authentik/releases/tag/version%2F${this.event.context.new_version}">${this.event.context.new_version}</a>
|
|
|
|
`;
|
2021-02-04 19:59:18 +00:00
|
|
|
// Action types which typically don't record any extra context.
|
|
|
|
// If context is not empty, we fall to the default response.
|
2020-12-28 13:26:41 +00:00
|
|
|
case "login":
|
2021-01-12 21:48:55 +00:00
|
|
|
if ("using_source" in this.event.context) {
|
|
|
|
return html`<div class="pf-l-flex">
|
|
|
|
<div class="pf-l-flex__item">
|
|
|
|
<h3>${gettext("Using source")}</h3>
|
|
|
|
${this.getModelInfo(this.event.context.using_source as EventContext)}
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
return this.defaultResponse();
|
2020-12-28 13:26:41 +00:00
|
|
|
case "logout":
|
|
|
|
if (this.event.context === {}) {
|
|
|
|
return html`<span>${gettext("No additional data available.")}</span>`;
|
|
|
|
}
|
|
|
|
return this.defaultResponse();
|
|
|
|
default:
|
|
|
|
return this.defaultResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|