diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index d02292bf..d0eee28d 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -3,9 +3,8 @@ import {Routes, RouterModule} from '@angular/router'; import {AuthGuard} from './auth/auth-guard.guard'; import {AuthService} from './auth/auth.service'; import {DashboardComponent} from './view/dashboard/dashboard.component'; -import {environment} from '../environments/environment'; -const guards: any[] = environment.authentication ? [AuthGuard] : []; +const guards: any[] = [AuthGuard]; const routes: Routes = [ {path: '', redirectTo: '/dashboard', pathMatch: 'full'}, diff --git a/src/app/auth/auth-guard.guard.ts b/src/app/auth/auth-guard.guard.ts index efc0b73a..a3e3383a 100644 --- a/src/app/auth/auth-guard.guard.ts +++ b/src/app/auth/auth-guard.guard.ts @@ -1,19 +1,24 @@ import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { CanActivate, UrlTree } from '@angular/router'; import { Auth } from 'aws-amplify'; +import { Globals } from '../model/portCall/globals'; @Injectable({ providedIn: 'root' }) export class AuthGuard implements CanActivate { - - async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { - try { - const session = await Auth.currentSession() - return session.isValid() - } catch(e) { - return false; + constructor( + private globals: Globals, + ) { } + async canActivate(): Promise { + if (this.globals.config.authentication === true) { + try { + const session = await Auth.currentSession() + return session.isValid() + } catch (e) { + return false; + } } - + return true; } } diff --git a/src/app/controller/services/base/config.service.ts b/src/app/controller/services/base/config.service.ts index 4b95e34a..66b98089 100644 --- a/src/app/controller/services/base/config.service.ts +++ b/src/app/controller/services/base/config.service.ts @@ -32,6 +32,5 @@ export class ConfigService { resolve(); }); }); - } } diff --git a/src/app/model/jit/config.ts b/src/app/model/jit/config.ts index f70ae833..c854dab8 100644 --- a/src/app/model/jit/config.ts +++ b/src/app/model/jit/config.ts @@ -15,5 +15,6 @@ export interface Config { authUserPoolWebClientId: string; authRedirectUriSignIn: string; enableShowTimestampsAsJSON: boolean | null; + authentication: boolean | null; } diff --git a/src/app/model/portCall/globals.ts b/src/app/model/portCall/globals.ts index 36de5529..41cccc9f 100644 --- a/src/app/model/portCall/globals.ts +++ b/src/app/model/portCall/globals.ts @@ -1,6 +1,4 @@ import {Injectable} from '@angular/core'; -import {Port} from "./port"; -import {Terminal} from "./terminal"; import {Config} from "../jit/config"; @Injectable() diff --git a/src/app/view/app.component.ts b/src/app/view/app.component.ts index 2c6aef96..411effaf 100644 --- a/src/app/view/app.component.ts +++ b/src/app/view/app.component.ts @@ -1,10 +1,8 @@ import {Port} from "../model/portCall/port"; import {TranslateService} from "@ngx-translate/core"; -import {TransportCall} from "../model/jit/transport-call"; -import { Timestamp } from '../model/jit/timestamp'; import { Component, ChangeDetectorRef, OnInit, OnDestroy, NgZone } from '@angular/core'; import { onAuthUIStateChange, CognitoUserInterface, AuthState } from '@aws-amplify/ui-components'; -import { environment } from "src/environments/environment"; +import { Globals } from "../model/portCall/globals"; import { Router } from "@angular/router"; import {AuthService} from "../auth/auth.service"; @@ -28,13 +26,14 @@ export class AppComponent implements OnInit, OnDestroy { private authService: AuthService, private ref: ChangeDetectorRef, private zone: NgZone, - private router: Router) { + private router: Router, + private globals: Globals) { translate.setDefaultLang('en'); translate.use('en'); } ngOnInit() { - this.authLocalState = environment.authentication; + this.authLocalState = this.globals.config.authentication; this.stateChange = onAuthUIStateChange((authState, authData) => { this.authState = authState; this.user = authData as CognitoUserInterface; diff --git a/src/app/view/dashboard/dashboard.component.spec.ts b/src/app/view/dashboard/dashboard.component.spec.ts deleted file mode 100644 index 5ec4ff8f..00000000 --- a/src/app/view/dashboard/dashboard.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { DashboardComponent } from './dashboard.component'; - -describe('DashboardComponent', () => { - let component: DashboardComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ DashboardComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(DashboardComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/view/header/header.component.ts b/src/app/view/header/header.component.ts index 58c9439e..90ec533e 100644 --- a/src/app/view/header/header.component.ts +++ b/src/app/view/header/header.component.ts @@ -5,7 +5,6 @@ import { MenuItem, MessageService, SelectItem } from "primeng/api"; import { TranslateService } from "@ngx-translate/core"; import { Globals } from "../../model/portCall/globals"; import { ExportService } from "../../controller/services/base/export.service"; -import { environment } from "src/environments/environment"; import {take} from "rxjs"; @Component({ @@ -65,7 +64,7 @@ export class HeaderComponent implements OnInit { ] } ]; - this.authLocalState = environment.authentication; + this.authLocalState = this.globals.config.authentication; } showInstructions() { diff --git a/src/assets/config.json b/src/assets/config.json index 7f1b8ce1..bc65388f 100644 --- a/src/assets/config.json +++ b/src/assets/config.json @@ -18,10 +18,10 @@ "uiSupportBackendURL": "http://localhost:9091/ui-support/v1", "jitBackendURL": "http://localhost:9090/jit/v1", "dateTimeFormat": "dd MMM yyyy HH:mm", - "authRegion":"eu-west-1", + "authRegion": "eu-west-1", "authUserPoolId": "eu-west-1_khrRmnDXz", "authUserPoolWebClientId": "5qgd24cfb8m4sm6bkrfk55cqfr", - "authRedirectUriSignIn":"/dashboard", - "enableShowTimestampsAsJSON": true -} - + "authRedirectUriSignIn": "/dashboard", + "enableShowTimestampsAsJSON": true, + "authentication": false +} \ No newline at end of file diff --git a/src/assets/devconfig.json b/src/assets/devconfig.json index 4085c798..997381a8 100644 --- a/src/assets/devconfig.json +++ b/src/assets/devconfig.json @@ -1,27 +1,27 @@ { - "id": "be5bc290-7bac-48bb-a211-f3fa5a3ab3ae", - "company": "DCSA", - "publisher": { - "partyName": "Test publisher", - "taxReference1": null, - "taxReference2": null, - "address": null, - "identifyingCodes": [ - { - "DCSAResponsibleAgencyCode": "SMDG", - "partyCode": "MSK", - "codeListName": "LCL" - } - ] - }, - "publisherRoles": ["CA", "AG", "VSL", "TR", "ATH", "PLT", "TWG", "BUK", "LSH", "SLU", "SVP", "MOR"], - "uiSupportBackendURL": "/uisupport", - "jitBackendURL": "/jit", - "dateTimeFormat": "dd MMM yyyy HH:mm", - "authRegion":"eu-west-1", - "authUserPoolId": "eu-west-1_khrRmnDXz", - "authUserPoolWebClientId": "5qgd24cfb8m4sm6bkrfk55cqfr", - "authRedirectUriSignIn":"/dashboard", - "enableShowTimestampsAsJSON": true -} - + "id": "be5bc290-7bac-48bb-a211-f3fa5a3ab3ae", + "company": "DCSA", + "publisher": { + "partyName": "Test publisher", + "taxReference1": null, + "taxReference2": null, + "address": null, + "identifyingCodes": [ + { + "DCSAResponsibleAgencyCode": "SMDG", + "partyCode": "MSK", + "codeListName": "LCL" + } + ] + }, + "publisherRoles": ["CA", "AG", "VSL", "TR", "ATH", "PLT", "TWG", "BUK", "LSH", "SLU", "SVP", "MOR"], + "uiSupportBackendURL": "/uisupport", + "jitBackendURL": "/jit", + "dateTimeFormat": "dd MMM yyyy HH:mm", + "authRegion": "eu-west-1", + "authUserPoolId": "eu-west-1_khrRmnDXz", + "authUserPoolWebClientId": "5qgd24cfb8m4sm6bkrfk55cqfr", + "authRedirectUriSignIn": "/dashboard", + "enableShowTimestampsAsJSON": true, + "authentication": false +} \ No newline at end of file diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 08b632cc..6622d9ac 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,6 +1,5 @@ export const environment = { - production: true, - authentication: true + production: true }; // define Server here, if you are not in production mode and want to have another server than http://localhost:8080 diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 4be2aaff..ed76543e 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -3,8 +3,7 @@ // The list of file replacements can be found in `angular.json`. export const environment = { - production: false, - authentication: false + production: false }; export const BACKEND_URL = window.location.origin + "/api";