Skip to content

Commit

Permalink
[ACA-2133] fix application ready event for kerberos (#1002)
Browse files Browse the repository at this point in the history
* fix application ready event for kerberos

* format file

* spellcheck fixes
  • Loading branch information
DenysVuika authored Mar 7, 2019
1 parent 92a5ec4 commit 9157d50
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"version": "0.1",
"language": "en",
"words": [
"Kerberos",
"succes",
"sharedlinks",
"Redistributable",
Expand Down
21 changes: 19 additions & 2 deletions src/app/services/app.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
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';

describe('AppService', () => {
let service: AppService;
let auth: AuthenticationService;
let routeReuse: AppRouteReuseStrategy;
let appConfig: AppConfigService;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -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 () => {
Expand Down
13 changes: 11 additions & 2 deletions src/app/services/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -36,11 +36,20 @@ export class AppService {
private ready: BehaviorSubject<boolean>;
ready$: Observable<boolean>;

/**
* Whether `withCredentials` mode is enabled.
* Usually means that `Kerberos` mode is used.
*/
get withCredentials(): boolean {
return this.config.get<boolean>('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(() => {
Expand Down

0 comments on commit 9157d50

Please sign in to comment.