diff --git a/lib/core/login/components/login.component.spec.ts b/lib/core/login/components/login.component.spec.ts index 93d2f731d1..3019afc7c2 100644 --- a/lib/core/login/components/login.component.spec.ts +++ b/lib/core/login/components/login.component.spec.ts @@ -650,7 +650,7 @@ describe('LoginComponent', () => { }); })); - it('should show the login SSO button', async(() => { + it('should show the login SSO button', async(() => { spyOn(authService, 'isOauth').and.returnValue(true); component.ngOnInit(); diff --git a/lib/core/services/auth-guard-ecm.service.spec.ts b/lib/core/services/auth-guard-ecm.service.spec.ts index 20549d9730..6521229188 100644 --- a/lib/core/services/auth-guard-ecm.service.spec.ts +++ b/lib/core/services/auth-guard-ecm.service.spec.ts @@ -93,7 +93,30 @@ describe('AuthGuardService ECM', () => { expect(router.navigateByUrl).toHaveBeenCalled(); })); - it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => { + it('should not redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async(() => { + spyOn(router, 'navigateByUrl').and.stub(); + spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); + spyOn(authService, 'isOauth').and.returnValue(true); + spyOn(authService, 'isPublicUrl').and.returnValue(false); + spyOn(authService, 'ssoImplicitLogin').and.stub(); + + appConfigService.config.oauth2 = { + silentLogin: true, + host: 'http://localhost:6543', + redirectUri: '/', + clientId: 'activiti', + publicUrl: 'settings', + scope: 'openid' + }; + + const route: RouterStateSnapshot = {url : 'abc'}; + + expect(authGuard.canActivate(null, route)).toBeTruthy(); + expect(router.navigateByUrl).toHaveBeenCalledTimes(0); + expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1); + })); + + it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); diff --git a/lib/core/services/auth-guard-ecm.service.ts b/lib/core/services/auth-guard-ecm.service.ts index 2a459e7cd2..5d15daad12 100644 --- a/lib/core/services/auth-guard-ecm.service.ts +++ b/lib/core/services/auth-guard-ecm.service.ts @@ -42,6 +42,10 @@ export class AuthGuardEcm extends AuthGuardBase { return true; } this.redirectToUrl('ECM', redirectUrl); + if (!this.authenticationService.isEcmLoggedIn() && this.isSilentLogin() && !this.authenticationService.isPublicUrl()) { + this.authenticationService.ssoImplicitLogin(); + return true; + } return false; } } diff --git a/lib/core/services/authentication.service.ts b/lib/core/services/authentication.service.ts index 7c5cdf4dae..8def6339c3 100644 --- a/lib/core/services/authentication.service.ts +++ b/lib/core/services/authentication.service.ts @@ -69,6 +69,10 @@ export class AuthenticationService { return this.alfrescoApi.getInstance().isOauthConfiguration(); } + isPublicUrl(): boolean { + return this.alfrescoApi.getInstance().isPublicUrl(); + } + /** * Does the provider support ECM? * @returns True if supported, false otherwise