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()); + } +}