mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Should not redirect if is SilentLogin on (#5216)
* fix redirect * fix lint * remove false behaviour alrady tested in the new unit test * Update auth-guard-base.ts
This commit is contained in:
committed by
Denys Vuika
parent
3c1097fb84
commit
5578b7b851
@@ -64,12 +64,14 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected redirectToUrl(provider: string, url: string) {
|
protected redirectToUrl(provider: string, url: string) {
|
||||||
this.authenticationService.setRedirect({ provider, url });
|
if (!this.isSilentLogin()) {
|
||||||
|
this.authenticationService.setRedirect({ provider, url });
|
||||||
|
|
||||||
const pathToLogin = this.getLoginRoute();
|
const pathToLogin = this.getLoginRoute();
|
||||||
const urlToRedirect = `/${pathToLogin}?redirectUrl=${url}`;
|
const urlToRedirect = `/${pathToLogin}?redirectUrl=${url}`;
|
||||||
|
|
||||||
this.router.navigateByUrl(urlToRedirect);
|
this.router.navigateByUrl(urlToRedirect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getLoginRoute(): string {
|
protected getLoginRoute(): string {
|
||||||
@@ -91,4 +93,13 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
|
|||||||
this.authenticationService.isOauth() && !!oauth && !oauth.silentLogin
|
this.authenticationService.isOauth() && !!oauth && !oauth.silentLogin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected isSilentLogin(): boolean {
|
||||||
|
const oauth = this.appConfigService.get<OauthConfigModel>(
|
||||||
|
AppConfigValues.OAUTHCONFIG,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
return this.authenticationService.isOauth() && oauth && oauth.silentLogin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -92,17 +92,6 @@ describe('AuthGuardService BPM', () => {
|
|||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
expect(router.navigateByUrl).toHaveBeenCalled();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithSilentLogin', async(() => {
|
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
|
||||||
appConfigService.config.oauth2.silentLogin = true;
|
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
|
|
||||||
|
|
||||||
expect(authGuard.canActivate(null, route)).toBeFalsy();
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => {
|
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => {
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
||||||
|
@@ -92,17 +92,6 @@ describe('AuthGuardService ECM', () => {
|
|||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
expect(router.navigateByUrl).toHaveBeenCalled();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithSilentLogin', async(() => {
|
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
|
||||||
appConfigService.config.oauth2.silentLogin = true;
|
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
|
|
||||||
|
|
||||||
expect(authGuard.canActivate(null, route)).toBeFalsy();
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => {
|
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => {
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
||||||
|
@@ -72,7 +72,7 @@ describe('AuthGuardService', () => {
|
|||||||
expect(authGuard.canActivate(null, route)).toBeTruthy();
|
expect(authGuard.canActivate(null, route)).toBeTruthy();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(() => {
|
it('should redirect url if the User is NOT logged in and isOAuthWithoutSilentLogin', async(() => {
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
@@ -82,17 +82,7 @@ describe('AuthGuardService', () => {
|
|||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
expect(router.navigateByUrl).toHaveBeenCalled();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithSilentLogin', async(() => {
|
it('should redirect url if the User is NOT logged in and isOAuth but no silentLogin configured', async(() => {
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
|
||||||
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
|
||||||
appConfigService.config.oauth2.silentLogin = true;
|
|
||||||
|
|
||||||
expect(authGuard.canActivate(null, state)).toBeFalsy();
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => {
|
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
@@ -102,6 +92,16 @@ describe('AuthGuardService', () => {
|
|||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
expect(router.navigateByUrl).toHaveBeenCalled();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should NOT redirect url if the User is NOT logged in and isOAuth but with silentLogin configured', async(() => {
|
||||||
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
|
appConfigService.config.oauth2.silentLogin = true;
|
||||||
|
|
||||||
|
expect(authGuard.canActivate(null, state)).toBeFalsy();
|
||||||
|
expect(router.navigateByUrl).not.toHaveBeenCalled();
|
||||||
|
}));
|
||||||
|
|
||||||
it('should set redirect url', async(() => {
|
it('should set redirect url', async(() => {
|
||||||
state.url = 'some-url';
|
state.url = 'some-url';
|
||||||
appConfigService.config.loginRoute = 'login';
|
appConfigService.config.loginRoute = 'login';
|
||||||
|
Reference in New Issue
Block a user