diff --git a/dmp-frontend/src/app/core/admin-auth-guard.service.ts b/dmp-frontend/src/app/core/admin-auth-guard.service.ts deleted file mode 100644 index 5126fba2c..000000000 --- a/dmp-frontend/src/app/core/admin-auth-guard.service.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterStateSnapshot } from '@angular/router'; -import { AuthService } from './services/auth/auth.service'; -import { AppRole } from './common/enum/app-role'; - -@Injectable() -export class AdminAuthGuard implements CanActivate, CanLoad { - constructor(private auth: AuthService, private router: Router) { - } - - isAdmin(): boolean { - if (!this.auth.currentAccountIsAuthenticated()) { return false; } - return this.auth.hasRole(AppRole.Admin); - } - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { - const url: string = state.url; - if (!this.isAdmin()) { - this.router.navigate(['/unauthorized'], { queryParams: { returnUrl: url } }); - return false; - } - return true; - } - - canLoad(route: Route): boolean { - const url = `/${route.path}`; - if (!this.isAdmin()) { - this.router.navigate(['/unauthorized'], { queryParams: { returnUrl: url } }); - return false; - } - return true; - } -} diff --git a/dmp-frontend/src/app/core/core-service.module.ts b/dmp-frontend/src/app/core/core-service.module.ts index f6a971f11..419e551ab 100644 --- a/dmp-frontend/src/app/core/core-service.module.ts +++ b/dmp-frontend/src/app/core/core-service.module.ts @@ -1,6 +1,5 @@ import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; import { CookieService } from 'ngx-cookie-service'; -import { AdminAuthGuard } from './admin-auth-guard.service'; import { AuthGuard } from './auth-guard.service'; import { AuthService } from './services/auth/auth.service'; import { ContactSupportService } from './services/contact-support/contact-support.service'; @@ -20,8 +19,6 @@ import { ProgressIndicationService } from './services/progress-indication/progre import { TimezoneService } from './services/timezone/timezone-service'; import { CollectionUtils } from './services/utilities/collection-utils.service'; import { TypeUtils } from './services/utilities/type-utils.service'; -import { SpecialAuthGuard } from './special-auth-guard.service'; -//import { KeycloakService } from 'keycloak-angular'; import { CanDeactivateGuard } from '@app/library/deactivate/can-deactivate.guard'; import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service'; import { FilterService } from '@common/modules/text-filter/filter-service'; @@ -70,8 +67,6 @@ export class CoreServiceModule { AuthService, CookieService, BaseHttpV2Service, - AdminAuthGuard, - SpecialAuthGuard, AuthGuard, CultureService, TimezoneService, diff --git a/dmp-frontend/src/app/core/services/auth/auth.service.ts b/dmp-frontend/src/app/core/services/auth/auth.service.ts index 1eb9a9dbe..547473319 100644 --- a/dmp-frontend/src/app/core/services/auth/auth.service.ts +++ b/dmp-frontend/src/app/core/services/auth/auth.service.ts @@ -279,7 +279,7 @@ export class AuthService extends BaseService { }) .catch((error) => this.onAuthenticateError(error)); } else { - this.zone.run(() => this.router.navigate([returnUrl])); + this.zone.run(() => this.router.navigateByUrl(returnUrl)); } } @@ -327,7 +327,7 @@ export class AuthService extends BaseService { this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-LOGIN'), SnackBarNotificationLevel.Success ); - this.zone.run(() => this.router.navigate([returnUrl])); + this.zone.run(() => this.router.navigateByUrl(returnUrl)); } onAuthenticateSuccessReload(): void { diff --git a/dmp-frontend/src/app/core/services/http/principal.service.ts b/dmp-frontend/src/app/core/services/http/principal.service.ts index a5538a027..efb453729 100644 --- a/dmp-frontend/src/app/core/services/http/principal.service.ts +++ b/dmp-frontend/src/app/core/services/http/principal.service.ts @@ -3,7 +3,6 @@ import { AppAccount } from '@app/core/model/auth/principal'; import { Observable } from 'rxjs'; import { ConfigurationService } from '../configuration/configuration.service'; import { BaseHttpV2Service } from '../http/base-http-v2.service'; -import { map } from 'rxjs/operators'; import { Tenant } from '@app/core/model/tenant/tenant'; @Injectable() diff --git a/dmp-frontend/src/app/core/special-auth-guard.service.ts b/dmp-frontend/src/app/core/special-auth-guard.service.ts deleted file mode 100644 index 53d90fe02..000000000 --- a/dmp-frontend/src/app/core/special-auth-guard.service.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterStateSnapshot } from '@angular/router'; -import { AuthService } from './services/auth/auth.service'; -import { AppRole } from './common/enum/app-role'; - -@Injectable() -export class SpecialAuthGuard implements CanActivate, CanLoad { - constructor(private auth: AuthService, private router: Router) { - } - - hasPermission(permission: AppRole): boolean { - if (!this.auth.currentAccountIsAuthenticated()) { return false; } - return this.auth.hasRole(permission); - } - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { - const url: string = state.url; - const permissions = route.data['authContext']['permissions']; - let count = permissions.length; - if (count < 0 || count === undefined) { - return false; - } - for (let i = 0; i < permissions.length; i++) { - if (!this.hasPermission(permissions[i])) { - count--; - } - } - if (count === 0) { - this.router.navigate(['/unauthorized'], { queryParams: { returnUrl: url } }); - return false; - } else { - return true; - } - } - - canLoad(route: Route): boolean { - const url = `/${route.path}`; - const permissions = route.data['authContext']['permissions']; - let count = permissions.length; - if (count < 0 || count === undefined) { - return false; - } - for (let i = 0; i < permissions.length; i++) { - if (!this.hasPermission(permissions[i])) { - count--; - } - } - if (count === 0) { - this.router.navigate(['/unauthorized'], { queryParams: { returnUrl: url } }); - return false; - } else { - return true; - } - } -} diff --git a/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.routing.ts b/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.routing.ts index daec08ac0..6d43e8ac8 100644 --- a/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.routing.ts +++ b/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.routing.ts @@ -1,15 +1,15 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { MaintenanceTasksComponent } from './maintenance-tasks.component'; -import { AdminAuthGuard } from '@app/core/admin-auth-guard.service'; +import { AuthGuard } from '@app/core/auth-guard.service'; const routes: Routes = [ - { path: '', component: MaintenanceTasksComponent, canActivate: [AdminAuthGuard] }, + { path: '', component: MaintenanceTasksComponent, canActivate: [AuthGuard] }, ]; @NgModule({ imports: [RouterModule.forChild(routes)], exports: [RouterModule] }) -export class MaintenanceTasksRoutingModule { } \ No newline at end of file +export class MaintenanceTasksRoutingModule { } diff --git a/dmp-frontend/src/app/ui/admin/prefilling-source/prefilling-source.routing.ts b/dmp-frontend/src/app/ui/admin/prefilling-source/prefilling-source.routing.ts index 0a22d62b3..9163aa9eb 100644 --- a/dmp-frontend/src/app/ui/admin/prefilling-source/prefilling-source.routing.ts +++ b/dmp-frontend/src/app/ui/admin/prefilling-source/prefilling-source.routing.ts @@ -1,6 +1,5 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { AdminAuthGuard } from '@app/core/admin-auth-guard.service'; import { PrefillingSourceEditorComponent } from './editor/prefilling-source-editor.component'; import { PrefillingSourceListingComponent } from './listing/prefilling-source-listing.component'; import { AppPermission } from '@app/core/common/enum/permission.enum'; diff --git a/dmp-frontend/src/app/ui/admin/reference-type/reference-type.routing.ts b/dmp-frontend/src/app/ui/admin/reference-type/reference-type.routing.ts index 8b13bdf31..08a531f10 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/reference-type.routing.ts +++ b/dmp-frontend/src/app/ui/admin/reference-type/reference-type.routing.ts @@ -1,6 +1,5 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; -import { AdminAuthGuard } from '@app/core/admin-auth-guard.service'; import { ReferenceTypeEditorComponent } from './editor/reference-type-editor.component'; import { ReferenceTypeListingComponent } from './listing/reference-type-listing.component'; import { AuthGuard } from '@app/core/auth-guard.service'; @@ -16,8 +15,8 @@ const routes: Routes = [ component: ReferenceTypeListingComponent, canActivate: [AuthGuard] }, - { - path: 'new', + { + path: 'new', component: ReferenceTypeEditorComponent, canActivate: [AuthGuard], canDeactivate: [PendingChangesGuard], diff --git a/dmp-frontend/src/app/ui/admin/reference/reference.routing.ts b/dmp-frontend/src/app/ui/admin/reference/reference.routing.ts index 357e6b33c..0306ef868 100644 --- a/dmp-frontend/src/app/ui/admin/reference/reference.routing.ts +++ b/dmp-frontend/src/app/ui/admin/reference/reference.routing.ts @@ -1,6 +1,5 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { AdminAuthGuard } from '@app/core/admin-auth-guard.service'; import { ReferenceEditorComponent } from './editor/reference-editor.component'; import { ReferenceListingComponent } from './listing/reference-listing.component'; import { AppPermission } from '@app/core/common/enum/permission.enum'; diff --git a/dmp-frontend/src/app/ui/admin/tenant/tenant.routing.ts b/dmp-frontend/src/app/ui/admin/tenant/tenant.routing.ts index 4a24a3228..4a3efd541 100644 --- a/dmp-frontend/src/app/ui/admin/tenant/tenant.routing.ts +++ b/dmp-frontend/src/app/ui/admin/tenant/tenant.routing.ts @@ -1,6 +1,5 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { AdminAuthGuard } from '@app/core/admin-auth-guard.service'; import { TenantEditorComponent } from './editor/tenant-editor.component'; import { TenantListingComponent } from './listing/tenant-listing.component'; import { AppPermission } from '@app/core/common/enum/permission.enum'; diff --git a/dmp-frontend/src/app/ui/auth/login/login.component.ts b/dmp-frontend/src/app/ui/auth/login/login.component.ts index eebd9aaca..48ff6a507 100644 --- a/dmp-frontend/src/app/ui/auth/login/login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/login.component.ts @@ -1,7 +1,10 @@ import { Component, Input, NgZone, OnInit } from '@angular/core'; import { ActivatedRoute, Params, Router } from '@angular/router'; import { AuthService } from '@app/core/services/auth/auth.service'; +import { PrincipalService } from '@app/core/services/http/principal.service'; import { BaseComponent } from '@common/base/base.component'; +import { BaseHttpParams } from '@common/http/base-http-params'; +import { InterceptorType } from '@common/http/interceptors/interceptor-type'; import { KeycloakService } from 'keycloak-angular'; import { from } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -24,6 +27,7 @@ export class LoginComponent extends BaseComponent implements OnInit { private router: Router, private authService: AuthService, private route: ActivatedRoute, + private principalService: PrincipalService, private keycloakService: KeycloakService ) { super(); } @@ -35,13 +39,34 @@ export class LoginComponent extends BaseComponent implements OnInit { if (!this.authService.selectedTenant()) { this.authService.selectedTenant('default'); } - this.authService.prepareAuthRequest(from(this.keycloakService.getToken())).pipe(takeUntil(this._destroyed)).subscribe( - () => { - let returnUrL = this.returnUrl; - let queryParams: Params = {}; - this.zone.run(() => this.router.navigate([returnUrL], { queryParams })); - }, - (error) => this.authService.authenticate('/')); + const params = new BaseHttpParams(); + params.interceptorContext = { + excludedInterceptors: [InterceptorType.TenantHeaderInterceptor] + }; + this.principalService.myTenants({ params: params }).subscribe(myTenants => { + if (myTenants) { + if (this.authService.selectedTenant()) { + if (myTenants.findIndex(x => x.code.toLocaleLowerCase() == this.authService.selectedTenant().toLocaleLowerCase()) < 0) { + this.authService.selectedTenant(null); + } + } + if (!this.authService.selectedTenant()) { + if (myTenants.length > 0) { + this.authService.selectedTenant(myTenants[0]?.code); + } + } + } else { + this.authService.selectedTenant(null); + } + + this.authService.prepareAuthRequest(from(this.keycloakService.getToken())).pipe(takeUntil(this._destroyed)).subscribe( + () => { + let returnUrL = this.returnUrl; + this.zone.run(() => this.router.navigateByUrl(returnUrL)); + }, + (error) => this.authService.authenticate('/')); + }, (error) => this.authService.authenticate('/')); + } } diff --git a/dmp-frontend/src/app/ui/auth/login/login.module.ts b/dmp-frontend/src/app/ui/auth/login/login.module.ts index 6546559d7..ff8dd384e 100644 --- a/dmp-frontend/src/app/ui/auth/login/login.module.ts +++ b/dmp-frontend/src/app/ui/auth/login/login.module.ts @@ -6,7 +6,6 @@ import { CommonFormsModule } from '@common/forms/common-forms.module'; import { CommonUiModule } from '@common/ui/common-ui.module'; import { MergeEmailConfirmation } from './merge-email-confirmation/merge-email-confirmation.component'; import { UnlinkEmailConfirmation } from './unlink-email-confirmation/unlink-email-confirmation.component'; -import { PostLoginComponent } from './post-login/post-login.component'; @NgModule({ imports: [ @@ -17,8 +16,7 @@ import { PostLoginComponent } from './post-login/post-login.component'; declarations: [ LoginComponent, MergeEmailConfirmation, - UnlinkEmailConfirmation, - PostLoginComponent + UnlinkEmailConfirmation ], exports: [ LoginComponent diff --git a/dmp-frontend/src/app/ui/auth/login/login.routing.ts b/dmp-frontend/src/app/ui/auth/login/login.routing.ts index 7beaba215..4ce9ef53d 100644 --- a/dmp-frontend/src/app/ui/auth/login/login.routing.ts +++ b/dmp-frontend/src/app/ui/auth/login/login.routing.ts @@ -4,7 +4,7 @@ import { LoginComponent } from './login.component'; import { MergeEmailConfirmation } from './merge-email-confirmation/merge-email-confirmation.component'; import { UnlinkEmailConfirmation } from './unlink-email-confirmation/unlink-email-confirmation.component'; import { AuthGuard } from '@app/core/auth-guard.service'; -import { PostLoginComponent } from './post-login/post-login.component'; +// import { PostLoginComponent } from './post-login/post-login.component'; const routes: Routes = [ { path: '', component: LoginComponent }, @@ -13,10 +13,10 @@ const routes: Routes = [ component: MergeEmailConfirmation, canActivate: [AuthGuard] }, - { - path: 'post', - component: PostLoginComponent - }, + // { + // path: 'post', + // component: PostLoginComponent + // }, { path: 'unlink/confirmation/:token', component: UnlinkEmailConfirmation }, ]; diff --git a/dmp-frontend/src/app/ui/auth/login/post-login/post-login.component.html b/dmp-frontend/src/app/ui/auth/login/post-login/post-login.component.html deleted file mode 100644 index c6ff1820d..000000000 --- a/dmp-frontend/src/app/ui/auth/login/post-login/post-login.component.html +++ /dev/null @@ -1,38 +0,0 @@ -