diff --git a/frontend/src/ts/modules/webbpm/interceptor/default-interceptors.prod.ts b/frontend/src/ts/modules/webbpm/interceptor/default-interceptors.prod.ts index 6cd9ffe..5079e05 100644 --- a/frontend/src/ts/modules/webbpm/interceptor/default-interceptors.prod.ts +++ b/frontend/src/ts/modules/webbpm/interceptor/default-interceptors.prod.ts @@ -1,14 +1,14 @@ import {HTTP_INTERCEPTORS} from "@angular/common/http"; import { FormDirtyInterceptor, - HttpSecurityErrorInterceptor, HttpSecurityInterceptor } from "@webbpm/base-package"; import {AbsoluteUrlCsrfInterceptor} from "./absolute-url-csrf.interceptor"; +import {ErvuHttpSecurityErrorInterceptor} from "./ervu-http-security-error-interceptor"; export const DEFAULT_HTTP_INTERCEPTOR_PROVIDERS = [ {provide: HTTP_INTERCEPTORS, useClass: HttpSecurityInterceptor, multi: true}, - {provide: HTTP_INTERCEPTORS, useClass: HttpSecurityErrorInterceptor, multi: true}, + {provide: HTTP_INTERCEPTORS, useClass: ErvuHttpSecurityErrorInterceptor, multi: true}, {provide: HTTP_INTERCEPTORS, useClass: FormDirtyInterceptor, multi: true}, {provide: HTTP_INTERCEPTORS, useClass: AbsoluteUrlCsrfInterceptor, multi: true} ]; diff --git a/frontend/src/ts/modules/webbpm/interceptor/default-interceptors.ts b/frontend/src/ts/modules/webbpm/interceptor/default-interceptors.ts index 77b3b40..8c9bf36 100644 --- a/frontend/src/ts/modules/webbpm/interceptor/default-interceptors.ts +++ b/frontend/src/ts/modules/webbpm/interceptor/default-interceptors.ts @@ -2,10 +2,11 @@ import {HTTP_INTERCEPTORS} from "@angular/common/http"; import {FormDirtyInterceptor, HttpSecurityInterceptor} from "@webbpm/base-package"; import {DevHttpSecurityErrorInterceptor} from "./http-security-error-interceptor.dev"; import {AbsoluteUrlCsrfInterceptor} from "./absolute-url-csrf.interceptor"; +import {ErvuHttpSecurityErrorInterceptor} from "./ervu-http-security-error-interceptor"; export const DEFAULT_HTTP_INTERCEPTOR_PROVIDERS = [ {provide: HTTP_INTERCEPTORS, useClass: HttpSecurityInterceptor, multi: true}, - {provide: HTTP_INTERCEPTORS, useClass: DevHttpSecurityErrorInterceptor, multi: true}, + {provide: HTTP_INTERCEPTORS, useClass: ErvuHttpSecurityErrorInterceptor, multi: true}, {provide: HTTP_INTERCEPTORS, useClass: FormDirtyInterceptor, multi: true}, {provide: HTTP_INTERCEPTORS, useClass: AbsoluteUrlCsrfInterceptor, multi: true}, ]; diff --git a/frontend/src/ts/modules/webbpm/interceptor/ervu-http-security-error-interceptor.ts b/frontend/src/ts/modules/webbpm/interceptor/ervu-http-security-error-interceptor.ts new file mode 100644 index 0000000..cda3da7 --- /dev/null +++ b/frontend/src/ts/modules/webbpm/interceptor/ervu-http-security-error-interceptor.ts @@ -0,0 +1,75 @@ +import { + HttpEvent, + HttpHandler, + HttpInterceptor, + HttpRequest +} from "@angular/common/http"; +import { + HttpSecurityErrorInterceptor, + MessagesService, + UserService +} from "@webbpm/base-package"; +import {Injectable} from "@angular/core"; +import {Router} from "@angular/router"; +import {Observable, throwError} from "rxjs"; +import {catchError} from "rxjs/operators"; + +@Injectable() +export class ErvuHttpSecurityErrorInterceptor extends HttpSecurityErrorInterceptor + implements HttpInterceptor { + private router: Router; + private _userService: UserService; + + + constructor(router: Router, messagesService: MessagesService, userService: UserService) { + super(router, messagesService, userService); + this.router = router; + this._userService = userService; + } + + intercept(req: HttpRequest, next: HttpHandler): Observable> { + + if (req.headers.has("Error-intercept-skip")) { + let isSkipped: string = req.headers.get("Error-intercept-skip"); + req.headers.delete("Error-intercept-skip"); + if (isSkipped == "true") { + return next.handle(req); + } + } + + return next.handle(req).pipe(catchError(error => { + switch (error.status) { + case 401: { + window.location.reload(); + break; + } + case 419: + case 440: { + console.log( + "Logout redirect applied due to response status " + error.status + + " received by HTTP Interceptor" + ); + this._userService.clearSessionStore(); + return throwError(error); + } + case 403: { + console.log( + "Access-Denied redirect applied due to response status " + error.status + + " received by HTTP Interceptor" + ); + this.router.navigateByUrl('/access-denied'); + return throwError(error); + } + case 422: { + console.log("Error " + error.status + " server response received by HTTP Interceptor"); + return throwError(error); + } + default: { + this._userService.hideProgressBar(); + console.log("Error " + error.status + " server response received by HTTP Interceptor"); + return throwError(error); + } + } + })); + } +} diff --git a/frontend/src/ts/modules/webbpm/interceptor/http-security-error-interceptor.dev.ts b/frontend/src/ts/modules/webbpm/interceptor/http-security-error-interceptor.dev.ts index 11a0c2b..29a711b 100644 --- a/frontend/src/ts/modules/webbpm/interceptor/http-security-error-interceptor.dev.ts +++ b/frontend/src/ts/modules/webbpm/interceptor/http-security-error-interceptor.dev.ts @@ -1,19 +1,18 @@ import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http"; -import {HttpSecurityErrorInterceptor, MessagesService, UserService} from "@webbpm/base-package"; +import {MessagesService, UserService} from "@webbpm/base-package"; import {Injectable} from "@angular/core"; import {Router} from "@angular/router"; import {EMPTY, Observable} from "rxjs"; import {catchError} from "rxjs/operators"; +import {ErvuHttpSecurityErrorInterceptor} from "./ervu-http-security-error-interceptor"; @Injectable() -export class DevHttpSecurityErrorInterceptor extends HttpSecurityErrorInterceptor +export class DevHttpSecurityErrorInterceptor extends ErvuHttpSecurityErrorInterceptor implements HttpInterceptor { - private router: Router; constructor(router: Router, messagesService: MessagesService, userService: UserService) { super(router, messagesService, userService); - this.router = router; } intercept(req: HttpRequest, next: HttpHandler): Observable> {