fix(console): login policy, idp type filter (#875)

* cleanup login policy

* detail layout

* disable if no custom

* fix login policy filter

* add styletype to idp

* stylelint

* lint
This commit is contained in:
Max Peintner
2020-10-20 11:37:17 +02:00
committed by GitHub
parent 46bc987b28
commit f8616265be
13 changed files with 184 additions and 131 deletions
+11 -3
View File
@@ -63,7 +63,7 @@
<mat-label>{{ 'IDP.IDPDISPLAYNAMMAPPING' | translate }}</mat-label>
<mat-select formControlName="idpDisplayNameMapping">
<mat-option *ngFor="let field of mappingFields" [value]="field">
{{ 'IDP.MAPPINTFIELD.'+field | translate }}
{{ 'IDP.MAPPINGFIELD.'+field | translate }}
</mat-option>
</mat-select>
</mat-form-field>
@@ -71,7 +71,15 @@
<mat-label>{{ 'IDP.USERNAMEMAPPING' | translate }}</mat-label>
<mat-select formControlName="usernameMapping">
<mat-option *ngFor="let field of mappingFields" [value]="field">
{{ 'IDP.MAPPINTFIELD.'+field | translate }}
{{ 'IDP.MAPPINGFIELD.'+field | translate }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="formfield" appearance="outline">
<mat-label>{{ 'IDP.STYLE' | translate }}</mat-label>
<mat-select formControlName="usernameMapping">
<mat-option *ngFor="let field of styleFields" [value]="field">
{{ 'IDP.STYLEFIELD.'+field | translate }}
</mat-option>
</mat-select>
</mat-form-field>
@@ -88,4 +96,4 @@
</ng-container>
</div>
</app-detail-layout>
</app-detail-layout>
+66 -53
View File
@@ -1,20 +1,22 @@
import { COMMA, ENTER, SPACE } from '@angular/cdk/keycodes';
import { Location } from '@angular/common';
import {Component, Injector, Input, OnDestroy, OnInit, Type} from '@angular/core';
import { Component, Injector, OnDestroy, OnInit, Type } from '@angular/core';
import { AbstractControl, FormControl, FormGroup, Validators } from '@angular/forms';
import { MatChipInputEvent } from '@angular/material/chips';
import { ActivatedRoute, Params } from '@angular/router';
import { Subscription } from 'rxjs';
import { switchMap, take } from 'rxjs/operators';
import {
OIDCMappingField as authMappingFields,
OidcIdpConfigUpdate as AdminOidcIdpConfigUpdate,
IdpUpdate as AdminIdpConfigUpdate,
IdpStylingType as adminIdpStylingType,
IdpUpdate as AdminIdpConfigUpdate,
OidcIdpConfigUpdate as AdminOidcIdpConfigUpdate,
OIDCMappingField as adminMappingFields,
} from 'src/app/proto/generated/admin_pb';
import {
OIDCMappingField as mgmtMappingFields,
OidcIdpConfigUpdate as MgmtOidcIdpConfigUpdate,
IdpUpdate as MgmtIdpConfigUpdate,
IdpStylingType as mgmtIdpStylingType,
IdpUpdate as MgmtIdpConfigUpdate,
OidcIdpConfigUpdate as MgmtOidcIdpConfigUpdate,
OIDCMappingField as mgmtMappingFields,
} from 'src/app/proto/generated/management_pb';
import { AdminService } from 'src/app/services/admin.service';
import { ManagementService } from 'src/app/services/mgmt.service';
@@ -28,7 +30,9 @@ import { PolicyComponentServiceType } from '../policies/policy-component-types.e
styleUrls: ['./idp.component.scss'],
})
export class IdpComponent implements OnInit, OnDestroy {
public mappingFields: mgmtMappingFields[] | authMappingFields[] = [];
public mappingFields: mgmtMappingFields[] | adminMappingFields[] = [];
public styleFields: mgmtIdpStylingType[] | adminIdpStylingType[] = [];
public showIdSecretSection: boolean = false;
public serviceType: PolicyComponentServiceType = PolicyComponentServiceType.MGMT;
private service!: ManagementService | AdminService;
@@ -41,7 +45,6 @@ export class IdpComponent implements OnInit, OnDestroy {
public oidcConfigForm!: FormGroup;
constructor(
// private router: Router,
private toast: ToastService,
private injector: Injector,
private route: ActivatedRoute,
@@ -50,15 +53,16 @@ export class IdpComponent implements OnInit, OnDestroy {
this.idpForm = new FormGroup({
id: new FormControl({ disabled: true, value: '' }, [Validators.required]),
name: new FormControl('', [Validators.required]),
stylingType: new FormControl('', [Validators.required]),
});
this.oidcConfigForm = new FormGroup({
clientId: new FormControl('', [Validators.required]),
clientSecret: new FormControl(''),
issuer: new FormControl('', [Validators.required]),
scopesList: new FormControl([], []),
idpDisplayNameMapping: new FormControl(0),
usernameMapping: new FormControl(0),
clientId: new FormControl('', [Validators.required]),
clientSecret: new FormControl(''),
issuer: new FormControl('', [Validators.required]),
scopesList: new FormControl([], []),
idpDisplayNameMapping: new FormControl(0),
usernameMapping: new FormControl(0),
});
this.route.data.pipe(switchMap(data => {
@@ -68,14 +72,20 @@ export class IdpComponent implements OnInit, OnDestroy {
case PolicyComponentServiceType.MGMT:
this.service = this.injector.get(ManagementService as Type<ManagementService>);
this.mappingFields = [
mgmtMappingFields.OIDCMAPPINGFIELD_PREFERRED_USERNAME,
mgmtMappingFields.OIDCMAPPINGFIELD_EMAIL];
mgmtMappingFields.OIDCMAPPINGFIELD_PREFERRED_USERNAME,
mgmtMappingFields.OIDCMAPPINGFIELD_EMAIL];
this.styleFields = [
mgmtIdpStylingType.IDPSTYLINGTYPE_UNSPECIFIED,
mgmtIdpStylingType.IDPSTYLINGTYPE_GOOGLE];
break;
case PolicyComponentServiceType.ADMIN:
this.service = this.injector.get(AdminService as Type<AdminService>);
this.mappingFields = [
authMappingFields.OIDCMAPPINGFIELD_PREFERRED_USERNAME,
authMappingFields.OIDCMAPPINGFIELD_EMAIL];
adminMappingFields.OIDCMAPPINGFIELD_PREFERRED_USERNAME,
adminMappingFields.OIDCMAPPINGFIELD_EMAIL];
this.styleFields = [
adminIdpStylingType.IDPSTYLINGTYPE_UNSPECIFIED,
adminIdpStylingType.IDPSTYLINGTYPE_GOOGLE];
break;
}
@@ -84,11 +94,11 @@ export class IdpComponent implements OnInit, OnDestroy {
const { id } = params;
if (id) {
this.service.IdpByID(id).then(idp => {
const idpObject = idp.toObject();
this.idpForm.patchValue(idpObject);
if (idpObject.oidcConfig) {
this.oidcConfigForm.patchValue(idpObject.oidcConfig);
}
const idpObject = idp.toObject();
this.idpForm.patchValue(idpObject);
if (idpObject.oidcConfig) {
this.oidcConfigForm.patchValue(idpObject.oidcConfig);
}
});
}
});
@@ -120,9 +130,10 @@ export class IdpComponent implements OnInit, OnDestroy {
req.setId(this.id?.value);
req.setName(this.name?.value);
req.setStylingType(this.stylingType?.value);
this.service.UpdateIdp(req).then((idp) => {
this.toast.showInfo('IDP.TOAST.SAVED', true);
this.toast.showInfo('IDP.TOAST.SAVED', true);
// this.router.navigate(['idp', ]);
}).catch(error => {
this.toast.showError(error);
@@ -130,31 +141,31 @@ export class IdpComponent implements OnInit, OnDestroy {
}
public updateOidcConfig(): void {
let req: AdminOidcIdpConfigUpdate | MgmtOidcIdpConfigUpdate;
let req: AdminOidcIdpConfigUpdate | MgmtOidcIdpConfigUpdate;
switch (this.serviceType) {
case PolicyComponentServiceType.MGMT:
req = new MgmtOidcIdpConfigUpdate();
break;
case PolicyComponentServiceType.ADMIN:
req = new AdminOidcIdpConfigUpdate();
break;
}
switch (this.serviceType) {
case PolicyComponentServiceType.MGMT:
req = new MgmtOidcIdpConfigUpdate();
break;
case PolicyComponentServiceType.ADMIN:
req = new AdminOidcIdpConfigUpdate();
break;
}
req.setIdpId(this.id?.value);
req.setClientId(this.clientId?.value);
req.setClientSecret(this.clientSecret?.value);
req.setIssuer(this.issuer?.value);
req.setScopesList(this.scopesList?.value);
req.setUsernameMapping(this.usernameMapping?.value);
req.setIdpDisplayNameMapping(this.idpDisplayNameMapping?.value);
req.setIdpId(this.id?.value);
req.setClientId(this.clientId?.value);
req.setClientSecret(this.clientSecret?.value);
req.setIssuer(this.issuer?.value);
req.setScopesList(this.scopesList?.value);
req.setUsernameMapping(this.usernameMapping?.value);
req.setIdpDisplayNameMapping(this.idpDisplayNameMapping?.value);
this.service.UpdateOidcIdpConfig(req).then((oidcConfig) => {
this.toast.showInfo('IDP.TOAST.SAVED', true);
// this.router.navigate(['idp', ]);
}).catch(error => {
this.toast.showError(error);
});
this.service.UpdateOidcIdpConfig(req).then((oidcConfig) => {
this.toast.showInfo('IDP.TOAST.SAVED', true);
// this.router.navigate(['idp', ]);
}).catch(error => {
this.toast.showError(error);
});
}
public close(): void {
@@ -188,12 +199,10 @@ export class IdpComponent implements OnInit, OnDestroy {
public get backroutes(): string[] {
switch (this.serviceType) {
case PolicyComponentServiceType.MGMT:
return ['/org', 'policy', 'login'];
return ['/org', 'policy', 'login'];
case PolicyComponentServiceType.ADMIN:
return ['/iam', 'policy', 'login'];
break;
return ['/iam', 'policy', 'login'];
}
return [];
}
public get id(): AbstractControl | null {
@@ -204,6 +213,10 @@ export class IdpComponent implements OnInit, OnDestroy {
return this.idpForm.get('name');
}
public get stylingType(): AbstractControl | null {
return this.idpForm.get('stylingType');
}
public get clientId(): AbstractControl | null {
return this.oidcConfigForm.get('clientId');
}
@@ -221,10 +234,10 @@ export class IdpComponent implements OnInit, OnDestroy {
}
public get idpDisplayNameMapping(): AbstractControl | null {
return this.oidcConfigForm.get('idpDisplayNameMapping');
return this.oidcConfigForm.get('idpDisplayNameMapping');
}
public get usernameMapping(): AbstractControl | null {
return this.oidcConfigForm.get('usernameMapping');
return this.oidcConfigForm.get('usernameMapping');
}
}