Browse Source

UI: Added validation unique domain

pull/3557/head
Vladyslav Prykhodko 6 years ago
parent
commit
9c5b353a17
  1. 49
      ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.html
  2. 65
      ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts
  3. 2
      ui-ngx/src/assets/locale/locale.constant-en_US.json

49
ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.html

@ -59,30 +59,31 @@
<section *ngFor="let domainInfo of clientDomainInfos(domain).controls; let n = index; trackBy: trackByParams"
class="domains-list">
<div [formGroupName]="n" fxLayout="row" fxLayoutGap="8px">
<div fxLayout="row" fxLayout.xs="column" fxFlex fxLayoutGap="8px">
<div fxLayout="row" fxLayout.xs="column" fxLayoutGap="8px" fxFlex.gt-xs="50">
<mat-form-field fxFlex="30" fxFlex.xs class="mat-block">
<mat-label translate>admin.oauth2.protocol</mat-label>
<mat-select formControlName="scheme">
<mat-option *ngFor="let protocol of protocols" [value]="protocol">
{{ domainSchemaTranslations.get(protocol) | translate | uppercase }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field fxFlex class="mat-block">
<mat-label translate>admin.domain-name</mat-label>
<input matInput formControlName="name" required>
<mat-error *ngIf="domainInfo.get('name').hasError('pattern')">
{{ 'admin.error-verification-url' | translate }}
</mat-error>
<mat-error *ngIf="domainInfo.get('name').hasError('unique')">
{{ 'admin.domain-name-unique' | translate }}
</mat-error>
</mat-form-field>
<div fxLayout="row" fxLayout.xs="column" fxLayoutGap="8px">
<div fxLayout="column" fxFlex.sm="60" fxFlex.gt-sm="50">
<div fxLayout="row" fxLayout.xs="column" fxLayoutGap="8px">
<mat-form-field fxFlex="30" fxFlex.xs class="mat-block">
<mat-label translate>admin.oauth2.protocol</mat-label>
<mat-select formControlName="scheme">
<mat-option *ngFor="let protocol of protocols" [value]="protocol">
{{ domainSchemaTranslations.get(protocol) | translate | uppercase }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field fxFlex class="mat-block">
<mat-label translate>admin.domain-name</mat-label>
<input matInput formControlName="name" required>
<mat-error *ngIf="domainInfo.get('name').hasError('pattern')">
{{ 'admin.error-verification-url' | translate }}
</mat-error>
</mat-form-field>
</div>
<mat-error *ngIf="domainInfo.hasError('unique')">
{{ 'admin.domain-name-unique' | translate }}
</mat-error>
</div>
<div fxFlex>
<div fxFlex fxLayout="column">
<mat-form-field fxFlex class="mat-block">
<mat-label translate>admin.oauth2.redirect-uri-template</mat-label>
<input matInput [value]="redirectURI(domainInfo)" readonly>
@ -94,8 +95,7 @@
</button>
</mat-form-field>
<mat-form-field fxFlex *ngIf="domainInfo.get('scheme').value === 'MIXED'"
class="mat-block">
<mat-form-field fxFlex *ngIf="domainInfo.get('scheme').value === 'MIXED'" class="mat-block">
<mat-label></mat-label>
<input matInput [value]="redirectURIMixed(domainInfo)" readonly>
<button mat-icon-button color="primary" matSuffix type="button"
@ -106,7 +106,6 @@
</button>
</mat-form-field>
</div>
</div>
<div fxLayout="column" fxLayoutAlign="center start">

65
ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts

@ -178,13 +178,14 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha
}
}
private uniqueDomainValidator(control: AbstractControl): { [key: string]: boolean } | null {
if (control.parent?.parent?.value) {
const domain = control.value;
const listProtocols = control.parent.parent.value
private uniqueDomainValidator(control: FormGroup): { [key: string]: boolean } | null {
if (control.parent?.value) {
const domain = control.value.name;
const listProtocols = control.parent.getRawValue()
.filter((domainInfo) => domainInfo.name === domain)
.map((domainInfo) => domainInfo.scheme);
if (listProtocols.length > 1 && listProtocols.indexOf(DomainSchema.MIXED) > -1) {
if (listProtocols.length > 1 && listProtocols.indexOf(DomainSchema.MIXED) > -1 ||
new Set(listProtocols).size !== listProtocols.length) {
return {unique: true};
}
}
@ -228,10 +229,9 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha
const domain = this.fb.group({
name: [domainInfo ? domainInfo.name : this.window.location.hostname, [
Validators.required,
Validators.pattern('((?![:/]).)*$'),
this.uniqueDomainValidator]],
Validators.pattern('((?![:/]).)*$')]],
scheme: [domainInfo?.scheme ? domainInfo.scheme : DomainSchema.HTTPS, Validators.required]
});
}, {validators: this.uniqueDomainValidator});
return domain;
}
@ -288,6 +288,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha
this.changeMapperConfigType(clientRegistration, registrationData.mapperConfig.type, registrationData.mapperConfig);
} else {
this.changeMapperConfigType(clientRegistration, MapperConfigType.BASIC);
this.setProviderDefaultValue(defaultProviderName, clientRegistration);
}
this.subscriptions.push(clientRegistration.get('mapperConfig.type').valueChanges.subscribe((value) => {
@ -296,33 +297,37 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha
this.subscriptions.push(clientRegistration.get('additionalInfo.providerName').valueChanges.subscribe((provider) => {
(clientRegistration.get('scope') as FormArray).clear();
if (provider === 'Custom') {
const defaultSettings = {...this.defaultProvider, ...{id: clientRegistration.get('id').value}};
clientRegistration.reset(defaultSettings, {emitEvent: false});
clientRegistration.get('accessTokenUri').enable();
clientRegistration.get('authorizationUri').enable();
clientRegistration.get('jwkSetUri').enable();
clientRegistration.get('userInfoUri').enable();
} else {
const template = this.templates.get(provider);
delete template.id;
delete template.additionalInfo;
template.clientId = '';
template.clientSecret = '';
template.scope.forEach(() => {
(clientRegistration.get('scope') as FormArray).push(this.fb.control(''));
});
clientRegistration.get('accessTokenUri').disable();
clientRegistration.get('authorizationUri').disable();
clientRegistration.get('jwkSetUri').disable();
clientRegistration.get('userInfoUri').disable();
clientRegistration.patchValue(template, {emitEvent: false});
}
this.setProviderDefaultValue(provider, clientRegistration);
}));
return clientRegistration;
}
private setProviderDefaultValue(provider: string, clientRegistration: FormGroup) {
if (provider === 'Custom') {
const defaultSettings = {...this.defaultProvider, ...{id: clientRegistration.get('id').value}};
clientRegistration.reset(defaultSettings, {emitEvent: false});
clientRegistration.get('accessTokenUri').enable();
clientRegistration.get('authorizationUri').enable();
clientRegistration.get('jwkSetUri').enable();
clientRegistration.get('userInfoUri').enable();
} else {
const template = this.templates.get(provider);
delete template.id;
delete template.additionalInfo;
template.clientId = '';
template.clientSecret = '';
template.scope.forEach(() => {
(clientRegistration.get('scope') as FormArray).push(this.fb.control(''));
});
clientRegistration.get('accessTokenUri').disable();
clientRegistration.get('authorizationUri').disable();
clientRegistration.get('jwkSetUri').disable();
clientRegistration.get('userInfoUri').disable();
clientRegistration.patchValue(template, {emitEvent: false});
}
}
private changeMapperConfigType(control: AbstractControl, type: MapperConfigType, predefinedValue?: MapperConfig) {
const mapperConfig = control.get('mapperConfig') as FormGroup;
if (type === MapperConfigType.BASIC) {

2
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -121,7 +121,7 @@
"minimum-max-failed-login-attempts-range": "Maximum number of failed login attempts can't be negative",
"user-lockout-notification-email": "In case user account lockout, send notification to email",
"domain-name": "Domain name",
"domain-name-unique": "Domain name need to unique for the system.",
"domain-name-unique": "Domain name and protocol need to unique.",
"error-verification-url": "A domain name shouldn't contain symbols '/' and ':'. Example: thingsboard.io",
"oauth2": {
"access-token-uri": "Access token URI",

Loading…
Cancel
Save