From 9157d509745418ad0885eba9fa3ab6f596c24a5a Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 7 Mar 2019 14:30:48 +0000 Subject: [PATCH] [ACA-2133] fix application ready event for kerberos (#1002) * fix application ready event for kerberos * format file * spellcheck fixes --- cspell.json | 1 + src/app/services/app.service.spec.ts | 21 +++++++++++++++++++-- src/app/services/app.service.ts | 13 +++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/cspell.json b/cspell.json index ecc4c0ed8f..64b6b0b898 100644 --- a/cspell.json +++ b/cspell.json @@ -2,6 +2,7 @@ "version": "0.1", "language": "en", "words": [ + "Kerberos", "succes", "sharedlinks", "Redistributable", diff --git a/src/app/services/app.service.spec.ts b/src/app/services/app.service.spec.ts index 442b9bfdc1..464b7c20fe 100644 --- a/src/app/services/app.service.spec.ts +++ b/src/app/services/app.service.spec.ts @@ -26,7 +26,7 @@ import { AppService } from './app.service'; 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 { AppRouteReuseStrategy } from '../app.routes.strategy'; import { Subject } from 'rxjs'; @@ -34,6 +34,7 @@ describe('AppService', () => { let service: AppService; let auth: AuthenticationService; let routeReuse: AppRouteReuseStrategy; + let appConfig: AppConfigService; beforeEach(() => { TestBed.configureTestingModule({ @@ -53,9 +54,25 @@ describe('AppService', () => { routeReuse = TestBed.get(AppRouteReuseStrategy); auth = TestBed.get(AuthenticationService); + appConfig = TestBed.get(AppConfigService); spyOn(routeReuse, 'resetCache').and.stub(); - service = new AppService(auth, routeReuse); + service = new AppService(auth, appConfig, routeReuse); + }); + + it('should be ready if [withCredentials] mode is used', done => { + appConfig.config = { + auth: { + withCredentials: true + } + }; + + const instance = new AppService(auth, appConfig, routeReuse); + expect(instance.withCredentials).toBeTruthy(); + + instance.ready$.subscribe(() => { + done(); + }); }); it('should reset route cache on login', async () => { diff --git a/src/app/services/app.service.ts b/src/app/services/app.service.ts index 259f972b13..99aca6732e 100644 --- a/src/app/services/app.service.ts +++ b/src/app/services/app.service.ts @@ -24,7 +24,7 @@ */ import { Injectable, Inject } from '@angular/core'; -import { AuthenticationService } from '@alfresco/adf-core'; +import { AuthenticationService, AppConfigService } from '@alfresco/adf-core'; import { Observable, BehaviorSubject } from 'rxjs'; import { AppRouteReuseStrategy } from '../app.routes.strategy'; import { RouteReuseStrategy } from '@angular/router'; @@ -36,11 +36,20 @@ export class AppService { private ready: BehaviorSubject; ready$: Observable; + /** + * Whether `withCredentials` mode is enabled. + * Usually means that `Kerberos` mode is used. + */ + get withCredentials(): boolean { + return this.config.get('auth.withCredentials', false); + } + constructor( auth: AuthenticationService, + private config: AppConfigService, @Inject(RouteReuseStrategy) routeStrategy: AppRouteReuseStrategy ) { - this.ready = new BehaviorSubject(auth.isLoggedIn()); + this.ready = new BehaviorSubject(auth.isLoggedIn() || this.withCredentials); this.ready$ = this.ready.asObservable(); auth.onLogin.subscribe(() => {