From e0e2a61821e3f1ad7c43a6fb6a4a3d3972d760e0 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 14 Feb 2019 06:45:37 +0000 Subject: [PATCH] [ACA-2211] auth guard: add support for withCredentials (#942) * auth guard: add support for withCredentials * formatting fixes * remove fdescribe --- src/app/guards/auth.guard.spec.ts | 24 +++++++++++++++++++++++- src/app/guards/auth.guard.ts | 11 ++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/app/guards/auth.guard.spec.ts b/src/app/guards/auth.guard.spec.ts index 03b6f5bbfa..8d3102f537 100644 --- a/src/app/guards/auth.guard.spec.ts +++ b/src/app/guards/auth.guard.spec.ts @@ -26,7 +26,7 @@ import { AppAuthGuard } from './auth.guard'; import { TestBed } from '@angular/core/testing'; import { AppTestingModule } from '../testing/app-testing.module'; -import { AuthenticationService } from '@alfresco/adf-core'; +import { AuthenticationService, AppConfigService } from '@alfresco/adf-core'; import { RouterTestingModule } from '@angular/router/testing'; import { Router } from '@angular/router'; @@ -34,6 +34,7 @@ describe('AppAuthGuard', () => { let auth: AuthenticationService; let guard: AppAuthGuard; let router: Router; + let config: AppConfigService; beforeEach(() => { TestBed.configureTestingModule({ @@ -44,10 +45,31 @@ describe('AppAuthGuard', () => { auth = TestBed.get(AuthenticationService); guard = TestBed.get(AppAuthGuard); router = TestBed.get(Router); + config = TestBed.get(AppConfigService); spyOn(router, 'navigateByUrl').and.stub(); }); + it('should fall through when withCredentials enabled', () => { + spyOn(auth, 'isEcmLoggedIn').and.returnValue(false); + + config.config = { + auth: { + withCredentials: false + } + }; + + expect(guard.checkLogin(null)).toBe(false); + + config.config = { + auth: { + withCredentials: true + } + }; + + expect(guard.checkLogin(null)).toBe(true); + }); + it('should evaluate to [true] if logged in already', () => { spyOn(auth, 'isEcmLoggedIn').and.returnValue(true); diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts index e8ac6876fa..d054fa8473 100644 --- a/src/app/guards/auth.guard.ts +++ b/src/app/guards/auth.guard.ts @@ -38,13 +38,18 @@ export class AppAuthGuard extends AuthGuardEcm { constructor( private _auth: AuthenticationService, private _router: Router, - config: AppConfigService + private _config: AppConfigService ) { - super(_auth, _router, config); + super(_auth, _router, _config); } checkLogin(redirectUrl: string): boolean { - if (this._auth.isEcmLoggedIn()) { + const withCredentials = this._config.get( + 'auth.withCredentials', + false + ); + + if (withCredentials || this._auth.isEcmLoggedIn()) { return true; }