mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-02 08:58:52 +00:00
chore!: Introduce ZITADEL v3 (#9645)
This PR summarizes multiple changes specifically only available with ZITADEL v3: - feat: Web Keys management (https://github.com/zitadel/zitadel/pull/9526) - fix(cmd): ensure proper working of mirror (https://github.com/zitadel/zitadel/pull/9509) - feat(Authz): system user support for permission check v2 (https://github.com/zitadel/zitadel/pull/9640) - chore(license): change from Apache to AGPL (https://github.com/zitadel/zitadel/pull/9597) - feat(console): list v2 sessions (https://github.com/zitadel/zitadel/pull/9539) - fix(console): add loginV2 feature flag (https://github.com/zitadel/zitadel/pull/9682) - fix(feature flags): allow reading "own" flags (https://github.com/zitadel/zitadel/pull/9649) - feat(console): add Actions V2 UI (https://github.com/zitadel/zitadel/pull/9591) BREAKING CHANGE - feat(webkey): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9445) - chore!: remove CockroachDB Support (https://github.com/zitadel/zitadel/pull/9444) - feat(actions): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9489) --------- Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Stefan Benz <[email protected]> Co-authored-by: Silvan <[email protected]> Co-authored-by: Ramon <[email protected]> Co-authored-by: Elio Bischof <[email protected]> Co-authored-by: Kenta Yamaguchi <[email protected]> Co-authored-by: Harsha Reddy <[email protected]> Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Max Peintner <[email protected]> Co-authored-by: Iraq <[email protected]> Co-authored-by: Florian Forster <[email protected]> Co-authored-by: Tim Möhlmann <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Max Peintner <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
Stefan Benz
Silvan
Ramon
Elio Bischof
Kenta Yamaguchi
Harsha Reddy
Livio Spring
Max Peintner
Iraq
Florian Forster
Tim Möhlmann
Copilot
Max Peintner
parent
d14a23ae7e
commit
07ce3b6905
+60
@@ -0,0 +1,60 @@
|
||||
<cnsl-card
|
||||
[title]="'DESCRIPTIONS.SETTINGS.WEB_KEYS.CREATE.TITLE' | translate"
|
||||
[description]="'DESCRIPTIONS.SETTINGS.WEB_KEYS.CREATE.DESCRIPTION' | translate"
|
||||
>
|
||||
<cnsl-form-field>
|
||||
<cnsl-label>{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.CREATE.KEY_TYPE' | translate }}</cnsl-label>
|
||||
<mat-select [value]="keyType()" (valueChange)="keyType.set($event)">
|
||||
<mat-option value="rsa">RSA</mat-option>
|
||||
<mat-option value="ecdsa">ECDSA</mat-option>
|
||||
<mat-option value="ed25519">ED25519</mat-option>
|
||||
</mat-select>
|
||||
</cnsl-form-field>
|
||||
<ng-container [ngSwitch]="keyType()">
|
||||
<form *ngSwitchCase="'rsa'" [formGroup]="rsaForm" (ngSubmit)="ngSubmit.emit(rsaForm.getRawValue())">
|
||||
<cnsl-form-field>
|
||||
<cnsl-label>{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.CREATE.BITS' | translate }}</cnsl-label>
|
||||
<mat-select formControlName="bits">
|
||||
<ng-container *ngFor="let bit of RSABits | keyvalue">
|
||||
<mat-option *ngIf="Number(bit.key) as key" [value]="key">{{
|
||||
$any(bit.value).replace('RSA_BITS_', '')
|
||||
}}</mat-option>
|
||||
</ng-container>
|
||||
</mat-select>
|
||||
</cnsl-form-field>
|
||||
<cnsl-form-field>
|
||||
<cnsl-label>{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.CREATE.HASHER' | translate }}</cnsl-label>
|
||||
<mat-select formControlName="hasher">
|
||||
<ng-container *ngFor="let hasher of RSAHasher | keyvalue">
|
||||
<mat-option *ngIf="Number(hasher.key) as key" [value]="key">{{
|
||||
$any(hasher.value).replace('RSA_HASHER_', '')
|
||||
}}</mat-option>
|
||||
</ng-container>
|
||||
</mat-select>
|
||||
</cnsl-form-field>
|
||||
<ng-container *ngTemplateOutlet="submitButton; context: { form: rsaForm }" />
|
||||
</form>
|
||||
<form *ngSwitchCase="'ecdsa'" [formGroup]="ecdsaForm" (ngSubmit)="ngSubmit.emit(ecdsaForm.getRawValue())">
|
||||
<cnsl-form-field>
|
||||
<cnsl-label>{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.CREATE.CURVE' | translate }}</cnsl-label>
|
||||
<mat-select formControlName="curve">
|
||||
<ng-container *ngFor="let curve of ECDSACurve | keyvalue">
|
||||
<mat-option *ngIf="Number(curve.key) as key" [value]="key">{{
|
||||
$any(curve.value).replace('ECDSA_CURVE_', '')
|
||||
}}</mat-option>
|
||||
</ng-container>
|
||||
</mat-select>
|
||||
</cnsl-form-field>
|
||||
<ng-container *ngTemplateOutlet="submitButton; context: { form: ecdsaForm }" />
|
||||
</form>
|
||||
<form *ngSwitchCase="'ed25519'" (submit)="emitEd25519($event)">
|
||||
<ng-container *ngTemplateOutlet="submitButton" />
|
||||
</form>
|
||||
<ng-template #submitButton let-form="form">
|
||||
<button [disabled]="(loading$ | async) || form?.invalid" mat-raised-button color="primary" type="submit">
|
||||
<mat-spinner diameter="20" *ngIf="loading$ | async"></mat-spinner>
|
||||
<span *ngIf="(loading$ | async) === false || (loading$ | async) === null">{{ 'ACTIONS.CREATE' | translate }}</span>
|
||||
</button>
|
||||
</ng-template>
|
||||
</ng-container>
|
||||
</cnsl-card>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, signal, WritableSignal } from '@angular/core';
|
||||
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
import { WebKey } from '@zitadel/proto/zitadel/webkey/v2beta/key_pb';
|
||||
import { ReplaySubject } from 'rxjs';
|
||||
import { RSAHasher, RSABits, ECDSACurve } from '@zitadel/proto/zitadel/webkey/v2beta/key_pb';
|
||||
|
||||
type RawValue<T extends FormGroup> = ReturnType<T['getRawValue']>;
|
||||
|
||||
@Component({
|
||||
selector: 'cnsl-oidc-webkeys-create',
|
||||
templateUrl: './oidc-webkeys-create.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class OidcWebKeysCreateComponent {
|
||||
protected readonly keyType: WritableSignal<NonNullable<WebKey['key']['case']>> = signal('rsa');
|
||||
protected readonly RSAHasher = RSAHasher;
|
||||
protected readonly RSABits = RSABits;
|
||||
protected readonly ECDSACurve = ECDSACurve;
|
||||
protected readonly Number = Number;
|
||||
protected readonly rsaForm = this.buildRsaForm();
|
||||
protected readonly ecdsaForm = this.buildEcdsaForm();
|
||||
protected readonly loading$ = new ReplaySubject<boolean>();
|
||||
|
||||
@Output()
|
||||
public readonly ngSubmit = new EventEmitter<RawValue<typeof this.rsaForm> | RawValue<typeof this.ecdsaForm> | void>();
|
||||
|
||||
@Input()
|
||||
public set loading(loading: boolean) {
|
||||
this.loading$.next(loading);
|
||||
}
|
||||
|
||||
constructor(private readonly fb: FormBuilder) {}
|
||||
|
||||
private buildRsaForm() {
|
||||
return this.fb.group({
|
||||
bits: new FormControl<RSABits>(RSABits.RSA_BITS_2048, {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
hasher: new FormControl<RSAHasher>(RSAHasher.RSA_HASHER_SHA256, {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
private buildEcdsaForm() {
|
||||
return this.fb.group({
|
||||
curve: new FormControl<ECDSACurve>(ECDSACurve.ECDSA_CURVE_P256, {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
protected emitEd25519(event: SubmitEvent) {
|
||||
event.preventDefault();
|
||||
this.ngSubmit.emit();
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<cnsl-card
|
||||
[title]="'DESCRIPTIONS.SETTINGS.WEB_KEYS.PREVIOUS_TABLE.TITLE' | translate"
|
||||
[description]="'DESCRIPTIONS.SETTINGS.WEB_KEYS.PREVIOUS_TABLE.DESCRIPTION' | translate"
|
||||
>
|
||||
<cnsl-refresh-table [hideRefresh]="true" [loading]="(dataSource$ | async) === null">
|
||||
<div class="table-wrapper">
|
||||
<table
|
||||
*ngIf="dataSource$ | async as dataSource"
|
||||
mat-table
|
||||
class="table"
|
||||
aria-label="Elements"
|
||||
[dataSource]="dataSource"
|
||||
>
|
||||
<ng-container matColumnDef="timestamp">
|
||||
<th mat-header-cell *matHeaderCellDef>
|
||||
{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.PREVIOUS_TABLE.DEACTIVATED_ON' | translate }}
|
||||
</th>
|
||||
<td mat-cell *cnslCellDef="let row; dataSource: dataSource">
|
||||
{{ row.changeDate | timestampToDate | localizedDate: 'EEE dd. MMM, HH:mm' }}
|
||||
</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="id">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ 'APP.PAGES.ID' | translate }}</th>
|
||||
<td mat-cell *cnslCellDef="let row; dataSource: dataSource">
|
||||
{{ row.id }}
|
||||
</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="type">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ 'PROJECT.TYPE.TITLE' | translate }}</th>
|
||||
<td mat-cell *cnslCellDef="let row; dataSource: dataSource">
|
||||
{{ row.key.case | uppercase }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="['timestamp', 'id', 'type']"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: ['timestamp', 'id', 'type']"></tr>
|
||||
</table>
|
||||
</div>
|
||||
</cnsl-refresh-table>
|
||||
</cnsl-card>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
|
||||
import { ReplaySubject } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { WebKey } from '@zitadel/proto/zitadel/webkey/v2beta/key_pb';
|
||||
|
||||
@Component({
|
||||
selector: 'cnsl-oidc-webkeys-inactive-table',
|
||||
templateUrl: './oidc-webkeys-inactive-table.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class OidcWebKeysInactiveTableComponent {
|
||||
@Input({ required: true })
|
||||
public set InactiveWebKeys(webKeys: WebKey[] | null) {
|
||||
this.inactiveWebKeys$.next(webKeys);
|
||||
}
|
||||
|
||||
private inactiveWebKeys$ = new ReplaySubject<WebKey[] | null>(1);
|
||||
protected dataSource$ = this.inactiveWebKeys$.pipe(
|
||||
filter(Boolean),
|
||||
map((webKeys) => new MatTableDataSource(webKeys)),
|
||||
);
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<cnsl-refresh-table (refreshed)="refresh.emit()" [loading]="(dataSource$ | async) === null">
|
||||
<div actions>
|
||||
<ng-content></ng-content>
|
||||
</div>
|
||||
<div class="table-wrapper">
|
||||
<table *ngIf="dataSource$ | async as dataSource" mat-table class="table" aria-label="Elements" [dataSource]="dataSource">
|
||||
<ng-container matColumnDef="state">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ 'APP.PAGES.STATE' | translate }}</th>
|
||||
<td mat-cell *cnslCellDef="let row; let i = index; dataSource: dataSource">
|
||||
<span
|
||||
class="state"
|
||||
[ngClass]="{
|
||||
active: i === 0,
|
||||
neutral: i === 1,
|
||||
}"
|
||||
[ngSwitch]="i"
|
||||
>
|
||||
<ng-container *ngSwitchCase="0">{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.TABLE.ACTIVE' | translate }}</ng-container>
|
||||
<ng-container *ngSwitchCase="1">{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.TABLE.NEXT' | translate }}</ng-container>
|
||||
<ng-container *ngSwitchDefault>{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.TABLE.FUTURE' | translate }}</ng-container>
|
||||
</span>
|
||||
</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="id">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ 'APP.PAGES.ID' | translate }}</th>
|
||||
<td mat-cell *cnslCellDef="let row; dataSource: dataSource">
|
||||
{{ row.id }}
|
||||
</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="type">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ 'PROJECT.TYPE.TITLE' | translate }}</th>
|
||||
<td mat-cell *cnslCellDef="let row; dataSource: dataSource">
|
||||
{{ row.key.case | uppercase }}
|
||||
</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="actions" stickyEnd>
|
||||
<th mat-header-cell *matHeaderCellDef></th>
|
||||
<td mat-cell *cnslCellDef="let row; dataSource: dataSource">
|
||||
<cnsl-table-actions *ngIf="row.state === State.INITIAL">
|
||||
<button
|
||||
actions
|
||||
matTooltip="{{ 'ACTIONS.REMOVE' | translate }}"
|
||||
color="warn"
|
||||
(click)="delete.emit(row)"
|
||||
mat-icon-button
|
||||
>
|
||||
<i class="las la-trash"></i>
|
||||
</button>
|
||||
</cnsl-table-actions>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="['state', 'id', 'type', 'actions']"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: ['state', 'id', 'type', 'actions']"></tr>
|
||||
</table>
|
||||
</div>
|
||||
</cnsl-refresh-table>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
.state.next {
|
||||
color: #0e6245;
|
||||
border: 1px solid #0e6245;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { ReplaySubject } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { State, WebKey } from '@zitadel/proto/zitadel/webkey/v2beta/key_pb';
|
||||
|
||||
@Component({
|
||||
selector: 'cnsl-oidc-webkeys-table',
|
||||
templateUrl: './oidc-webkeys-table.component.html',
|
||||
styleUrls: ['./oidc-webkeys-table.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class OidcWebKeysTableComponent {
|
||||
@Output()
|
||||
public readonly refresh = new EventEmitter<void>();
|
||||
|
||||
@Output()
|
||||
public readonly delete = new EventEmitter<WebKey>();
|
||||
|
||||
@Input({ required: true })
|
||||
public set webKeys(webKeys: WebKey[] | null) {
|
||||
this.webKeys$.next(webKeys);
|
||||
}
|
||||
|
||||
private readonly webKeys$ = new ReplaySubject<WebKey[] | null>(1);
|
||||
protected readonly dataSource$ = this.webKeys$.pipe(
|
||||
filter(Boolean),
|
||||
map((keys) => new MatTableDataSource(keys)),
|
||||
);
|
||||
protected readonly State = State;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<h2>{{ 'SETTINGS.LIST.WEB_KEYS' | translate }}</h2>
|
||||
<p>{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.DESCRIPTION' | translate }}</p>
|
||||
<h3>{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.TABLE.TITLE' | translate }}</h3>
|
||||
<p>{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.TABLE.DESCRIPTION' | translate }}</p>
|
||||
<p>{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.TABLE.NOTE' | translate }}</p>
|
||||
<cnsl-oidc-webkeys-table (refresh)="refresh.next(true)" (delete)="deleteWebKey($event)" [webKeys]="webKeys$ | async">
|
||||
<button
|
||||
*ngIf="nextWebKeyCandidate$ | async as nextWebKeyCandidate"
|
||||
[disabled]="activateLoading()"
|
||||
mat-raised-button
|
||||
color="primary"
|
||||
(click)="activateWebKey(nextWebKeyCandidate)"
|
||||
>
|
||||
<mat-spinner diameter="20" *ngIf="activateLoading()"></mat-spinner>
|
||||
<span *ngIf="!activateLoading()">{{ 'DESCRIPTIONS.SETTINGS.WEB_KEYS.TABLE.ACTIVATE' | translate }}</span>
|
||||
</button>
|
||||
</cnsl-oidc-webkeys-table>
|
||||
<cnsl-oidc-webkeys-create [loading]="createLoading()" (ngSubmit)="createWebKey($event)" />
|
||||
<cnsl-oidc-webkeys-inactive-table [InactiveWebKeys]="inactiveWebKeys$ | async" />
|
||||
@@ -0,0 +1,217 @@
|
||||
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, signal } from '@angular/core';
|
||||
import { WebKeysService } from 'src/app/services/webkeys.service';
|
||||
import { defer, EMPTY, firstValueFrom, Observable, ObservedValueOf, of, shareReplay, Subject, switchMap } from 'rxjs';
|
||||
import { catchError, map, startWith, withLatestFrom } from 'rxjs/operators';
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
import { MessageInitShape } from '@bufbuild/protobuf';
|
||||
import { OidcWebKeysCreateComponent } from './oidc-webkeys-create/oidc-webkeys-create.component';
|
||||
import { TimestampToDatePipe } from 'src/app/pipes/timestamp-to-date-pipe/timestamp-to-date.pipe';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { WarnDialogComponent } from 'src/app/modules/warn-dialog/warn-dialog.component';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { State, WebKey } from '@zitadel/proto/zitadel/webkey/v2beta/key_pb';
|
||||
import { CreateWebKeyRequestSchema } from '@zitadel/proto/zitadel/webkey/v2beta/webkey_service_pb';
|
||||
import { RSAHasher, RSABits, ECDSACurve } from '@zitadel/proto/zitadel/webkey/v2beta/key_pb';
|
||||
import { NewFeatureService } from 'src/app/services/new-feature.service';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
const CACHE_WARNING_MS = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
@Component({
|
||||
selector: 'cnsl-oidc-webkeys',
|
||||
templateUrl: './oidc-webkeys.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class OidcWebKeysComponent implements OnInit {
|
||||
protected readonly refresh = new Subject<true>();
|
||||
protected readonly webKeysEnabled$: Observable<boolean>;
|
||||
protected readonly webKeys$: Observable<WebKey[]>;
|
||||
protected readonly inactiveWebKeys$: Observable<WebKey[]>;
|
||||
protected readonly nextWebKeyCandidate$: Observable<WebKey | undefined>;
|
||||
|
||||
protected readonly activateLoading = signal(false);
|
||||
protected readonly createLoading = signal(false);
|
||||
|
||||
constructor(
|
||||
private readonly webKeysService: WebKeysService,
|
||||
private readonly featureService: NewFeatureService,
|
||||
private readonly toast: ToastService,
|
||||
private readonly timestampToDatePipe: TimestampToDatePipe,
|
||||
private readonly dialog: MatDialog,
|
||||
private readonly destroyRef: DestroyRef,
|
||||
private readonly router: Router,
|
||||
private readonly route: ActivatedRoute,
|
||||
) {
|
||||
this.webKeysEnabled$ = this.getWebKeysEnabled().pipe(shareReplay({ refCount: true, bufferSize: 1 }));
|
||||
|
||||
const webKeys$ = this.getWebKeys(this.webKeysEnabled$).pipe(shareReplay({ refCount: true, bufferSize: 1 }));
|
||||
|
||||
this.webKeys$ = webKeys$.pipe(map((webKeys) => webKeys.filter((webKey) => webKey.state !== State.INACTIVE)));
|
||||
this.inactiveWebKeys$ = webKeys$.pipe(map((webKeys) => webKeys.filter((webKey) => webKey.state === State.INACTIVE)));
|
||||
|
||||
this.nextWebKeyCandidate$ = this.getNextWebKeyCandidate(this.webKeys$);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
// redirect away from this page if web keys are not enabled
|
||||
// this also preloads the web keys enabled state
|
||||
this.webKeysEnabled$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(async (webKeysEnabled) => {
|
||||
if (webKeysEnabled) {
|
||||
return;
|
||||
}
|
||||
await this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParamsHandling: 'merge',
|
||||
queryParams: {
|
||||
id: null,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private getWebKeysEnabled() {
|
||||
return defer(() => this.featureService.getInstanceFeatures()).pipe(
|
||||
map((features) => features.webKey?.enabled ?? false),
|
||||
catchError((err) => {
|
||||
this.toast.showError(err);
|
||||
return of(false);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
private getWebKeys(webKeysEnabled$: Observable<boolean>) {
|
||||
return this.refresh.pipe(
|
||||
startWith(true),
|
||||
switchMap(() => {
|
||||
return this.webKeysService.ListWebKeys();
|
||||
}),
|
||||
map(({ webKeys }) => webKeys),
|
||||
catchError(async (err) => {
|
||||
const webKeysEnabled = await firstValueFrom(webKeysEnabled$);
|
||||
// suppress errors if web keys are not enabled
|
||||
if (!webKeysEnabled) {
|
||||
return [];
|
||||
}
|
||||
|
||||
this.toast.showError(err);
|
||||
return [];
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
private getNextWebKeyCandidate(webKeys$: Observable<WebKey[]>) {
|
||||
return webKeys$.pipe(
|
||||
map((webKeys) => {
|
||||
if (webKeys.length < 2) {
|
||||
return undefined;
|
||||
}
|
||||
const [webKey, nextWebKey] = webKeys;
|
||||
if (webKey.state !== State.ACTIVE) {
|
||||
return undefined;
|
||||
}
|
||||
if (nextWebKey.state !== State.INITIAL) {
|
||||
return undefined;
|
||||
}
|
||||
return nextWebKey;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
protected async createWebKey(event: ObservedValueOf<OidcWebKeysCreateComponent['ngSubmit']>) {
|
||||
try {
|
||||
this.createLoading.set(true);
|
||||
|
||||
const req = !event
|
||||
? this.createEd25519()
|
||||
: 'curve' in event
|
||||
? this.createEcdsa(event.curve)
|
||||
: this.createRsa(event.bits, event.hasher);
|
||||
await this.webKeysService.CreateWebKey(req);
|
||||
|
||||
this.refresh.next(true);
|
||||
} catch (error) {
|
||||
this.toast.showError(error);
|
||||
} finally {
|
||||
this.createLoading.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
private createEd25519(): MessageInitShape<typeof CreateWebKeyRequestSchema> {
|
||||
return {
|
||||
key: {
|
||||
case: 'ed25519',
|
||||
value: {},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private createEcdsa(curve: ECDSACurve): MessageInitShape<typeof CreateWebKeyRequestSchema> {
|
||||
return {
|
||||
key: {
|
||||
case: 'ecdsa',
|
||||
value: {
|
||||
curve,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private createRsa(bits: RSABits, hasher: RSAHasher): MessageInitShape<typeof CreateWebKeyRequestSchema> {
|
||||
return {
|
||||
key: {
|
||||
case: 'rsa',
|
||||
value: {
|
||||
bits,
|
||||
hasher,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
protected async deleteWebKey(row: WebKey) {
|
||||
try {
|
||||
await this.webKeysService.DeleteWebKey(row.id);
|
||||
this.refresh.next(true);
|
||||
} catch (err) {
|
||||
this.toast.showError(err);
|
||||
}
|
||||
}
|
||||
|
||||
protected async activateWebKey(nextWebKey: WebKey) {
|
||||
try {
|
||||
this.activateLoading.set(true);
|
||||
const creationDate = this.timestampToDatePipe.transform(nextWebKey.creationDate);
|
||||
if (!creationDate) {
|
||||
// noinspection ExceptionCaughtLocallyJS
|
||||
throw new Error('Invalid creation date');
|
||||
}
|
||||
|
||||
const diffToCurrentTime = Date.now() - creationDate.getTime();
|
||||
if (diffToCurrentTime < CACHE_WARNING_MS && !(await this.openCacheWarnDialog())) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.webKeysService.ActivateWebKey(nextWebKey.id);
|
||||
this.refresh.next(true);
|
||||
} catch (error) {
|
||||
this.toast.showError(error);
|
||||
} finally {
|
||||
this.activateLoading.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
private openCacheWarnDialog() {
|
||||
const dialogRef = this.dialog.open(WarnDialogComponent, {
|
||||
data: {
|
||||
confirmKey: 'DESCRIPTIONS.SETTINGS.WEB_KEYS.TABLE.ACTIVATE',
|
||||
cancelKey: 'ACTIONS.CANCEL',
|
||||
titleKey: 'Web Key is less then 5 min old',
|
||||
descriptionKey: 'DESCRIPTIONS.SETTINGS.WEB_KEYS.TABLE.NOTE',
|
||||
},
|
||||
width: '400px',
|
||||
});
|
||||
|
||||
const obs = dialogRef.afterClosed().pipe(map(Boolean), takeUntilDestroyed(this.destroyRef));
|
||||
return firstValueFrom(obs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { OidcWebKeysComponent } from './oidc-webkeys.component';
|
||||
import { RefreshTableModule } from 'src/app/modules/refresh-table/refresh-table.module';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { TableActionsModule } from 'src/app/modules/table-actions/table-actions.module';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { ActionKeysModule } from 'src/app/modules/action-keys/action-keys.module';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { FormFieldModule } from 'src/app/modules/form-field/form-field.module';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { CardModule } from 'src/app/modules/card/card.module';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { OidcWebKeysCreateComponent } from './oidc-webkeys-create/oidc-webkeys-create.component';
|
||||
import { OidcWebKeysTableComponent } from './oidc-webkeys-table/oidc-webkeys-table.component';
|
||||
import { TimestampToDatePipeModule } from 'src/app/pipes/timestamp-to-date-pipe/timestamp-to-date-pipe.module';
|
||||
import { LocalizedDatePipeModule } from 'src/app/pipes/localized-date-pipe/localized-date-pipe.module';
|
||||
import { OidcWebKeysInactiveTableComponent } from './oidc-webkeys-inactive-table/oidc-webkeys-inactive-table.component';
|
||||
import { TypeSafeCellDefDirective } from './type-safe-cell-def.directive';
|
||||
import { TimestampToDatePipe } from '../../../pipes/timestamp-to-date-pipe/timestamp-to-date.pipe';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
OidcWebKeysComponent,
|
||||
OidcWebKeysCreateComponent,
|
||||
OidcWebKeysTableComponent,
|
||||
OidcWebKeysInactiveTableComponent,
|
||||
TypeSafeCellDefDirective,
|
||||
],
|
||||
providers: [TimestampToDatePipe],
|
||||
imports: [
|
||||
CommonModule,
|
||||
TranslateModule,
|
||||
RefreshTableModule,
|
||||
MatCheckboxModule,
|
||||
MatTableModule,
|
||||
MatMenuModule,
|
||||
TableActionsModule,
|
||||
MatButtonModule,
|
||||
ActionKeysModule,
|
||||
MatIconModule,
|
||||
FormFieldModule,
|
||||
MatSelectModule,
|
||||
ReactiveFormsModule,
|
||||
CardModule,
|
||||
MatProgressSpinnerModule,
|
||||
TimestampToDatePipeModule,
|
||||
LocalizedDatePipeModule,
|
||||
MatTooltipModule,
|
||||
],
|
||||
exports: [OidcWebKeysComponent],
|
||||
})
|
||||
export class OidcWebkeysModule {}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Directive, Input } from '@angular/core';
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { MatCellDef } from '@angular/material/table';
|
||||
import { CdkCellDef } from '@angular/cdk/table';
|
||||
|
||||
@Directive({
|
||||
selector: '[cnslCellDef]',
|
||||
providers: [{ provide: CdkCellDef, useExisting: TypeSafeCellDefDirective }],
|
||||
})
|
||||
export class TypeSafeCellDefDirective<T> extends MatCellDef {
|
||||
@Input({ required: true }) cnslCellDefDataSource!: DataSource<T>;
|
||||
|
||||
static ngTemplateContextGuard<T>(_dir: TypeSafeCellDefDirective<T>, _ctx: any): _ctx is { $implicit: T; index: number } {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user