Project

General

Profile

« Previous | Next » 

Revision 59965

[Library | Trunk]: Add unauthorized whitelist to avoid logout in certain calls

View differences:

modules/uoa-services-library/trunk/ng-openaire-library/src/app/services/user-management.service.ts
62 62
        if(resolve) {
63 63
          resolve();
64 64
        }
65
      });
65
      }, error => {
66
       this.getUserInfoSubject.next(null);
67
       if(resolve) {
68
         resolve();
69
       }
70
     });
66 71
    }
67 72
  }
68 73
  
modules/uoa-services-library/trunk/ng-openaire-library/src/app/error-interceptor.service.ts
6 6
import {Router} from "@angular/router";
7 7
import {LoginErrorCodes} from "./login/utils/guardHelper.class";
8 8
import {properties} from "../../environments/environment";
9
import {isArray} from "util";
10
import {element} from "@angular/core/src/render3";
9 11

  
10 12
@Injectable()
11 13
export class ErrorInterceptorService implements HttpInterceptor {
12 14
  
15
  private static UNAUTHORIZED_WHITELIST = [properties.userInfoUrl];
16
  
13 17
  constructor(private router: Router) {
14 18
  }
15 19
  
16 20
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
17 21
    return next.handle(req).pipe(catchError(err => {
18
      if ((err.status === 0 && this.isRegistryService(req)) || err.status === 401 || err.status === 403) {
22
      if ((err.status === 0 && this.isService(req, properties.registryUrl)) ||
23
        (err.status === 401 && !this.isService(req, ErrorInterceptorService.UNAUTHORIZED_WHITELIST)) || err.status === 403) {
19 24
        this.logOut();
20 25
      }
21 26
      return throwError(err);
22 27
    }));
23 28
  }
24 29
  
25
  isRegistryService(req: HttpRequest<any>):boolean {
26
    return req.url.indexOf(properties.registryUrl) !== -1;
30
  isService(req: HttpRequest<any>, service: string | string[]):boolean {
31
    if(isArray(service)) {
32
      return !!service.find(element => req.url.indexOf(element) !== -1);
33
    } else {
34
      return req.url.indexOf(service) !== -1;
35
    }
27 36
  }
28 37
  
29 38
  logOut() {

Also available in: Unified diff