Fix loop scenario when the login page is not present in silent login (#6512)

* fix loop scenario when the login page is not present in silent login

* fix build

* fix

* remove isECM

* fix unit

* fix
This commit is contained in:
Eugenio Romano
2021-01-11 09:31:11 +00:00
committed by GitHub
parent 62cec5c5b4
commit 8e12e51fb3
7 changed files with 88 additions and 36 deletions

View File

@@ -35,11 +35,6 @@ import { Observable } from 'rxjs';
export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
abstract checkLogin(
activeRoute: ActivatedRouteSnapshot,
redirectUrl: string
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree;
protected get withCredentials(): boolean {
return this.appConfigService.get<boolean>(
'auth.withCredentials',
@@ -55,6 +50,12 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
private storageService: StorageService
) {
}
ls;
abstract checkLogin(
activeRoute: ActivatedRouteSnapshot,
redirectUrl: string
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree;
canActivate(
route: ActivatedRouteSnapshot,
@@ -62,7 +63,7 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const redirectFragment = this.storageService.getItem('loginFragment');
if (this.authenticationService.isEcmLoggedIn() || this.withCredentials) {
if (this.authenticationService.isLoggedIn() || this.withCredentials) {
if (redirectFragment) {
this.storageService.removeItem('loginFragment');
return this.router.createUrlTree([redirectFragment]);
@@ -85,20 +86,34 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.canActivate(route, state);
}
protected redirectToUrl(provider: string, url: string) {
const pathToLogin = `/${this.getLoginRoute()}`;
let urlToRedirect;
this.dialog.closeAll();
if (!this.authenticationService.isOauth()) {
this.authenticationService.setRedirect({ provider, url });
urlToRedirect = `${pathToLogin}?redirectUrl=${url}`;
this.router.navigateByUrl(urlToRedirect);
} else if (this.getOauthConfig().silentLogin && !this.authenticationService.isPublicUrl()) {
this.authenticationService.ssoImplicitLogin();
} else {
urlToRedirect = pathToLogin;
this.router.navigateByUrl(urlToRedirect);
}
this.dialog.closeAll();
this.router.navigateByUrl(urlToRedirect);
}
protected getOauthConfig(): OauthConfigModel {
return (
this.appConfigService &&
this.appConfigService.get<OauthConfigModel>(
AppConfigValues.OAUTHCONFIG,
null
)
);
}
protected getLoginRoute(): string {