2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2020-12-28 13:26:41 +00:00
|
|
|
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
|
|
|
|
import { until } from "lit-html/directives/until";
|
2021-03-16 20:32:39 +00:00
|
|
|
import { FlowsApi } from "authentik-api";
|
2020-12-28 13:26:41 +00:00
|
|
|
import "../../elements/Spinner";
|
2021-02-04 19:59:18 +00:00
|
|
|
import "../../elements/Expand";
|
2021-04-04 20:04:46 +00:00
|
|
|
import { PFSize } from "../../elements/Spinner";
|
2021-03-08 10:14:00 +00:00
|
|
|
import { EventContext, EventWithContext } from "../../api/Events";
|
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
2020-12-28 13:26:41 +00:00
|
|
|
|
2021-03-17 16:11:39 +00:00
|
|
|
import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css";
|
|
|
|
import PFFlex from "@patternfly/patternfly/layouts/Flex/flex.css";
|
|
|
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
|
|
|
import PFList from "@patternfly/patternfly/components/List/list.css";
|
|
|
|
|
2020-12-28 13:26:41 +00:00
|
|
|
@customElement("ak-event-info")
|
|
|
|
export class EventInfo extends LitElement {
|
|
|
|
|
|
|
|
@property({attribute: false})
|
2021-03-08 10:14:00 +00:00
|
|
|
event!: EventWithContext;
|
2020-12-28 13:26:41 +00:00
|
|
|
|
|
|
|
static get styles(): CSSResult[] {
|
2021-03-17 16:11:39 +00:00
|
|
|
return [PFBase, PFFlex, PFList, PFDescriptionList,
|
2020-12-28 13:26:41 +00:00
|
|
|
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
|
|
|
`
|
2021-03-17 16:11:39 +00:00
|
|
|
];
|
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>`;
|
|
|
|
}
|
2021-02-16 22:19:01 +00:00
|
|
|
return html`<dl class="pf-c-description-list pf-m-horizontal">
|
|
|
|
<div class="pf-c-description-list__group">
|
|
|
|
<dt class="pf-c-description-list__term">
|
2021-04-03 17:26:43 +00:00
|
|
|
<span class="pf-c-description-list__text">${t`UID`}</span>
|
2021-02-16 22:19:01 +00:00
|
|
|
</dt>
|
|
|
|
<dd class="pf-c-description-list__description">
|
|
|
|
<div class="pf-c-description-list__text">${context.pk as string}</div>
|
|
|
|
</dd>
|
|
|
|
</div>
|
|
|
|
<div class="pf-c-description-list__group">
|
|
|
|
<dt class="pf-c-description-list__term">
|
2021-04-03 17:26:43 +00:00
|
|
|
<span class="pf-c-description-list__text">${t`Name`}</span>
|
2021-02-16 22:19:01 +00:00
|
|
|
</dt>
|
|
|
|
<dd class="pf-c-description-list__description">
|
|
|
|
<div class="pf-c-description-list__text">${context.name as string}</div>
|
|
|
|
</dd>
|
|
|
|
</div>
|
|
|
|
<div class="pf-c-description-list__group">
|
|
|
|
<dt class="pf-c-description-list__term">
|
2021-04-03 17:26:43 +00:00
|
|
|
<span class="pf-c-description-list__text">${t`App`}</span>
|
2021-02-16 22:19:01 +00:00
|
|
|
</dt>
|
|
|
|
<dd class="pf-c-description-list__description">
|
|
|
|
<div class="pf-c-description-list__text">${context.app as string}</div>
|
|
|
|
</dd>
|
|
|
|
</div>
|
|
|
|
<div class="pf-c-description-list__group">
|
|
|
|
<dt class="pf-c-description-list__term">
|
2021-04-03 17:26:43 +00:00
|
|
|
<span class="pf-c-description-list__text">${t`Model Name`}</span>
|
2021-02-16 22:19:01 +00:00
|
|
|
</dt>
|
|
|
|
<dd class="pf-c-description-list__description">
|
|
|
|
<div class="pf-c-description-list__text">${context.model_name as string}</div>
|
|
|
|
</dd>
|
|
|
|
</div>
|
|
|
|
</dl>`;
|
2020-12-28 13:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultResponse(): TemplateResult {
|
|
|
|
return html`<div class="pf-l-flex">
|
2021-03-08 10:14:00 +00:00
|
|
|
<div class="pf-l-flex__item">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Context`}</h3>
|
2021-03-08 10:14:00 +00:00
|
|
|
<code>${JSON.stringify(this.event?.context, null, 4)}</code>
|
|
|
|
</div>
|
|
|
|
<div class="pf-l-flex__item">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`User`}</h3>
|
2021-03-08 10:14:00 +00:00
|
|
|
<code>${JSON.stringify(this.event?.user, null, 4)}</code>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
2020-12-28 13:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render(): TemplateResult {
|
|
|
|
if (!this.event) {
|
2021-04-04 20:04:46 +00:00
|
|
|
return html`<ak-spinner size=${PFSize.Medium}></ak-spinner>`;
|
2020-12-28 13:26:41 +00:00
|
|
|
}
|
|
|
|
switch (this.event?.action) {
|
|
|
|
case "model_created":
|
|
|
|
case "model_updated":
|
|
|
|
case "model_deleted":
|
|
|
|
return html`
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Affected model:`}</h3>
|
2021-03-08 10:14:00 +00:00
|
|
|
${this.getModelInfo(this.event.context?.model as EventContext)}
|
2020-12-28 13:26:41 +00:00
|
|
|
`;
|
|
|
|
case "authorize_application":
|
|
|
|
return html`<div class="pf-l-flex">
|
|
|
|
<div class="pf-l-flex__item">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`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">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Using flow`}</h3>
|
2021-03-08 10:14:00 +00:00
|
|
|
<span>${until(new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({
|
|
|
|
flowUuid: this.event.context.flow as string,
|
2021-02-04 19:48:16 +00:00
|
|
|
}).then(resp => {
|
2021-02-19 18:29:17 +00:00
|
|
|
return html`<a href="#/flow/flows/${resp.results[0].slug}">${resp.results[0].name}</a>`;
|
2021-04-04 20:04:46 +00:00
|
|
|
}), html`<ak-spinner size=${PFSize.Medium}></ak-spinner>`)}
|
2021-02-04 19:48:16 +00:00
|
|
|
</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`
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`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-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Secret:`}</h3>
|
2021-02-09 19:10:43 +00:00
|
|
|
${this.getModelInfo(this.event.context.secret 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">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`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">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Expression`}</h3>
|
2020-12-28 13:26:41 +00:00
|
|
|
<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">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Binding`}</h3>
|
2021-01-14 17:13:52 +00:00
|
|
|
${this.getModelInfo(this.event.context.binding as EventContext)}
|
|
|
|
</div>
|
|
|
|
<div class="pf-l-flex__item">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Request`}</h3>
|
2021-01-14 17:13:52 +00:00
|
|
|
<ul class="pf-c-list">
|
2021-04-03 17:26:43 +00:00
|
|
|
<li>${t`Object`}: ${this.getModelInfo((this.event.context.request as EventContext).obj as EventContext)}</li>
|
|
|
|
<li><span>${t`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">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`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">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Binding`}</h3>
|
2021-01-05 10:52:18 +00:00
|
|
|
${this.getModelInfo(this.event.context.binding as EventContext)}
|
|
|
|
</div>
|
2020-12-31 10:21:52 +00:00
|
|
|
<div class="pf-l-flex__item">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Request`}</h3>
|
2020-12-31 10:21:52 +00:00
|
|
|
<ul class="pf-c-list">
|
2021-04-03 17:26:43 +00:00
|
|
|
<li>${t`Object`}: ${this.getModelInfo((this.event.context.request as EventContext).obj as EventContext)}</li>
|
|
|
|
<li><span>${t`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">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Result`}</h3>
|
2020-12-31 10:21:52 +00:00
|
|
|
<ul class="pf-c-list">
|
2021-04-03 17:26:43 +00:00
|
|
|
<li>${t`Passing`}: ${(this.event.context.result as EventContext).passing}</li>
|
|
|
|
<li>${t`Messages`}:
|
2020-12-31 10:21:52 +00:00
|
|
|
<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":
|
2021-04-03 17:26:43 +00:00
|
|
|
return html`<h3>${t`New version available!`}</h3>
|
2021-04-21 20:46:48 +00:00
|
|
|
<a target="_blank" href="https://github.com/goauthentik/authentik/releases/tag/version%2F${this.event.context.new_version}">${this.event.context.new_version}</a>
|
2020-12-28 13:26:41 +00:00
|
|
|
`;
|
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">
|
2021-04-03 17:26:43 +00:00
|
|
|
<h3>${t`Using source`}</h3>
|
2021-01-12 21:48:55 +00:00
|
|
|
${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 === {}) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return html`<span>${t`No additional data available.`}</span>`;
|
2020-12-28 13:26:41 +00:00
|
|
|
}
|
|
|
|
return this.defaultResponse();
|
|
|
|
default:
|
|
|
|
return this.defaultResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|