feat: directly specify factors/idps on addCustomLoginPolicy and return on LoginPolicy responses (#3711)

* feat: directly specify factors on addCustomLoginPolicy and return on LoginPolicy responses

* fix proto

* update login policy

* feat: directly specify idp on addCustomLoginPolicy and return on LoginPolicy responses

* fix: tests

Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Fabi <38692350+hifabienne@users.noreply.github.com>
This commit is contained in:
Livio Amstutz
2022-05-30 13:51:07 +02:00
committed by GitHub
parent 2fc39c0da0
commit b3f50702f8
19 changed files with 494 additions and 142 deletions

View File

@@ -3,7 +3,7 @@
</div>
<div class="login-policy-mfa-list">
<div class="mfa" *ngFor="let mfa of mfas">
<div class="mfa" *ngFor="let mfa of list">
<span>
{{
(componentType === LoginMethodComponentType.SecondFactor

View File

@@ -1,4 +1,4 @@
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatPaginator } from '@angular/material/paginator';
import { TranslateService } from '@ngx-translate/core';
@@ -34,14 +34,15 @@ export enum LoginMethodComponentType {
templateUrl: './factor-table.component.html',
styleUrls: ['./factor-table.component.scss'],
})
export class FactorTableComponent implements OnInit {
export class FactorTableComponent {
public LoginMethodComponentType: any = LoginMethodComponentType;
@Input() componentType!: LoginMethodComponentType;
@Input() public serviceType!: PolicyComponentServiceType;
@Input() service!: AdminService | ManagementService;
@Input() disabled: boolean = false;
@Input() list: Array<MultiFactorType | SecondFactorType> = [];
@Output() listChanged: EventEmitter<void> = new EventEmitter();
@ViewChild(MatPaginator) public paginator!: MatPaginator;
public mfas: Array<MultiFactorType | SecondFactorType> = [];
private loadingSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
public loading$: Observable<boolean> = this.loadingSubject.asObservable();
@@ -50,10 +51,6 @@ export class FactorTableComponent implements OnInit {
constructor(public translate: TranslateService, private toast: ToastService, private dialog: MatDialog) {}
public ngOnInit(): void {
this.getData();
}
public removeMfa(type: MultiFactorType | SecondFactorType): void {
const dialogRef = this.dialog.open(WarnDialogComponent, {
data: {
@@ -73,14 +70,14 @@ export class FactorTableComponent implements OnInit {
req.setType(type as MultiFactorType);
(this.service as ManagementService).removeMultiFactorFromLoginPolicy(req).then(() => {
this.toast.showInfo('MFA.TOAST.DELETED', true);
this.refreshPageAfterTimout(2000);
this.listChanged.emit();
});
} else if (this.componentType === LoginMethodComponentType.SecondFactor) {
const req = new MgmtRemoveSecondFactorFromLoginPolicyRequest();
req.setType(type as SecondFactorType);
(this.service as ManagementService).removeSecondFactorFromLoginPolicy(req).then(() => {
this.toast.showInfo('MFA.TOAST.DELETED', true);
this.refreshPageAfterTimout(2000);
this.listChanged.emit();
});
}
} else if (this.serviceType === PolicyComponentServiceType.ADMIN) {
@@ -89,14 +86,14 @@ export class FactorTableComponent implements OnInit {
req.setType(type as MultiFactorType);
(this.service as AdminService).removeMultiFactorFromLoginPolicy(req).then(() => {
this.toast.showInfo('MFA.TOAST.DELETED', true);
this.refreshPageAfterTimout(2000);
this.listChanged.emit();
});
} else if (this.componentType === LoginMethodComponentType.SecondFactor) {
const req = new AdminRemoveSecondFactorFromLoginPolicyRequest();
req.setType(type as SecondFactorType);
(this.service as AdminService).removeSecondFactorFromLoginPolicy(req).then(() => {
this.toast.showInfo('MFA.TOAST.DELETED', true);
this.refreshPageAfterTimout(2000);
this.listChanged.emit();
});
}
}
@@ -124,7 +121,8 @@ export class FactorTableComponent implements OnInit {
(this.service as ManagementService)
.addMultiFactorToLoginPolicy(req)
.then(() => {
this.refreshPageAfterTimout(2000);
this.toast.showInfo('MFA.TOAST.ADDED', true);
this.listChanged.emit();
})
.catch((error) => {
this.toast.showError(error);
@@ -135,7 +133,8 @@ export class FactorTableComponent implements OnInit {
(this.service as ManagementService)
.addSecondFactorToLoginPolicy(req)
.then(() => {
this.refreshPageAfterTimout(2000);
this.toast.showInfo('MFA.TOAST.ADDED', true);
this.listChanged.emit();
})
.catch((error) => {
this.toast.showError(error);
@@ -148,7 +147,8 @@ export class FactorTableComponent implements OnInit {
(this.service as AdminService)
.addMultiFactorToLoginPolicy(req)
.then(() => {
this.refreshPageAfterTimout(2000);
this.toast.showInfo('MFA.TOAST.ADDED', true);
this.listChanged.emit();
})
.catch((error) => {
this.toast.showError(error);
@@ -159,7 +159,8 @@ export class FactorTableComponent implements OnInit {
(this.service as AdminService)
.addSecondFactorToLoginPolicy(req)
.then(() => {
this.refreshPageAfterTimout(2000);
this.toast.showInfo('MFA.TOAST.ADDED', true);
this.listChanged.emit();
})
.catch((error) => {
this.toast.showError(error);
@@ -170,66 +171,6 @@ export class FactorTableComponent implements OnInit {
});
}
private async getData(): Promise<void> {
this.loadingSubject.next(true);
if (this.serviceType === PolicyComponentServiceType.MGMT) {
if (this.componentType === LoginMethodComponentType.MultiFactor) {
(this.service as ManagementService)
.listLoginPolicyMultiFactors()
.then((resp) => {
this.mfas = resp.resultList;
this.loadingSubject.next(false);
})
.catch((error) => {
this.toast.showError(error);
this.loadingSubject.next(false);
});
} else if (this.componentType === LoginMethodComponentType.SecondFactor) {
(this.service as ManagementService)
.listLoginPolicySecondFactors()
.then((resp) => {
this.mfas = resp.resultList;
this.loadingSubject.next(false);
})
.catch((error) => {
this.toast.showError(error);
this.loadingSubject.next(false);
});
}
} else if (this.serviceType === PolicyComponentServiceType.ADMIN) {
if (this.componentType === LoginMethodComponentType.MultiFactor) {
(this.service as AdminService)
.listLoginPolicyMultiFactors()
.then((resp) => {
this.mfas = resp.resultList;
this.loadingSubject.next(false);
})
.catch((error) => {
this.toast.showError(error);
this.loadingSubject.next(false);
});
} else if (this.componentType === LoginMethodComponentType.SecondFactor) {
(this.service as AdminService)
.listLoginPolicySecondFactors()
.then((resp) => {
this.mfas = resp.resultList;
this.loadingSubject.next(false);
})
.catch((error) => {
this.toast.showError(error);
this.loadingSubject.next(false);
});
}
}
}
public refreshPageAfterTimout(to: number): void {
setTimeout(() => {
this.getData();
}, to);
}
public get availableSelection(): Array<MultiFactorType | SecondFactorType> {
const allTypes: MultiFactorType[] | SecondFactorType[] =
this.componentType === LoginMethodComponentType.MultiFactor
@@ -238,7 +179,7 @@ export class FactorTableComponent implements OnInit {
? [SecondFactorType.SECOND_FACTOR_TYPE_U2F, SecondFactorType.SECOND_FACTOR_TYPE_OTP]
: [];
const filtered = (allTypes as Array<MultiFactorType | SecondFactorType>).filter((type) => !this.mfas.includes(type));
const filtered = (allTypes as Array<MultiFactorType | SecondFactorType>).filter((type) => !this.list.includes(type));
return filtered;
}

View File

@@ -55,6 +55,8 @@
[service]="service"
[serviceType]="serviceType"
[componentType]="LoginMethodComponentType.MultiFactor"
[list]="loginData.multiFactorsList"
(listChanged)="fetchData()"
[disabled]="
loginData?.passwordlessType === PasswordlessType.PASSWORDLESS_TYPE_NOT_ALLOWED ||
([
@@ -103,6 +105,8 @@
[service]="service"
[serviceType]="serviceType"
[componentType]="LoginMethodComponentType.SecondFactor"
[list]="loginData.secondFactorsList"
(listChanged)="fetchData()"
[disabled]="
([
serviceType === PolicyComponentServiceType.ADMIN

View File

@@ -57,7 +57,7 @@ export class LoginPolicyComponent implements OnInit {
});
}
private fetchData(): void {
public fetchData(): void {
this.getData()
.then((resp) => {
if (resp.policy) {
@@ -147,6 +147,8 @@ export class LoginPolicyComponent implements OnInit {
mgmtreq.setForceMfa(this.loginData.forceMfa);
mgmtreq.setPasswordlessType(this.loginData.passwordlessType);
mgmtreq.setHidePasswordReset(this.loginData.hidePasswordReset);
mgmtreq.setMultiFactorsList(this.loginData.multiFactorsList);
mgmtreq.setSecondFactorsList(this.loginData.secondFactorsList);
const pcl = new Duration().setSeconds((this.passwordCheckLifetime?.value ?? 240) * 60 * 60);
mgmtreq.setPasswordCheckLifetime(pcl);