webin-authentication.interceptor.ts 2.23 KB
Newer Older
Rasko Leinonen's avatar
Rasko Leinonen committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * Copyright 2018 EMBL - European Bioinformatics Institute
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

12
import {Injectable, Injector} from '@angular/core';
13
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';
Rasko Leinonen's avatar
Rasko Leinonen committed
14
import { Observable } from 'rxjs';
15
16

import { WebinAuthenticationService } from './webin-authentication.service';
17
import { environment } from '../environments/environment';
18
19
20
21
22
23
24
25

@Injectable()
export class WebinAuthenticationInterceptor implements HttpInterceptor {

  constructor(private injector: Injector) {}

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

26
  console.log(req.url);
27
  
28
29
    if (!req.url.startsWith(environment.webinAuthenticationServiceUrl) &&
        !req.url.startsWith(environment.webinReportServiceUrl + "/checklist-groups") &&
30
31
        !req.url.startsWith(environment.webinReportServiceUrl + "/checklists") &&
        !req.url.startsWith(environment.webinAuthenticationTokenUrl) &&
32
        !(req.url.startsWith(environment.webinAdminServiceUrl + "/submission-account") && req.method==="POST") &&
rajkumar's avatar
rajkumar committed
33
34
        !req.url.startsWith(environment.webinAdminServiceUrl + "/country") && 
        !req.url.startsWith(environment.pupMedUrl) && 
35
        !req.url.startsWith(environment.webinAdminServiceUrl + "/request-password-change")) {
36
       //console.log('Webin authentication interceptor');
37
      const webinAuthenticationService = this.injector.get(WebinAuthenticationService);
rajkumar's avatar
rajkumar committed
38
      //console.log(webinAuthenticationService.getAuthorizationTokenHeader())
39
40
      const authReq = req.clone({headers: req.headers.set('Authorization', webinAuthenticationService.getAuthorizationTokenHeader())});
      return next.handle(authReq);
41

42
    } else {
43
       return next.handle(req);
44
45
    }
  }
46
}