SUPPORT-8897: Fix

This commit is contained in:
Eduard Tihomirov 2025-02-17 14:01:53 +03:00
parent ad9c1ef68f
commit 003aea9fb2
8 changed files with 39 additions and 130 deletions

View file

@ -22,4 +22,13 @@ export class AuthenticationService {
public isAuthenticated(): boolean {
return this.cookieService.get('webbpm.ervu-lkrp-fl') != null;
}
public redirectToEsia() {
return this.http.get<string>("esia/url")
.toPromise()
.then(url => {
window.open(url, "_self");
return true;
});
}
}

View file

@ -65,15 +65,10 @@ export abstract class AuthGuard implements CanActivate {
return false;
}
else {
return this.httpClient.get<string>("esia/url")
.toPromise()
.then(url => {
window.open(url, "_self");
return true;
}).catch((reason)=> {
console.error(reason);
return false;
});
return this.authenticationService.redirectToEsia().catch((reason) => {
console.error(reason);
return false;
});
}
}).catch((reason) => {
console.error(reason);

View file

@ -13,76 +13,42 @@ import {
} from "@webbpm/base-package";
import {Injectable} from "@angular/core";
import {Router} from "@angular/router";
import {Observable, throwError} from "rxjs";
import {catchError} from "rxjs/operators";
import {from, Observable, throwError} from "rxjs";
import {catchError, map} from "rxjs/operators";
import {ErvuHttpInterceptorUtils} from "../../../util/ErvuHttpInterceptorUtils";
import {AuthenticationService} from "../../security/authentication.service";
@Injectable()
export class ErvuHttpSecurityErrorInterceptor extends HttpSecurityErrorInterceptor
implements HttpInterceptor {
private router: Router;
private _userService: UserService;
private _messagesService: MessagesService;
private authService: AuthenticationService;
constructor(router: Router, messagesService: MessagesService, userService: UserService) {
constructor(router: Router, messagesService: MessagesService, userService: UserService,
authService: AuthenticationService) {
super(router, messagesService, userService);
this.router = router;
this._userService = userService;
this._messagesService = messagesService;
this.authService = authService;
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
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");
this.processErrorResponseDataErvu(error);
return throwError(error);
}
}
}));
}
private processErrorResponseDataErvu(error: HttpErrorResponse) {
protected processErrorResponseData(error: HttpErrorResponse) {
let errorResponse: ErrorResponse = ErvuHttpInterceptorUtils.getErrorResponseFromResponse(error);
errorResponse.messages.forEach((errorMessage) => {
this._messagesService.error(errorMessage, errorResponse);
this.messagesService.error(errorMessage, errorResponse);
});
}
protected processAuthError(req: HttpRequest<any>, next: HttpHandler,
error: any): Observable<HttpEvent<any>> {
if (this.authService.isAuthenticated()) {
return super.processAuthError(req, next, error);
}
else {
return from(this.authService.redirectToEsia()).pipe(
map(() => null),
catchError((err) => {
throw err;
})
);
}
}
}