diff --git a/lib/content-services/content-node-selector/content-node-selector-panel.component.ts b/lib/content-services/content-node-selector/content-node-selector-panel.component.ts index 3e5dd6a26d..65b7bd3e65 100644 --- a/lib/content-services/content-node-selector/content-node-selector-panel.component.ts +++ b/lib/content-services/content-node-selector/content-node-selector-panel.component.ts @@ -195,7 +195,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit { private isExcludedSiteContent(row: ShareDataRow): boolean { const entry = row.node.entry; - if (this._excludeSiteContent.length && + if (this._excludeSiteContent && this._excludeSiteContent.length && entry && entry.properties && entry.properties['st:componentId']) { @@ -368,7 +368,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit { * @param entry */ private attemptNodeSelection(entry: Node): void { - if (this.isSelectionValid(entry)) { + if (entry && this.isSelectionValid(entry)) { this.chosenNode = entry; } else { this.resetChosenNode(); diff --git a/lib/core/services/auth-guard-bpm.service.spec.ts b/lib/core/services/auth-guard-bpm.service.spec.ts index ace13e2e73..be4ddd1346 100644 --- a/lib/core/services/auth-guard-bpm.service.spec.ts +++ b/lib/core/services/auth-guard-bpm.service.spec.ts @@ -42,6 +42,7 @@ describe('AuthGuardService BPM', () => { appConfigService = TestBed.get(AppConfigService); appConfigService.config.providers = 'BPM'; + appConfigService.config.auth = {}; }); it('if the alfresco js api is logged in should canActivate be true', async(() => { @@ -51,6 +52,15 @@ describe('AuthGuardService BPM', () => { expect(authGuard.canActivate(null, router)).toBeTruthy(); })); + it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(() => { + spyOn(authService, 'isBpmLoggedIn').and.returnValue(true); + appConfigService.config.auth.withCredentials = true; + + const router: RouterStateSnapshot = {url : 'some-url'}; + + expect(authGuard.canActivate(null, router)).toBeTruthy(); + })); + it('if the alfresco js api is NOT logged in should canActivate be false', async(() => { spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); spyOn(routerService, 'navigate').and.stub(); diff --git a/lib/core/services/auth-guard-bpm.service.ts b/lib/core/services/auth-guard-bpm.service.ts index 9d01230e14..fda80502c2 100644 --- a/lib/core/services/auth-guard-bpm.service.ts +++ b/lib/core/services/auth-guard-bpm.service.ts @@ -25,7 +25,9 @@ import { OauthConfigModel } from '../models/oauth-config.model'; providedIn: 'root' }) export class AuthGuardBpm implements CanActivate, CanActivateChild { - constructor(private authService: AuthenticationService, private router: Router, private appConfig: AppConfigService) {} + + constructor(private authService: AuthenticationService, private router: Router, private appConfigService: AppConfigService) { + } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { return this.checkLogin(state.url); @@ -36,7 +38,9 @@ export class AuthGuardBpm implements CanActivate, CanActivateChild { } checkLogin(redirectUrl: string): boolean { - if (this.authService.isBpmLoggedIn()) { + let withCredentialsMode = this.appConfigService.get('auth.withCredentials', false); + + if (this.authService.isBpmLoggedIn() || withCredentialsMode) { return true; } @@ -50,11 +54,11 @@ export class AuthGuardBpm implements CanActivate, CanActivateChild { } isOAuthWithoutSilentLogin() { - let oauth: OauthConfigModel = this.appConfig.get(AppConfigValues.OAUTHCONFIG, null); + let oauth: OauthConfigModel = this.appConfigService.get(AppConfigValues.OAUTHCONFIG, null); return this.authService.isOauth() && oauth.silentLogin === false; } private getRouteDestinationForLogin(): string { - return this.appConfig && this.appConfig.get(AppConfigValues.LOGIN_ROUTE) ? this.appConfig.get(AppConfigValues.LOGIN_ROUTE) : 'login'; + return this.appConfigService && this.appConfigService.get(AppConfigValues.LOGIN_ROUTE) ? this.appConfigService.get(AppConfigValues.LOGIN_ROUTE) : 'login'; } } diff --git a/lib/core/services/auth-guard-ecm.service.spec.ts b/lib/core/services/auth-guard-ecm.service.spec.ts index 105f9cb5d1..19b72693ea 100644 --- a/lib/core/services/auth-guard-ecm.service.spec.ts +++ b/lib/core/services/auth-guard-ecm.service.spec.ts @@ -42,6 +42,7 @@ describe('AuthGuardService ECM', () => { appConfigService = TestBed.get(AppConfigService); appConfigService.config.providers = 'ECM'; + appConfigService.config.auth = {}; }); it('if the alfresco js api is logged in should canActivate be true', async(() => { @@ -51,6 +52,15 @@ describe('AuthGuardService ECM', () => { expect(authGuard.canActivate(null, router)).toBeTruthy(); })); + it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(() => { + spyOn(authService, 'isBpmLoggedIn').and.returnValue(true); + appConfigService.config.auth.withCredentials = true; + + const router: RouterStateSnapshot = {url : 'some-url'}; + + expect(authGuard.canActivate(null, router)).toBeTruthy(); + })); + it('if the alfresco js api is NOT logged in should canActivate be false', async(() => { spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(routerService, 'navigate').and.stub(); diff --git a/lib/core/services/auth-guard-ecm.service.ts b/lib/core/services/auth-guard-ecm.service.ts index fa4a5aacdf..6e1a4ae968 100644 --- a/lib/core/services/auth-guard-ecm.service.ts +++ b/lib/core/services/auth-guard-ecm.service.ts @@ -27,9 +27,10 @@ import { OauthConfigModel } from '../models/oauth-config.model'; providedIn: 'root' }) export class AuthGuardEcm implements CanActivate { + constructor(private authService: AuthenticationService, private router: Router, - private appConfig: AppConfigService) { + private appConfigService: AppConfigService) { } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { @@ -41,7 +42,9 @@ export class AuthGuardEcm implements CanActivate { } checkLogin(redirectUrl: string): boolean { - if (this.authService.isEcmLoggedIn()) { + let withCredentialsMode = this.appConfigService.get('auth.withCredentials', false); + + if (this.authService.isEcmLoggedIn() || withCredentialsMode) { return true; } @@ -55,13 +58,13 @@ export class AuthGuardEcm implements CanActivate { } isOAuthWithoutSilentLogin() { - let oauth: OauthConfigModel = this.appConfig.get(AppConfigValues.OAUTHCONFIG, null); + let oauth: OauthConfigModel = this.appConfigService.get(AppConfigValues.OAUTHCONFIG, null); return this.authService.isOauth() && oauth.silentLogin === false; } private getRouteDestinationForLogin(): string { - return this.appConfig && - this.appConfig.get(AppConfigValues.LOGIN_ROUTE) ? - this.appConfig.get(AppConfigValues.LOGIN_ROUTE) : 'login'; + return this.appConfigService && + this.appConfigService.get(AppConfigValues.LOGIN_ROUTE) ? + this.appConfigService.get(AppConfigValues.LOGIN_ROUTE) : 'login'; } } diff --git a/lib/core/services/auth-guard.service.spec.ts b/lib/core/services/auth-guard.service.spec.ts index 01315bb02e..137aab59a8 100644 --- a/lib/core/services/auth-guard.service.spec.ts +++ b/lib/core/services/auth-guard.service.spec.ts @@ -16,7 +16,7 @@ */ import { async, TestBed } from '@angular/core/testing'; -import { Router } from '@angular/router'; +import { Router, RouterStateSnapshot } from '@angular/router'; import { AppConfigService } from '../app-config/app-config.service'; import { AuthGuard } from './auth-guard.service'; import { AuthenticationService } from './authentication.service'; @@ -26,8 +26,8 @@ import { CoreTestingModule } from '../testing/core.testing.module'; describe('AuthGuardService', () => { let state; let authService: AuthenticationService; - let router: Router; - let service: AuthGuard; + let routerService: Router; + let authGuard: AuthGuard; let appConfigService: AppConfigService; setupTestBed({ @@ -38,80 +38,91 @@ describe('AuthGuardService', () => { localStorage.clear(); state = { url: '' }; authService = TestBed.get(AuthenticationService); - router = TestBed.get(Router); - service = TestBed.get(AuthGuard); + routerService = TestBed.get(Router); + authGuard = TestBed.get(AuthGuard); appConfigService = TestBed.get(AppConfigService); + + appConfigService.config.auth = {}; }); it('if the alfresco js api is logged in should canActivate be true', async(() => { - spyOn(router, 'navigate'); + spyOn(routerService, 'navigate'); spyOn(authService, 'isLoggedIn').and.returnValue(true); - expect(service.canActivate(null, state)).toBeTruthy(); - expect(router.navigate).not.toHaveBeenCalled(); + expect(authGuard.canActivate(null, state)).toBeTruthy(); + expect(routerService.navigate).not.toHaveBeenCalled(); })); it('if the alfresco js api is NOT logged in should canActivate be false', async(() => { state.url = 'some-url'; - spyOn(router, 'navigate'); + spyOn(routerService, 'navigate'); spyOn(authService, 'isLoggedIn').and.returnValue(false); - expect(service.canActivate(null, state)).toBeFalsy(); - expect(router.navigate).toHaveBeenCalled(); + expect(authGuard.canActivate(null, state)).toBeFalsy(); + expect(routerService.navigate).toHaveBeenCalled(); + })); + + it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(() => { + spyOn(authService, 'isBpmLoggedIn').and.returnValue(true); + appConfigService.config.auth.withCredentials = true; + + const router: RouterStateSnapshot = {url : 'some-url'}; + + expect(authGuard.canActivate(null, router)).toBeTruthy(); })); it('should set redirect url', async(() => { state.url = 'some-url'; appConfigService.config.loginRoute = 'login'; - spyOn(router, 'navigate'); + spyOn(routerService, 'navigate'); spyOn(authService, 'setRedirect'); - service.canActivate(null, state); + authGuard.canActivate(null, state); expect(authService.setRedirect).toHaveBeenCalledWith({ provider: 'ALL', url: 'some-url' }); - expect(router.navigate).toHaveBeenCalledWith(['/login']); + expect(routerService.navigate).toHaveBeenCalledWith(['/login']); })); it('should set redirect url with query params', async(() => { state.url = 'some-url;q=query'; appConfigService.config.loginRoute = 'login'; - spyOn(router, 'navigate'); + spyOn(routerService, 'navigate'); spyOn(authService, 'setRedirect'); - service.canActivate(null, state); + authGuard.canActivate(null, state); expect(authService.setRedirect).toHaveBeenCalledWith({ provider: 'ALL', url: 'some-url;q=query' }); - expect(router.navigate).toHaveBeenCalledWith(['/login']); + expect(routerService.navigate).toHaveBeenCalledWith(['/login']); })); it('should get redirect url from config if there is one configured', async(() => { state.url = 'some-url'; appConfigService.config.loginRoute = 'fakeLoginRoute'; - spyOn(router, 'navigate'); + spyOn(routerService, 'navigate'); spyOn(authService, 'setRedirect'); - service.canActivate(null, state); + authGuard.canActivate(null, state); expect(authService.setRedirect).toHaveBeenCalledWith({ provider: 'ALL', url: 'some-url' }); - expect(router.navigate).toHaveBeenCalledWith(['/fakeLoginRoute']); + expect(routerService.navigate).toHaveBeenCalledWith(['/fakeLoginRoute']); })); it('should pass actual redirect when no state segments exists', async(() => { state.url = '/'; - spyOn(router, 'navigate'); + spyOn(routerService, 'navigate'); spyOn(authService, 'setRedirect'); - service.canActivate(null, state); + authGuard.canActivate(null, state); expect(authService.setRedirect).toHaveBeenCalledWith({ provider: 'ALL', url: '/' diff --git a/lib/core/services/auth-guard.service.ts b/lib/core/services/auth-guard.service.ts index 4d0bf7e386..85217fcb02 100644 --- a/lib/core/services/auth-guard.service.ts +++ b/lib/core/services/auth-guard.service.ts @@ -31,7 +31,7 @@ import { OauthConfigModel } from '../models/oauth-config.model'; export class AuthGuard implements CanActivate, CanActivateChild { constructor(private authService: AuthenticationService, private router: Router, - private appConfig: AppConfigService) { + private appConfigService: AppConfigService) { } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean { @@ -44,7 +44,9 @@ export class AuthGuard implements CanActivate, CanActivateChild { } checkLogin(redirectUrl: string): boolean { - if (this.authService.isLoggedIn()) { + let withCredentialsMode = this.appConfigService.get('auth.withCredentials', false); + + if (this.authService.isLoggedIn() || withCredentialsMode) { return true; } if (!this.authService.isOauth() || this.isOAuthWithoutSilentLogin()) { @@ -58,13 +60,13 @@ export class AuthGuard implements CanActivate, CanActivateChild { } isOAuthWithoutSilentLogin() { - let oauth: OauthConfigModel = this.appConfig.get(AppConfigValues.OAUTHCONFIG, null); + let oauth: OauthConfigModel = this.appConfigService.get(AppConfigValues.OAUTHCONFIG, null); return this.authService.isOauth() && oauth.silentLogin === false; } public getRouteDestinationForLogin(): string { - return this.appConfig && - this.appConfig.get(AppConfigValues.LOGIN_ROUTE) ? - this.appConfig.get(AppConfigValues.LOGIN_ROUTE) : 'login'; + return this.appConfigService && + this.appConfigService.get(AppConfigValues.LOGIN_ROUTE) ? + this.appConfigService.get(AppConfigValues.LOGIN_ROUTE) : 'login'; } }