From 4a9b3cf4610b4598dbf585474d2e76a091c7a09d Mon Sep 17 00:00:00 2001 From: Subham Date: Thu, 10 Nov 2022 12:43:23 +0530 Subject: [PATCH] Changes to disable auth and set default tenant (#52) --- .gitpod.yml | 9 +++++++++ src/app/core/authentication/authentication.guard.ts | 5 ++++- .../core/authentication/authentication.interceptor.ts | 6 ++++++ src/app/core/authentication/authentication.service.ts | 2 +- src/app/core/shell/sidenav/sidenav.component.ts | 8 ++++++-- src/app/home/home.component.ts | 6 +++++- .../incoming/incoming-transactions.component.ts | 6 +++++- .../outgoing/outgoing-transactions.component.ts | 6 +++++- src/assets/configuration.properties | 5 +++-- src/environments/environment.kubernetes.ts | 6 +++++- src/environments/environment.prod.ts | 6 +++++- src/environments/environment.ts | 8 ++++++-- 12 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000..b7c1d365 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,9 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) +# and commit this file to your remote git repository to share the goodness with others. + +tasks: + - init: npm install -g @angular/cli@12.2.16 && npm install --force + command: ng serve + + diff --git a/src/app/core/authentication/authentication.guard.ts b/src/app/core/authentication/authentication.guard.ts index fb7ade24..d9c2ba8d 100644 --- a/src/app/core/authentication/authentication.guard.ts +++ b/src/app/core/authentication/authentication.guard.ts @@ -6,6 +6,9 @@ import { Router, CanActivate } from '@angular/router'; import { Logger } from '../logger/logger.service'; import { AuthenticationService } from './authentication.service'; +/** Environment Configuration */ +import { environment } from '../../../environments/environment'; + /** Initialize logger */ const log = new Logger('AuthenticationGuard'); @@ -28,7 +31,7 @@ export class AuthenticationGuard implements CanActivate { * @returns {boolean} True if user is authenticated. */ canActivate(): boolean { - if (this.authenticationService.isAuthenticated()) { + if (this.authenticationService.isAuthenticated() || !environment.auth.enabled) { return true; } diff --git a/src/app/core/authentication/authentication.interceptor.ts b/src/app/core/authentication/authentication.interceptor.ts index eae06769..d6334ba3 100644 --- a/src/app/core/authentication/authentication.interceptor.ts +++ b/src/app/core/authentication/authentication.interceptor.ts @@ -10,6 +10,8 @@ import { switchMap, take, filter, catchError } from 'rxjs/operators'; import { AuthenticationService } from './authentication.service'; import { Router } from '@angular/router'; +import { environment } from '../../../environments/environment'; + /** Http request options headers. */ const httpOptions = { headers: {} @@ -42,6 +44,10 @@ export class AuthenticationInterceptor implements HttpInterceptor { */ this.retrieveAuthData(); + if (!environment.auth.enabled) { + return next.handle(this.injectToken(request)); + } + if (request.url.indexOf('/oauth/token') !== -1) { return next.handle(this.injectToken(request)); } diff --git a/src/app/core/authentication/authentication.service.ts b/src/app/core/authentication/authentication.service.ts index 83ef546c..4130b21f 100644 --- a/src/app/core/authentication/authentication.service.ts +++ b/src/app/core/authentication/authentication.service.ts @@ -48,7 +48,7 @@ export class AuthenticationService { private refreshAccessToken = false; private loggedIn = false; private authorizationToken: String; - private tenantId: String; + private tenantId: String = environment.auth.tenant; private username: String; private accessTokenExpirationTime = 1; diff --git a/src/app/core/shell/sidenav/sidenav.component.ts b/src/app/core/shell/sidenav/sidenav.component.ts index 917ac279..1a7df1c2 100644 --- a/src/app/core/shell/sidenav/sidenav.component.ts +++ b/src/app/core/shell/sidenav/sidenav.component.ts @@ -25,14 +25,18 @@ export class SidenavComponent implements OnInit { * @param {AuthenticationService} authenticationService Authentication Service. */ constructor(private router: Router, - private authenticationService: AuthenticationService) { } + private authenticationService: AuthenticationService) { } /** * Sets the username of the authenticated user. */ ngOnInit() { const credentials = this.authenticationService.getCredentials(); - this.username = credentials.username; + if (credentials) { + this.username = credentials.username; + } else { + this.username = 'User'; + } } /** diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index fc071a4d..7dd14fbd 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -27,7 +27,11 @@ export class HomeComponent implements OnInit { */ ngOnInit() { const credentials = this.authenticationService.getCredentials(); - this.username = credentials.username; + if (credentials) { + this.username = credentials.username; + } else { + this.username = 'User'; + } } } diff --git a/src/app/payment-hub/transactions/incoming/incoming-transactions.component.ts b/src/app/payment-hub/transactions/incoming/incoming-transactions.component.ts index 6fb0c691..fa1de2cb 100644 --- a/src/app/payment-hub/transactions/incoming/incoming-transactions.component.ts +++ b/src/app/payment-hub/transactions/incoming/incoming-transactions.component.ts @@ -394,7 +394,11 @@ export class IncomingTransactionsComponent implements OnInit, AfterViewInit { */ getTransactions() { this.dataSource = new TransactionsDataSource(this.transactionsService); - this.dataSource.getTransactions(this.filterTransactionsBy, this.sort.active, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize); + if (this.sort && this.paginator) { + this.dataSource.getTransactions(this.filterTransactionsBy, this.sort.active, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize); + } else { + this.dataSource.getTransactions(this.filterTransactionsBy, '', '', 0, 10); + } } openRetryResolveDialog(workflowInstanceKey: any, action: string) { diff --git a/src/app/payment-hub/transactions/outgoing/outgoing-transactions.component.ts b/src/app/payment-hub/transactions/outgoing/outgoing-transactions.component.ts index fcf0f80c..7032be5e 100644 --- a/src/app/payment-hub/transactions/outgoing/outgoing-transactions.component.ts +++ b/src/app/payment-hub/transactions/outgoing/outgoing-transactions.component.ts @@ -394,7 +394,11 @@ export class OutgoingTransactionsComponent implements OnInit, AfterViewInit { */ getTransactions() { this.dataSource = new TransactionsDataSource(this.transactionsService); - this.dataSource.getTransactions(this.filterTransactionsBy, this.sort.active, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize); + if (this.sort && this.paginator) { + this.dataSource.getTransactions(this.filterTransactionsBy, this.sort.active, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize); + } else { + this.dataSource.getTransactions(this.filterTransactionsBy, '', '', 0, 10); + } } openRetryResolveDialog(workflowInstanceKey: any, action: string) { diff --git a/src/assets/configuration.properties b/src/assets/configuration.properties index 728b726f..b3e55a80 100644 --- a/src/assets/configuration.properties +++ b/src/assets/configuration.properties @@ -1,5 +1,6 @@ -oauth.enabled true +oauth.enabled false oauth.serverUrl https://ops-bk.sandbox.fynarfin.io oauth.basicAuth true oauth.basicAuthToken Y2xpZW50Og== -serverUrl https://ops-bk.sandbox.fynarfin.io \ No newline at end of file +serverUrl https://ops-bk.sandbox.fynarfin.io +auth.tenant default \ No newline at end of file diff --git a/src/environments/environment.kubernetes.ts b/src/environments/environment.kubernetes.ts index 038b67f1..7c1d6d2a 100644 --- a/src/environments/environment.kubernetes.ts +++ b/src/environments/environment.kubernetes.ts @@ -19,5 +19,9 @@ export let environment = { }, defaultLanguage: "en-US", supportedLanguages: ["en-US", "fr-FR"], - externalConfigurationFile: "configuration.properties" // When provided, the external configuration file content will override this environment settings based on naming conventions + externalConfigurationFile: "configuration.properties", // When provided, the external configuration file content will override this environment settings based on naming conventions + auth: { + enabled: false, + tenant: "default" + } }; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 53eb539d..bbb8c91e 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -14,5 +14,9 @@ export let environment = { }, defaultLanguage: "en-US", supportedLanguages: ["en-US", "fr-FR"], - externalConfigurationFile: "" + externalConfigurationFile: "", + auth: { + enabled: true, + tenant: "default" + } }; \ No newline at end of file diff --git a/src/environments/environment.ts b/src/environments/environment.ts index b1ff82ff..66b3a6ab 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -12,12 +12,16 @@ export let environment = { version: env.npm_package_version + "-dev", serverUrl: "https://paymenthub.qa.oneacrefund.org/opsapp", oauth: { - enabled: "true", // For connecting to Mifos X using OAuth2 Authentication change the value to true + enabled: "false", // For connecting to Mifos X using OAuth2 Authentication change the value to true serverUrl: "https://paymenthub.qa.oneacrefund.org/opsapp", basicAuth: "true", basicAuthToken: 'Y2xpZW50Og==' }, defaultLanguage: "en-US", supportedLanguages: ["en-US", "fr-FR"], - externalConfigurationFile: "configuration.properties" + externalConfigurationFile: "configuration.properties", + auth: { + enabled: false, + tenant: "default" + } }; \ No newline at end of file