diff --git a/ui-ngx/src/app/core/guards/redirect.guard.ts b/ui-ngx/src/app/core/guards/redirect.guard.ts new file mode 100644 index 0000000000..106cc0840b --- /dev/null +++ b/ui-ngx/src/app/core/guards/redirect.guard.ts @@ -0,0 +1,35 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; +import { AuthState } from '@core/auth/auth.models'; +import { select, Store } from '@ngrx/store'; +import { selectAuth } from '@core/auth/auth.selectors'; +import { take } from 'rxjs/operators'; +import { AppState } from '@core/core.state'; +import { Authority } from '@shared/models/authority.enum'; + +@Injectable({ + providedIn: 'root' +}) +export class RedirectGuard implements CanActivate { + constructor(private store: Store, + private router: Router) { } + + canActivate( + next: ActivatedRouteSnapshot, + state: RouterStateSnapshot) { + let auth: AuthState = null; + this.store.pipe(select(selectAuth), take(1)).subscribe( + (authState: AuthState) => { + auth = authState; + } + ); + + if (auth?.userDetails?.authority === Authority.TENANT_ADMIN) { + this.router.navigateByUrl('/settings/oauth2-settings'); + return false; + } + this.router.navigateByUrl('/settings/general'); + return false; + } + +} diff --git a/ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts b/ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts index 329e313110..a6b18cfd29 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts @@ -23,6 +23,7 @@ import { Authority } from '@shared/models/authority.enum'; import { GeneralSettingsComponent } from '@modules/home/pages/admin/general-settings.component'; import { SecuritySettingsComponent } from '@modules/home/pages/admin/security-settings.component'; import { OAuth2SettingsComponent } from '@home/pages/admin/oauth2-settings.component'; +import { RedirectGuard } from '@core/guards/redirect.guard'; const routes: Routes = [ { @@ -37,7 +38,7 @@ const routes: Routes = [ children: [ { path: '', - redirectTo: Authority.TENANT_ADMIN ? 'oauth2-settings' : 'general', + canActivate: [RedirectGuard], pathMatch: 'full' }, { diff --git a/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.html b/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.html index 5c8c92658e..e5ea872fbc 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.html +++ b/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.html @@ -80,26 +80,16 @@ delete -
- - admin.oauth2.registration-id - - - {{ 'admin.oauth2.registration-id-required' | translate }} - - - {{ 'admin.oauth2.registration-id-unique' | translate }} - - - - - admin.oauth2.client-name - - - {{ 'admin.oauth2.client-name-required' | translate }} - - -
+ + admin.oauth2.registration-id + + + {{ 'admin.oauth2.registration-id-required' | translate }} + + + {{ 'admin.oauth2.registration-id-unique' | translate }} + +
@@ -310,7 +300,7 @@ common.password - +
diff --git a/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts b/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts index 47333a99b1..ab472643a6 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/oauth2-settings.component.ts @@ -16,7 +16,14 @@ import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; -import { ClientRegistration, DomainParams, OAuth2Settings } from '@shared/models/settings.models'; +import { + ClientAuthenticationMethod, + ClientRegistration, + DomainParams, + MapperConfigType, + OAuth2Settings, + TenantNameStrategy +} from '@shared/models/settings.models'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { AdminService } from '@core/http/admin.service'; @@ -44,9 +51,9 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha oauth2SettingsForm: FormGroup; oauth2Settings: OAuth2Settings; - clientAuthenticationMethods = ['basic', 'post']; - converterTypesExternalUser = ['BASIC', 'CUSTOM']; - tenantNameStrategies = ['DOMAIN', 'EMAIL', 'CUSTOM']; + clientAuthenticationMethods: ClientAuthenticationMethod[] = ['BASIC', 'POST']; + converterTypesExternalUser: MapperConfigType[] = ['BASIC', 'CUSTOM']; + tenantNameStrategies: TenantNameStrategy[] = ['DOMAIN', 'EMAIL', 'CUSTOM']; constructor(protected store: Store, private adminService: AdminService, @@ -117,7 +124,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha } private initOAuth2Settings(oauth2Settings: OAuth2Settings): void { - if(oauth2Settings.clientsDomainsParams) { + if (oauth2Settings.clientsDomainsParams) { oauth2Settings.clientsDomainsParams.forEach((domaindomain) => { this.clientsDomainsParams.push(this.buildSettingsDomain(domaindomain)); }); @@ -173,7 +180,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha formDomain.get('redirectUriTemplate').patchValue(uri); })); - if(domainParams){ + if (domainParams) { domainParams.clientRegistrations.forEach((registration) => { this.clientDomainRegistrations(formDomain).push(this.buildSettingsRegistration(registration)); }) @@ -187,7 +194,6 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha private buildSettingsRegistration(registrationData?: ClientRegistration): FormGroup { const clientRegistration = this.fb.group({ registrationId: [null, [Validators.required, this.uniqueRegistrationIdValidator]], - clientName: [null, [Validators.required]], loginButtonLabel: [null, [Validators.required]], loginButtonIcon: [null], clientId: ['', [Validators.required]], @@ -197,7 +203,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha scope: this.fb.array([], [Validators.required]), jwkSetUri: ['', [Validators.required, Validators.pattern(this.URL_REGEXP)]], userInfoUri: ['', [Validators.required, Validators.pattern(this.URL_REGEXP)]], - clientAuthenticationMethod: ['post', [Validators.required]], + clientAuthenticationMethod: ['POST', [Validators.required]], userNameAttributeName: ['email', [Validators.required]], mapperConfig: this.fb.group({ allowUserCreation: [true], @@ -219,11 +225,11 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha } })); - if(registrationData){ + if (registrationData) { registrationData.scope.forEach(() => { (clientRegistration.get('scope') as FormArray).push(this.fb.control('')) }) - if(registrationData.mapperConfig.type !== 'BASIC'){ + if (registrationData.mapperConfig.type !== 'BASIC') { clientRegistration.get('mapperConfig.type').patchValue('CUSTOM'); } } diff --git a/ui-ngx/src/app/shared/models/settings.models.ts b/ui-ngx/src/app/shared/models/settings.models.ts index c52c759719..c4a1504f0f 100644 --- a/ui-ngx/src/app/shared/models/settings.models.ts +++ b/ui-ngx/src/app/shared/models/settings.models.ts @@ -23,7 +23,7 @@ export interface AdminSettings { export declare type SmtpProtocol = 'smtp' | 'smtps'; -export declare type ClientAuthenticationMethod = 'basic' | 'post'; +export declare type ClientAuthenticationMethod = 'BASIC' | 'POST'; export declare type MapperConfigType = 'BASIC' | 'CUSTOM'; export declare type TenantNameStrategy = 'DOMAIN' | 'EMAIL' | 'CUSTOM'; @@ -77,7 +77,6 @@ export interface DomainParams { export interface ClientRegistration { registrationId: string; - clientName: string; loginButtonLabel: string; loginButtonIcon: string; clientId: string; diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 0866117933..239a580ef7 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -131,8 +131,6 @@ "registration-id": "Registration ID", "registration-id-required": "Registration ID is required.", "registration-id-unique": "Registration ID need to unique for the system.", - "client-name": "Client name", - "client-name-required": "Client name is required.", "client-id": "Client ID", "client-id-required": "Client ID is required.", "client-secret": "Client secret",