From 04f9a4303f4978c1074afb8b5731b7509d338b35 Mon Sep 17 00:00:00 2001 From: FORESTIER Fabien <fabien.forestier@soprasteria.com> Date: Wed, 17 Oct 2018 16:32:31 +0200 Subject: [PATCH] Disable request cache in elasticsearchService with option in environment, remove lazy loading for geosource module, redirect to oidc login page for 401 unauthorized response --- src/app/app-routing.module.ts | 8 ++++---- src/app/core/interceptors/auth-interceptor.ts | 1 - .../http-error-response-interceptor.ts | 11 +++++++--- src/app/core/services/auth.service.ts | 6 +++--- .../editorialisation.module.ts | 1 - .../services/actors.service.ts | 2 +- src/app/geosource/geosource-routing.module.ts | 2 +- .../services/elasticsearch.service.ts | 2 +- src/environments/environment.prod.ts | 20 ++++++++++--------- src/environments/environment.ts | 15 ++++++++------ 10 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 06ff11ae..2c744415 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -3,10 +3,10 @@ import { Routes, RouterModule, PreloadAllModules } from '@angular/router'; import { AppRoutes } from './routes'; export const routes: Routes = [ - { - path: AppRoutes.research.uri, - loadChildren: './geosource/geosource.module#GeosourceModule', - }, + // { + // path: AppRoutes.research.uri, + // loadChildren: './geosource/geosource.module#GeosourceModule', + // }, ]; @NgModule({ diff --git a/src/app/core/interceptors/auth-interceptor.ts b/src/app/core/interceptors/auth-interceptor.ts index 37f8d62f..88158686 100644 --- a/src/app/core/interceptors/auth-interceptor.ts +++ b/src/app/core/interceptors/auth-interceptor.ts @@ -1,7 +1,6 @@ import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import { environment } from '../../../environments/environment.prod'; @Injectable() export class AuthInterceptor implements HttpInterceptor { diff --git a/src/app/core/interceptors/http-error-response-interceptor.ts b/src/app/core/interceptors/http-error-response-interceptor.ts index f5381084..0445fe9f 100644 --- a/src/app/core/interceptors/http-error-response-interceptor.ts +++ b/src/app/core/interceptors/http-error-response-interceptor.ts @@ -6,10 +6,15 @@ import { HttpEvent, HttpResponse, HttpErrorResponse, } from '@angular/common/http'; import { tap } from 'rxjs/operators'; +import { environment } from '../../../environments/environment'; +import { Router } from '@angular/router'; +import { AppRoutes } from '../../routes'; @Injectable() export class HttpErrorResponseInterceptor implements HttpInterceptor { - constructor() { } + constructor( + private router: Router, + ) { } intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { return next.handle(req).pipe(tap( (event: HttpEvent<any>) => { @@ -23,6 +28,8 @@ export class HttpErrorResponseInterceptor implements HttpInterceptor { switch (err.status) { case 401: console.log('HTTP ERROR: Unauthorized'); + window.location.href = environment.oidcLoginEndpoint; + // this.router.navigate(['/', AppRoutes.signin.uri]) break; case 403: console.log('HTTP ERROR: Forbidden'); @@ -30,8 +37,6 @@ export class HttpErrorResponseInterceptor implements HttpInterceptor { case 404: console.log('HTTP ERROR: Not Found'); break; - case 301: - console.log('Redirection !!!!!!'); case 500: case 502: case 503: diff --git a/src/app/core/services/auth.service.ts b/src/app/core/services/auth.service.ts index a3c874b2..37be76ac 100644 --- a/src/app/core/services/auth.service.ts +++ b/src/app/core/services/auth.service.ts @@ -31,7 +31,7 @@ export class AuthService { exchangeOidcCode(code: string): Observable<boolean> { console.log('[x] Exchanging code'); - const url = `${env.kongUrl}/authentication/api/oidc/token?code=${code}`; + const url = `${env.kongUrl}/authentication/oidc/token?code=${code}`; return this._http.get<ILoginResponse>(url).pipe( map( (res) => { @@ -48,7 +48,7 @@ export class AuthService { exchangeGlcCode(code: string): Observable<boolean> { console.log('[x] Exchanging code'); - const url = `${env.kongUrl}/authentication/api/glc/token?code=${code}`; + const url = `${env.kongUrl}/authentication/glc/token?code=${code}`; return this._http.get<ILoginResponse>(url).pipe( map( (res) => { @@ -102,7 +102,7 @@ export class AuthService { } catch (error) { } - let url = `${env.kongUrl}/authentication/api/logout?`; + let url = `${env.kongUrl}/authentication/logout?`; url += `id_token=${idToken}&identity_provider=${identityProvider}`; window.location.href = url; diff --git a/src/app/editorialisation/editorialisation.module.ts b/src/app/editorialisation/editorialisation.module.ts index 080de402..24092e52 100644 --- a/src/app/editorialisation/editorialisation.module.ts +++ b/src/app/editorialisation/editorialisation.module.ts @@ -6,7 +6,6 @@ import { EditorialisationServices } from './services'; import { EditorialisationResolvers } from './resolvers'; import { SharedModule } from '../shared/shared.module'; import { GeosourceModule } from '../geosource/geosource.module'; -import { DatasetResearchService } from '../geosource/services'; @NgModule({ imports: [ diff --git a/src/app/editorialisation/services/actors.service.ts b/src/app/editorialisation/services/actors.service.ts index 523938c0..984c23de 100644 --- a/src/app/editorialisation/services/actors.service.ts +++ b/src/app/editorialisation/services/actors.service.ts @@ -13,7 +13,7 @@ export class ActorsService { ) { } getActors() { - return this._httpClient.get<IActor[]>(environment.backend.url + '/organizations').pipe( + return this._httpClient.get<IActor[]>(environment.organizations.url).pipe( map((actorsLoopback) => { const actors = []; actorsLoopback.forEach((actor) => { diff --git a/src/app/geosource/geosource-routing.module.ts b/src/app/geosource/geosource-routing.module.ts index e1ccd324..d17b0023 100644 --- a/src/app/geosource/geosource-routing.module.ts +++ b/src/app/geosource/geosource-routing.module.ts @@ -6,7 +6,7 @@ import { AppRoutes } from '../routes'; export const routes: Routes = [ { - path: '', + path: AppRoutes.research.uri, component: ResearchComponent, data: { title: AppRoutes.research.title, diff --git a/src/app/geosource/services/elasticsearch.service.ts b/src/app/geosource/services/elasticsearch.service.ts index 84f0a0a8..9a9b0a4b 100644 --- a/src/app/geosource/services/elasticsearch.service.ts +++ b/src/app/geosource/services/elasticsearch.service.ts @@ -28,7 +28,7 @@ export class ElasticsearchService { getFullDataList(options: ElasticsearchOptions): Observable<IElasticsearchResponse> { const requestOptions = this.constructElasticsearchRequest(options); const request = this._storageService.get('requestES'); - if (request === JSON.stringify(requestOptions)) { + if (environment.enableEsFrontCache === true && request === JSON.stringify(requestOptions)) { const jsonESResponse = JSON.parse(this._storageService.get('resultES')) as IElasticsearchResponse; return of(jsonESResponse); } diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index a4bb4a9e..c37be8b3 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -5,27 +5,29 @@ import { AppRoutes } from '../app/routes'; // `ng build --env=prod` then `environment.prod.ts` will be used instead. // The list of which env maps to which file can be found in `.angular-cli.json`. const servicesProxyUrl = 'https://data-intothesky.alpha.grandlyon.com'; -const kongUrl = 'https://kong.alpha.grandlyon.com'; +const kongBaseUrl = 'https://kong.alpha.grandlyon.com'; export const environment = { - kongUrl, production: true, - oidcLoginEndpoint: kongUrl + '/authentication/api/oidc/login', - glcLoginEndpoint: kongUrl + '/authentication/api/glc/login', - logoutEndpoint: kongUrl + '/authentication/api/logout', + kongUrl: kongBaseUrl, + oidcLoginEndpoint: kongBaseUrl + '/authentication/oidc/login', + glcLoginEndpoint: kongBaseUrl + '/authentication/glc/login', + logoutEndpoint: kongBaseUrl + '/authentication/logout', // ElasticSearch elasticsearchUrl: { - full: kongUrl + '/elasticsearch/test-all-in-one-index.full.v8.quadtree', - meta: servicesProxyUrl + '/elasticsearch/*.meta', + full: kongBaseUrl + '/es-consumer-aware', + meta: kongBaseUrl + '/elasticsearch/*.meta', }, + enableEsFrontCache: false, + matomo: { url: 'https://matomo-intothesky.alpha.grandlyon.com', }, - backend: { - url: servicesProxyUrl + '/backend', + organizations: { + url: kongBaseUrl + '/organizations', }, // Path to the built app in a particular language diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 3ca6ad00..ec5d50ed 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -5,27 +5,30 @@ import { AppRoutes } from '../app/routes'; // `ng build --env=prod` then `environment.prod.ts` will be used instead. // The list of which env maps to which file can be found in `.angular-cli.json`. const servicesProxyUrl = 'https://data-intothesky.alpha.grandlyon.com'; -const kongUrl = 'https://kong.alpha.grandlyon.com'; +const kongBaseUrl = 'https://kong.alpha.grandlyon.com'; export const environment = { - kongUrl, production: false, - oidcLoginEndpoint: '', + kongUrl: kongBaseUrl, + oidcLoginEndpoint: kongBaseUrl + '/authentication/oidc/login', glcLoginEndpoint: '', logoutEndpoint: '', // ElasticSearch elasticsearchUrl: { - full: servicesProxyUrl + '/elasticsearch2/test-all-in-one-index.full.v8.quadtree', + // full: servicesProxyUrl + '/elasticsearch2/test-all-in-one-index.full.v8.quadtree', + full: kongBaseUrl + '/es-consumer-aware', meta: servicesProxyUrl + '/elasticsearch/*.meta', }, + enableEsFrontCache: true, + matomo: { url: 'https://matomo-intothesky.alpha.grandlyon.com', }, - backend: { - url: 'http://localhost:3000', + organizations: { + url: kongBaseUrl + '/organizations', }, // Path to the built app in a particular language -- GitLab