diff --git a/Core/Domibus-MSH-angular/angular.json b/Core/Domibus-MSH-angular/angular.json index 97713b33ab..f4e5c48ecf 100644 --- a/Core/Domibus-MSH-angular/angular.json +++ b/Core/Domibus-MSH-angular/angular.json @@ -30,7 +30,8 @@ "buildOptimizer": false, "sourceMap": true, "optimization": false, - "namedChunks": true + "namedChunks": true, + "baseHref": "/" }, "configurations": { "production": { @@ -48,6 +49,7 @@ "outputHashing": "all", "sourceMap": false, "namedChunks": false, + "baseHref": "./", "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, diff --git a/Core/Domibus-MSH-angular/pom.xml b/Core/Domibus-MSH-angular/pom.xml index 15a334152f..3182af0f70 100644 --- a/Core/Domibus-MSH-angular/pom.xml +++ b/Core/Domibus-MSH-angular/pom.xml @@ -8,7 +8,7 @@ org.niis core - 2.4.0 + 2.5.0 harmony-msh-angular jar diff --git a/Core/Domibus-MSH-angular/src/app/app.component.ts b/Core/Domibus-MSH-angular/src/app/app.component.ts index 9387b9359a..55e4d11d70 100644 --- a/Core/Domibus-MSH-angular/src/app/app.component.ts +++ b/Core/Domibus-MSH-angular/src/app/app.component.ts @@ -127,7 +127,16 @@ export class AppComponent implements OnInit { console.log('onHttpEventService in app component error=', error) if (error && (error.status === Server.HTTP_UNAUTHORIZED || error.status === Server.HTTP_FORBIDDEN)) { this.securityService.clearAppData(SessionState.EXPIRED_INACTIVITY_OR_ERROR); - this.router.navigate(['/login']); + + // don't go to login page if we are in the login page already + let currentRoute = this.router.url; + if (currentRoute === '/login' || currentRoute === '/logout') { + console.debug('no redirect, staying on current page: ' + currentRoute); + return; + } + + // don't go to login page if we're using external authentication, go to logout instead + this.router.navigate([this.isExtAuthProviderEnabled() ? '/logout' : '/login']); } } diff --git a/Core/Domibus-MSH-angular/src/app/app.module.ts b/Core/Domibus-MSH-angular/src/app/app.module.ts index 7277cdb893..45f930a803 100644 --- a/Core/Domibus-MSH-angular/src/app/app.module.ts +++ b/Core/Domibus-MSH-angular/src/app/app.module.ts @@ -126,6 +126,7 @@ import {NgxMatMomentModule} from '@angular-material-components/moment-adapter'; import {MatDatepickerModule} from '@angular/material/datepicker'; import {ManageBackendsComponent} from './messagefilter/manageBackends-form/manageBackends-form.component'; import {DateService} from './common/customDate/date.service'; +import {HelperService} from './common/helper.service'; const CUSTOM_MOMENT_FORMATS: NgxMatDateFormats = { parse: { @@ -268,6 +269,7 @@ const CUSTOM_MOMENT_FORMATS: NgxMatDateFormats = { PluginUserValidatorService, DialogsService, PropertiesService, + HelperService, FileUploadValidatorService, ApplicationContextService, DatePipe, diff --git a/Core/Domibus-MSH-angular/src/app/common/guards/authenticated-authorized.guard.ts b/Core/Domibus-MSH-angular/src/app/common/guards/authenticated-authorized.guard.ts index 783465560d..deae17497f 100644 --- a/Core/Domibus-MSH-angular/src/app/common/guards/authenticated-authorized.guard.ts +++ b/Core/Domibus-MSH-angular/src/app/common/guards/authenticated-authorized.guard.ts @@ -19,6 +19,7 @@ export class AuthenticatedAuthorizedGuard { async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { const isAuthenticated = await this.securityService.isAuthenticated(); if (!isAuthenticated) { + console.log(`[${this.securityService.getCurrentUser()?.username}] not authenticated`); this.handleNotAuthenticated(); return this.getNotAuthenticatedRoute(state); } @@ -42,7 +43,7 @@ export class AuthenticatedAuthorizedGuard { } else { allowedRoles = routeData.checkRoles } - return this.securityService.isCurrentUserInRole(allowedRoles); + return this.securityService.isCurrentUserInRole(allowedRoles, true /* logWarning */); } private getNotAuthorizedRoute(): UrlTree { @@ -56,11 +57,12 @@ export class AuthenticatedAuthorizedGuard { private async getNotAuthenticatedRoute(state: RouterStateSnapshot): Promise { let isExtAuthProvider = await this.domibusInfoService.isExtAuthProviderEnabled(); - // not logged in so redirect to login page with the return url if (!isExtAuthProvider) { + // Domibus Login: not logged in so redirect to login page with the return url return this.router.createUrlTree(['/login'], {queryParams: {returnUrl: state.url}}); + } else { + // EU Login: redirect to logout + return this.router.createUrlTree(['/logout']); } - // EU Login redirect to logout - return this.router.createUrlTree(['/logout']); } } diff --git a/Core/Domibus-MSH-angular/src/app/common/helper.service.ts b/Core/Domibus-MSH-angular/src/app/common/helper.service.ts new file mode 100644 index 0000000000..75f14d7159 --- /dev/null +++ b/Core/Domibus-MSH-angular/src/app/common/helper.service.ts @@ -0,0 +1,42 @@ +import {Injectable} from '@angular/core'; +import {PropertiesService} from '../properties/support/properties.service'; + +@Injectable() +export class HelperService { + + constructor() { + } + + arrayBufferToBase64(buffer) { + let binary = ''; + const bytes = new Uint8Array(buffer); + const len = bytes.byteLength; + for (let i = 0; i < len; i++) { + binary += String.fromCharCode(bytes[i]); + } + return window.btoa(binary); + } + + base64ToArrayBuffer(base64) { + const binaryString = window.atob(base64); + const len = binaryString.length; + const bytes = new Uint8Array(len); + for (let i = 0; i < len; i++) { + bytes[i] = binaryString.charCodeAt(i); + } + return bytes.buffer; + } + + arrayBufferToPem(buffer: ArrayBuffer): string { + let binary = ''; + const bytes = new Uint8Array(buffer); + const len = bytes.byteLength; + for (let i = 0; i < len; i++) { + binary += String.fromCharCode(bytes[i]); + } + const base64 = window.btoa(binary); + return `-----BEGIN PUBLIC KEY-----\n${base64}\n-----END PUBLIC KEY-----`; + } + +} + diff --git a/Core/Domibus-MSH-angular/src/app/common/page-grid/datatable-pager.comonent.ts b/Core/Domibus-MSH-angular/src/app/common/page-grid/datatable-pager.comonent.ts index 8ce286e3e3..a943fd745a 100644 --- a/Core/Domibus-MSH-angular/src/app/common/page-grid/datatable-pager.comonent.ts +++ b/Core/Domibus-MSH-angular/src/app/common/page-grid/datatable-pager.comonent.ts @@ -6,28 +6,28 @@ import {PageGridComponent} from './page-grid.component'; template: `