From dc215dc0344fdfe2484887362bd2901b7faa717d Mon Sep 17 00:00:00 2001 From: Shubham Bansal <90307437+sbansal3107@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:00:29 +0000 Subject: [PATCH] ACA-4615 : Restrict Edit Profile functionality to ECM users only (#2662) * ACA-4615 Restrict Edit Profile functionality to ECM users only --- app/src/app/app.routes.ts | 2 ++ .../view-profile/view-profile.guard.ts | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app/src/app/components/view-profile/view-profile.guard.ts diff --git a/app/src/app/app.routes.ts b/app/src/app/app.routes.ts index 97a9b66fe..38bbc4ca0 100644 --- a/app/src/app/app.routes.ts +++ b/app/src/app/app.routes.ts @@ -39,6 +39,7 @@ import { SharedFilesComponent } from './components/shared-files/shared-files.com import { DetailsComponent } from './components/details/details.component'; import { HomeComponent } from './components/home/home.component'; import { ViewProfileComponent } from './components/view-profile/view-profile.component'; +import { ViewProfileRuleGuard } from './components/view-profile/view-profile.guard'; export const APP_ROUTES: Routes = [ { @@ -79,6 +80,7 @@ export const APP_ROUTES: Routes = [ children: [ { path: 'profile', + canActivate: [ViewProfileRuleGuard], component: ViewProfileComponent }, { diff --git a/app/src/app/components/view-profile/view-profile.guard.ts b/app/src/app/components/view-profile/view-profile.guard.ts new file mode 100644 index 000000000..adb6be2ef --- /dev/null +++ b/app/src/app/components/view-profile/view-profile.guard.ts @@ -0,0 +1,27 @@ +/* + * Copyright © 2005 - 2021 Alfresco Software, Ltd. All rights reserved. + * + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +import { Injectable } from '@angular/core'; +import { CanActivate, ActivatedRouteSnapshot } from '@angular/router'; +import { Observable } from 'rxjs'; +import { AuthenticationService } from '@alfresco/adf-core'; + +@Injectable({ + providedIn: 'root' +}) +export class ViewProfileRuleGuard implements CanActivate { + constructor(private authService: AuthenticationService) {} + + canActivate(_: ActivatedRouteSnapshot): Observable | Promise | boolean { + return this.isEcmLoggedIn() && !this.authService.isOauth(); + } + + private isEcmLoggedIn() { + return this.authService.isEcmLoggedIn() || (this.authService.isECMProvider() && this.authService.isKerberosEnabled()); + } +}