Showing
6 changed files
with
65 additions
and
36 deletions
ui-ngx/src/app/core/guards/redirect.guard.ts
0 → 100644
1 | +import { Injectable } from '@angular/core'; | ||
2 | +import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; | ||
3 | +import { AuthState } from '@core/auth/auth.models'; | ||
4 | +import { select, Store } from '@ngrx/store'; | ||
5 | +import { selectAuth } from '@core/auth/auth.selectors'; | ||
6 | +import { take } from 'rxjs/operators'; | ||
7 | +import { AppState } from '@core/core.state'; | ||
8 | +import { Authority } from '@shared/models/authority.enum'; | ||
9 | + | ||
10 | +@Injectable({ | ||
11 | + providedIn: 'root' | ||
12 | +}) | ||
13 | +export class RedirectGuard implements CanActivate { | ||
14 | + constructor(private store: Store<AppState>, | ||
15 | + private router: Router) { } | ||
16 | + | ||
17 | + canActivate( | ||
18 | + next: ActivatedRouteSnapshot, | ||
19 | + state: RouterStateSnapshot) { | ||
20 | + let auth: AuthState = null; | ||
21 | + this.store.pipe(select(selectAuth), take(1)).subscribe( | ||
22 | + (authState: AuthState) => { | ||
23 | + auth = authState; | ||
24 | + } | ||
25 | + ); | ||
26 | + | ||
27 | + if (auth?.userDetails?.authority === Authority.TENANT_ADMIN) { | ||
28 | + this.router.navigateByUrl('/settings/oauth2-settings'); | ||
29 | + return false; | ||
30 | + } | ||
31 | + this.router.navigateByUrl('/settings/general'); | ||
32 | + return false; | ||
33 | + } | ||
34 | + | ||
35 | +} |
@@ -23,6 +23,7 @@ import { Authority } from '@shared/models/authority.enum'; | @@ -23,6 +23,7 @@ import { Authority } from '@shared/models/authority.enum'; | ||
23 | import { GeneralSettingsComponent } from '@modules/home/pages/admin/general-settings.component'; | 23 | import { GeneralSettingsComponent } from '@modules/home/pages/admin/general-settings.component'; |
24 | import { SecuritySettingsComponent } from '@modules/home/pages/admin/security-settings.component'; | 24 | import { SecuritySettingsComponent } from '@modules/home/pages/admin/security-settings.component'; |
25 | import { OAuth2SettingsComponent } from '@home/pages/admin/oauth2-settings.component'; | 25 | import { OAuth2SettingsComponent } from '@home/pages/admin/oauth2-settings.component'; |
26 | +import { RedirectGuard } from '@core/guards/redirect.guard'; | ||
26 | 27 | ||
27 | const routes: Routes = [ | 28 | const routes: Routes = [ |
28 | { | 29 | { |
@@ -37,7 +38,7 @@ const routes: Routes = [ | @@ -37,7 +38,7 @@ const routes: Routes = [ | ||
37 | children: [ | 38 | children: [ |
38 | { | 39 | { |
39 | path: '', | 40 | path: '', |
40 | - redirectTo: Authority.TENANT_ADMIN ? 'oauth2-settings' : 'general', | 41 | + canActivate: [RedirectGuard], |
41 | pathMatch: 'full' | 42 | pathMatch: 'full' |
42 | }, | 43 | }, |
43 | { | 44 | { |
@@ -80,26 +80,16 @@ | @@ -80,26 +80,16 @@ | ||
80 | <mat-icon>delete</mat-icon> | 80 | <mat-icon>delete</mat-icon> |
81 | </button> | 81 | </button> |
82 | </div> | 82 | </div> |
83 | - <div fxLayout="row" fxLayout.xs="column" fxLayoutGap.gt-xs="8px"> | ||
84 | - <mat-form-field fxFlex class="mat-block"> | ||
85 | - <mat-label translate>admin.oauth2.registration-id</mat-label> | ||
86 | - <input matInput formControlName="registrationId" required> | ||
87 | - <mat-error *ngIf="registration.get('registrationId').hasError('required')"> | ||
88 | - {{ 'admin.oauth2.registration-id-required' | translate }} | ||
89 | - </mat-error> | ||
90 | - <mat-error *ngIf="registration.get('registrationId').hasError('unique')"> | ||
91 | - {{ 'admin.oauth2.registration-id-unique' | translate }} | ||
92 | - </mat-error> | ||
93 | - </mat-form-field> | ||
94 | - | ||
95 | - <mat-form-field fxFlex class="mat-block"> | ||
96 | - <mat-label translate>admin.oauth2.client-name</mat-label> | ||
97 | - <input matInput formControlName="clientName" required> | ||
98 | - <mat-error *ngIf="registration.get('clientName').hasError('required')"> | ||
99 | - {{ 'admin.oauth2.client-name-required' | translate }} | ||
100 | - </mat-error> | ||
101 | - </mat-form-field> | ||
102 | - </div> | 83 | + <mat-form-field fxFlex class="mat-block"> |
84 | + <mat-label translate>admin.oauth2.registration-id</mat-label> | ||
85 | + <input matInput formControlName="registrationId" required> | ||
86 | + <mat-error *ngIf="registration.get('registrationId').hasError('required')"> | ||
87 | + {{ 'admin.oauth2.registration-id-required' | translate }} | ||
88 | + </mat-error> | ||
89 | + <mat-error *ngIf="registration.get('registrationId').hasError('unique')"> | ||
90 | + {{ 'admin.oauth2.registration-id-unique' | translate }} | ||
91 | + </mat-error> | ||
92 | + </mat-form-field> | ||
103 | 93 | ||
104 | <div fxLayout="row" fxLayout.xs="column" fxLayoutGap.gt-xs="8px"> | 94 | <div fxLayout="row" fxLayout.xs="column" fxLayoutGap.gt-xs="8px"> |
105 | <mat-form-field fxFlex class="mat-block"> | 95 | <mat-form-field fxFlex class="mat-block"> |
@@ -310,7 +300,7 @@ | @@ -310,7 +300,7 @@ | ||
310 | 300 | ||
311 | <mat-form-field fxFlex class="mat-block"> | 301 | <mat-form-field fxFlex class="mat-block"> |
312 | <mat-label translate>common.password</mat-label> | 302 | <mat-label translate>common.password</mat-label> |
313 | - <input matInput formControlName="password"> | 303 | + <input matInput type="password" formControlName="password" autocomplete="new-password"> |
314 | </mat-form-field> | 304 | </mat-form-field> |
315 | </div> | 305 | </div> |
316 | </section> | 306 | </section> |
@@ -16,7 +16,14 @@ | @@ -16,7 +16,14 @@ | ||
16 | 16 | ||
17 | import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; | 17 | import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; |
18 | import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; | 18 | import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; |
19 | -import { ClientRegistration, DomainParams, OAuth2Settings } from '@shared/models/settings.models'; | 19 | +import { |
20 | + ClientAuthenticationMethod, | ||
21 | + ClientRegistration, | ||
22 | + DomainParams, | ||
23 | + MapperConfigType, | ||
24 | + OAuth2Settings, | ||
25 | + TenantNameStrategy | ||
26 | +} from '@shared/models/settings.models'; | ||
20 | import { Store } from '@ngrx/store'; | 27 | import { Store } from '@ngrx/store'; |
21 | import { AppState } from '@core/core.state'; | 28 | import { AppState } from '@core/core.state'; |
22 | import { AdminService } from '@core/http/admin.service'; | 29 | import { AdminService } from '@core/http/admin.service'; |
@@ -44,9 +51,9 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | @@ -44,9 +51,9 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | ||
44 | oauth2SettingsForm: FormGroup; | 51 | oauth2SettingsForm: FormGroup; |
45 | oauth2Settings: OAuth2Settings; | 52 | oauth2Settings: OAuth2Settings; |
46 | 53 | ||
47 | - clientAuthenticationMethods = ['basic', 'post']; | ||
48 | - converterTypesExternalUser = ['BASIC', 'CUSTOM']; | ||
49 | - tenantNameStrategies = ['DOMAIN', 'EMAIL', 'CUSTOM']; | 54 | + clientAuthenticationMethods: ClientAuthenticationMethod[] = ['BASIC', 'POST']; |
55 | + converterTypesExternalUser: MapperConfigType[] = ['BASIC', 'CUSTOM']; | ||
56 | + tenantNameStrategies: TenantNameStrategy[] = ['DOMAIN', 'EMAIL', 'CUSTOM']; | ||
50 | 57 | ||
51 | constructor(protected store: Store<AppState>, | 58 | constructor(protected store: Store<AppState>, |
52 | private adminService: AdminService, | 59 | private adminService: AdminService, |
@@ -117,7 +124,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | @@ -117,7 +124,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | ||
117 | } | 124 | } |
118 | 125 | ||
119 | private initOAuth2Settings(oauth2Settings: OAuth2Settings): void { | 126 | private initOAuth2Settings(oauth2Settings: OAuth2Settings): void { |
120 | - if(oauth2Settings.clientsDomainsParams) { | 127 | + if (oauth2Settings.clientsDomainsParams) { |
121 | oauth2Settings.clientsDomainsParams.forEach((domaindomain) => { | 128 | oauth2Settings.clientsDomainsParams.forEach((domaindomain) => { |
122 | this.clientsDomainsParams.push(this.buildSettingsDomain(domaindomain)); | 129 | this.clientsDomainsParams.push(this.buildSettingsDomain(domaindomain)); |
123 | }); | 130 | }); |
@@ -173,7 +180,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | @@ -173,7 +180,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | ||
173 | formDomain.get('redirectUriTemplate').patchValue(uri); | 180 | formDomain.get('redirectUriTemplate').patchValue(uri); |
174 | })); | 181 | })); |
175 | 182 | ||
176 | - if(domainParams){ | 183 | + if (domainParams) { |
177 | domainParams.clientRegistrations.forEach((registration) => { | 184 | domainParams.clientRegistrations.forEach((registration) => { |
178 | this.clientDomainRegistrations(formDomain).push(this.buildSettingsRegistration(registration)); | 185 | this.clientDomainRegistrations(formDomain).push(this.buildSettingsRegistration(registration)); |
179 | }) | 186 | }) |
@@ -187,7 +194,6 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | @@ -187,7 +194,6 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | ||
187 | private buildSettingsRegistration(registrationData?: ClientRegistration): FormGroup { | 194 | private buildSettingsRegistration(registrationData?: ClientRegistration): FormGroup { |
188 | const clientRegistration = this.fb.group({ | 195 | const clientRegistration = this.fb.group({ |
189 | registrationId: [null, [Validators.required, this.uniqueRegistrationIdValidator]], | 196 | registrationId: [null, [Validators.required, this.uniqueRegistrationIdValidator]], |
190 | - clientName: [null, [Validators.required]], | ||
191 | loginButtonLabel: [null, [Validators.required]], | 197 | loginButtonLabel: [null, [Validators.required]], |
192 | loginButtonIcon: [null], | 198 | loginButtonIcon: [null], |
193 | clientId: ['', [Validators.required]], | 199 | clientId: ['', [Validators.required]], |
@@ -197,7 +203,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | @@ -197,7 +203,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | ||
197 | scope: this.fb.array([], [Validators.required]), | 203 | scope: this.fb.array([], [Validators.required]), |
198 | jwkSetUri: ['', [Validators.required, Validators.pattern(this.URL_REGEXP)]], | 204 | jwkSetUri: ['', [Validators.required, Validators.pattern(this.URL_REGEXP)]], |
199 | userInfoUri: ['', [Validators.required, Validators.pattern(this.URL_REGEXP)]], | 205 | userInfoUri: ['', [Validators.required, Validators.pattern(this.URL_REGEXP)]], |
200 | - clientAuthenticationMethod: ['post', [Validators.required]], | 206 | + clientAuthenticationMethod: ['POST', [Validators.required]], |
201 | userNameAttributeName: ['email', [Validators.required]], | 207 | userNameAttributeName: ['email', [Validators.required]], |
202 | mapperConfig: this.fb.group({ | 208 | mapperConfig: this.fb.group({ |
203 | allowUserCreation: [true], | 209 | allowUserCreation: [true], |
@@ -219,11 +225,11 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | @@ -219,11 +225,11 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha | ||
219 | } | 225 | } |
220 | })); | 226 | })); |
221 | 227 | ||
222 | - if(registrationData){ | 228 | + if (registrationData) { |
223 | registrationData.scope.forEach(() => { | 229 | registrationData.scope.forEach(() => { |
224 | (clientRegistration.get('scope') as FormArray).push(this.fb.control('')) | 230 | (clientRegistration.get('scope') as FormArray).push(this.fb.control('')) |
225 | }) | 231 | }) |
226 | - if(registrationData.mapperConfig.type !== 'BASIC'){ | 232 | + if (registrationData.mapperConfig.type !== 'BASIC') { |
227 | clientRegistration.get('mapperConfig.type').patchValue('CUSTOM'); | 233 | clientRegistration.get('mapperConfig.type').patchValue('CUSTOM'); |
228 | } | 234 | } |
229 | } | 235 | } |
@@ -23,7 +23,7 @@ export interface AdminSettings<T> { | @@ -23,7 +23,7 @@ export interface AdminSettings<T> { | ||
23 | 23 | ||
24 | export declare type SmtpProtocol = 'smtp' | 'smtps'; | 24 | export declare type SmtpProtocol = 'smtp' | 'smtps'; |
25 | 25 | ||
26 | -export declare type ClientAuthenticationMethod = 'basic' | 'post'; | 26 | +export declare type ClientAuthenticationMethod = 'BASIC' | 'POST'; |
27 | export declare type MapperConfigType = 'BASIC' | 'CUSTOM'; | 27 | export declare type MapperConfigType = 'BASIC' | 'CUSTOM'; |
28 | export declare type TenantNameStrategy = 'DOMAIN' | 'EMAIL' | 'CUSTOM'; | 28 | export declare type TenantNameStrategy = 'DOMAIN' | 'EMAIL' | 'CUSTOM'; |
29 | 29 | ||
@@ -77,7 +77,6 @@ export interface DomainParams { | @@ -77,7 +77,6 @@ export interface DomainParams { | ||
77 | 77 | ||
78 | export interface ClientRegistration { | 78 | export interface ClientRegistration { |
79 | registrationId: string; | 79 | registrationId: string; |
80 | - clientName: string; | ||
81 | loginButtonLabel: string; | 80 | loginButtonLabel: string; |
82 | loginButtonIcon: string; | 81 | loginButtonIcon: string; |
83 | clientId: string; | 82 | clientId: string; |
@@ -131,8 +131,6 @@ | @@ -131,8 +131,6 @@ | ||
131 | "registration-id": "Registration ID", | 131 | "registration-id": "Registration ID", |
132 | "registration-id-required": "Registration ID is required.", | 132 | "registration-id-required": "Registration ID is required.", |
133 | "registration-id-unique": "Registration ID need to unique for the system.", | 133 | "registration-id-unique": "Registration ID need to unique for the system.", |
134 | - "client-name": "Client name", | ||
135 | - "client-name-required": "Client name is required.", | ||
136 | "client-id": "Client ID", | 134 | "client-id": "Client ID", |
137 | "client-id-required": "Client ID is required.", | 135 | "client-id-required": "Client ID is required.", |
138 | "client-secret": "Client secret", | 136 | "client-secret": "Client secret", |