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 | 23 | import { GeneralSettingsComponent } from '@modules/home/pages/admin/general-settings.component'; |
24 | 24 | import { SecuritySettingsComponent } from '@modules/home/pages/admin/security-settings.component'; |
25 | 25 | import { OAuth2SettingsComponent } from '@home/pages/admin/oauth2-settings.component'; |
26 | +import { RedirectGuard } from '@core/guards/redirect.guard'; | |
26 | 27 | |
27 | 28 | const routes: Routes = [ |
28 | 29 | { |
... | ... | @@ -37,7 +38,7 @@ const routes: Routes = [ |
37 | 38 | children: [ |
38 | 39 | { |
39 | 40 | path: '', |
40 | - redirectTo: Authority.TENANT_ADMIN ? 'oauth2-settings' : 'general', | |
41 | + canActivate: [RedirectGuard], | |
41 | 42 | pathMatch: 'full' |
42 | 43 | }, |
43 | 44 | { | ... | ... |
... | ... | @@ -80,26 +80,16 @@ |
80 | 80 | <mat-icon>delete</mat-icon> |
81 | 81 | </button> |
82 | 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 | 94 | <div fxLayout="row" fxLayout.xs="column" fxLayoutGap.gt-xs="8px"> |
105 | 95 | <mat-form-field fxFlex class="mat-block"> |
... | ... | @@ -310,7 +300,7 @@ |
310 | 300 | |
311 | 301 | <mat-form-field fxFlex class="mat-block"> |
312 | 302 | <mat-label translate>common.password</mat-label> |
313 | - <input matInput formControlName="password"> | |
303 | + <input matInput type="password" formControlName="password" autocomplete="new-password"> | |
314 | 304 | </mat-form-field> |
315 | 305 | </div> |
316 | 306 | </section> | ... | ... |
... | ... | @@ -16,7 +16,14 @@ |
16 | 16 | |
17 | 17 | import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; |
18 | 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 | 27 | import { Store } from '@ngrx/store'; |
21 | 28 | import { AppState } from '@core/core.state'; |
22 | 29 | import { AdminService } from '@core/http/admin.service'; |
... | ... | @@ -44,9 +51,9 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha |
44 | 51 | oauth2SettingsForm: FormGroup; |
45 | 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 | 58 | constructor(protected store: Store<AppState>, |
52 | 59 | private adminService: AdminService, |
... | ... | @@ -117,7 +124,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha |
117 | 124 | } |
118 | 125 | |
119 | 126 | private initOAuth2Settings(oauth2Settings: OAuth2Settings): void { |
120 | - if(oauth2Settings.clientsDomainsParams) { | |
127 | + if (oauth2Settings.clientsDomainsParams) { | |
121 | 128 | oauth2Settings.clientsDomainsParams.forEach((domaindomain) => { |
122 | 129 | this.clientsDomainsParams.push(this.buildSettingsDomain(domaindomain)); |
123 | 130 | }); |
... | ... | @@ -173,7 +180,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha |
173 | 180 | formDomain.get('redirectUriTemplate').patchValue(uri); |
174 | 181 | })); |
175 | 182 | |
176 | - if(domainParams){ | |
183 | + if (domainParams) { | |
177 | 184 | domainParams.clientRegistrations.forEach((registration) => { |
178 | 185 | this.clientDomainRegistrations(formDomain).push(this.buildSettingsRegistration(registration)); |
179 | 186 | }) |
... | ... | @@ -187,7 +194,6 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha |
187 | 194 | private buildSettingsRegistration(registrationData?: ClientRegistration): FormGroup { |
188 | 195 | const clientRegistration = this.fb.group({ |
189 | 196 | registrationId: [null, [Validators.required, this.uniqueRegistrationIdValidator]], |
190 | - clientName: [null, [Validators.required]], | |
191 | 197 | loginButtonLabel: [null, [Validators.required]], |
192 | 198 | loginButtonIcon: [null], |
193 | 199 | clientId: ['', [Validators.required]], |
... | ... | @@ -197,7 +203,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha |
197 | 203 | scope: this.fb.array([], [Validators.required]), |
198 | 204 | jwkSetUri: ['', [Validators.required, Validators.pattern(this.URL_REGEXP)]], |
199 | 205 | userInfoUri: ['', [Validators.required, Validators.pattern(this.URL_REGEXP)]], |
200 | - clientAuthenticationMethod: ['post', [Validators.required]], | |
206 | + clientAuthenticationMethod: ['POST', [Validators.required]], | |
201 | 207 | userNameAttributeName: ['email', [Validators.required]], |
202 | 208 | mapperConfig: this.fb.group({ |
203 | 209 | allowUserCreation: [true], |
... | ... | @@ -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 | 229 | registrationData.scope.forEach(() => { |
224 | 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 | 233 | clientRegistration.get('mapperConfig.type').patchValue('CUSTOM'); |
228 | 234 | } |
229 | 235 | } | ... | ... |
... | ... | @@ -23,7 +23,7 @@ export interface AdminSettings<T> { |
23 | 23 | |
24 | 24 | export declare type SmtpProtocol = 'smtp' | 'smtps'; |
25 | 25 | |
26 | -export declare type ClientAuthenticationMethod = 'basic' | 'post'; | |
26 | +export declare type ClientAuthenticationMethod = 'BASIC' | 'POST'; | |
27 | 27 | export declare type MapperConfigType = 'BASIC' | 'CUSTOM'; |
28 | 28 | export declare type TenantNameStrategy = 'DOMAIN' | 'EMAIL' | 'CUSTOM'; |
29 | 29 | |
... | ... | @@ -77,7 +77,6 @@ export interface DomainParams { |
77 | 77 | |
78 | 78 | export interface ClientRegistration { |
79 | 79 | registrationId: string; |
80 | - clientName: string; | |
81 | 80 | loginButtonLabel: string; |
82 | 81 | loginButtonIcon: string; |
83 | 82 | clientId: string; | ... | ... |
... | ... | @@ -131,8 +131,6 @@ |
131 | 131 | "registration-id": "Registration ID", |
132 | 132 | "registration-id-required": "Registration ID is required.", |
133 | 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 | 134 | "client-id": "Client ID", |
137 | 135 | "client-id-required": "Client ID is required.", |
138 | 136 | "client-secret": "Client secret", | ... | ... |