From f2ff8cfe8a7d9ecd3da507bcc46d289529d756e6 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Wed, 25 Nov 2020 16:45:41 +0000 Subject: [PATCH] [Library | Trunk]: Add unauthorized whitelist to avoid logout in certain calls git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59965 d315682c-612b-4755-9ff5-7f18f6832af3 --- error-interceptor.service.ts | 15 ++++++++++++--- services/user-management.service.ts | 7 ++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/error-interceptor.service.ts b/error-interceptor.service.ts index 0c27810d..2dbe2f68 100644 --- a/error-interceptor.service.ts +++ b/error-interceptor.service.ts @@ -6,24 +6,33 @@ import {Session} from "./login/utils/helper.class"; import {Router} from "@angular/router"; import {LoginErrorCodes} from "./login/utils/guardHelper.class"; import {properties} from "../../environments/environment"; +import {isArray} from "util"; +import {element} from "@angular/core/src/render3"; @Injectable() export class ErrorInterceptorService implements HttpInterceptor { + private static UNAUTHORIZED_WHITELIST = [properties.userInfoUrl]; + constructor(private router: Router) { } intercept(req: HttpRequest, next: HttpHandler): Observable> { return next.handle(req).pipe(catchError(err => { - if ((err.status === 0 && this.isRegistryService(req)) || err.status === 401 || err.status === 403) { + if ((err.status === 0 && this.isService(req, properties.registryUrl)) || + (err.status === 401 && !this.isService(req, ErrorInterceptorService.UNAUTHORIZED_WHITELIST)) || err.status === 403) { this.logOut(); } return throwError(err); })); } - isRegistryService(req: HttpRequest):boolean { - return req.url.indexOf(properties.registryUrl) !== -1; + isService(req: HttpRequest, service: string | string[]):boolean { + if(isArray(service)) { + return !!service.find(element => req.url.indexOf(element) !== -1); + } else { + return req.url.indexOf(service) !== -1; + } } logOut() { diff --git a/services/user-management.service.ts b/services/user-management.service.ts index e40f93c4..310be3f6 100644 --- a/services/user-management.service.ts +++ b/services/user-management.service.ts @@ -62,7 +62,12 @@ export class UserManagementService{ if(resolve) { resolve(); } - }); + }, error => { + this.getUserInfoSubject.next(null); + if(resolve) { + resolve(); + } + }); } }