Session idle timeout with logout implementation

This commit is contained in:
Jose Alberto Hernandez
2024-04-16 19:43:17 -06:00
committed by Jose Alberto Hernandez
parent caf3d39719
commit 29d3d08e88
28 changed files with 189 additions and 6 deletions
+6
View File
@@ -153,6 +153,12 @@ MIFOS_SUPPORTED_LANGUAGES=cs-CS,de-DE,en-US,es-MX,fr-FR,it-IT,ko-KO,lt-LT,lv-LV,
```
These are the Language available now:
```
MIFOS_SESSION_IDLE_TIMEOUT=300000
```
Time in milliseconds for Session idle timeout, default 300000 seconds
| Language | Code | File |
|:----------:|:----:|:----------:|
| Czech | cs | cs-CS.json |
+1
View File
@@ -22,3 +22,4 @@ services:
- FINERACT_PLATFORM_TENANT_IDENTIFIER=default
- MIFOS_DEFAULT_LANGUAGE=en-US
- MIFOS_SUPPORTED_LANGUAGES=cs-CS,de-DE,en-US,es-MX,fr-FR,it-IT,ko-KO,lt-LT,lv-LV,ne-NE,pt-PT,sw-SW
- MIFOS_SESSION_IDLE_TIMEOUT=300000
@@ -25,6 +25,8 @@ import { OAuth2Token } from './o-auth2-token.model';
*/
@Injectable()
export class AuthenticationService {
// User logged in boolean
private userLoggedIn: boolean;
/** Denotes whether the user credentials should persist through sessions. */
private rememberMe: boolean;
@@ -57,6 +59,7 @@ export class AuthenticationService {
constructor(private http: HttpClient,
private alertService: AlertService,
private authenticationInterceptor: AuthenticationInterceptor) {
this.userLoggedIn = false;
this.rememberMe = false;
this.storage = sessionStorage;
const savedCredentials = JSON.parse(
@@ -169,6 +172,7 @@ export class AuthenticationService {
* @param {Credentials} credentials Authenticated user credentials.
*/
private onLoginSuccess(credentials: Credentials) {
this.userLoggedIn = true;
if (environment.oauth.enabled) {
this.authenticationInterceptor.setAuthorizationToken(credentials.accessToken);
} else {
@@ -202,6 +206,7 @@ export class AuthenticationService {
this.authenticationInterceptor.removeAuthorization();
this.setCredentials();
this.resetDialog();
this.userLoggedIn = false;
return of(true);
}
@@ -344,4 +349,11 @@ export class AuthenticationService {
);
}
/*
* Get user logged in
*/
getUserLoggedIn(): boolean {
return this.userLoggedIn;
}
}
+3 -1
View File
@@ -15,6 +15,7 @@ import { AmountDisbursedPieComponent } from './dashboard/amount-disbursed-pie/am
import { ClientTrendsBarComponent } from './dashboard/client-trends-bar/client-trends-bar.component';
import { TranslateModule } from '@ngx-translate/core';
import { WarningDialogComponent } from './warning-dialog/warning-dialog.component';
import { SessionTimeoutDialogComponent } from './timeout-dialog/session-timeout-dialog.component';
/**
* Home Component
@@ -35,7 +36,8 @@ import { WarningDialogComponent } from './warning-dialog/warning-dialog.componen
AmountCollectedPieComponent,
AmountDisbursedPieComponent,
ClientTrendsBarComponent,
WarningDialogComponent
WarningDialogComponent,
SessionTimeoutDialogComponent
],
providers: [ ]
})
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { IdleTimeoutService } from './idle-timeout.service';
describe('IdleTimeoutService', () => {
let service: IdleTimeoutService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(IdleTimeoutService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,29 @@
import { Injectable } from '@angular/core';
import { environment } from 'environments/environment';
import { interval, merge, fromEvent, Observable} from 'rxjs';
import { takeUntil, repeat, map} from 'rxjs/operators';
/**
* Idle timeout service used to track idle user
*/
@Injectable({
providedIn: 'root'
})
export class IdleTimeoutService {
// max timeout for an idle user
readonly timeoutDelay = environment.session.timeout.idleTimeout || 300000; // 5 minutes
// observable timeout
readonly $onSessionTimeout: Observable<void>;
constructor() {
const events = ['mousemove', 'keydown', 'wheel', 'mousedown', 'scroll'];
const $signal = merge(...events.map(eventName => fromEvent(document, eventName)));
this.$onSessionTimeout = interval(this.timeoutDelay).pipe(
takeUntil($signal),
map(() => undefined),
repeat()
);
}
}
@@ -0,0 +1,5 @@
<h1 mat-dialog-title>{{ 'labels.heading.Session Timeout' | translate }}</h1>
<mat-dialog-content>{{ 'labels.text.Session timed out after a period of inactivity' | translate }}.</mat-dialog-content>
<mat-dialog-actions>
<button mat-raised-button color="primary" mat-dialog-close>{{ 'labels.buttons.Close' | translate }}</button>
</mat-dialog-actions>
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SessionTimeoutDialogComponent } from './session-timeout-dialog.component';
describe('SessionTimeoutDialogComponent', () => {
let component: SessionTimeoutDialogComponent;
let fixture: ComponentFixture<SessionTimeoutDialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SessionTimeoutDialogComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(SessionTimeoutDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,17 @@
import { Component, OnInit } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
@Component({
selector: 'mifosx-session-timeout-dialog',
templateUrl: './session-timeout-dialog.component.html',
styleUrls: ['./session-timeout-dialog.component.scss']
})
export class SessionTimeoutDialogComponent implements OnInit {
constructor(public dialogRef: MatDialogRef<SessionTimeoutDialogComponent>) {
}
ngOnInit(): void {
}
}
@@ -1,5 +1,5 @@
<h1 mat-dialog-title>{{ "labels.text."+title | translate }}</h1>
<h1 mat-dialog-title>{{ "labels.text." + title | translate }}</h1>
<mat-dialog-content>{{ "labels.text.Warning message" | translate }}</mat-dialog-content>
<mat-dialog-actions>
<button mat-raised-button color="primary" mat-dialog-close>{{ "labels.buttons."+buttonText | translate}}</button>
<button mat-raised-button color="primary" mat-dialog-close>{{ "labels.buttons." + buttonText | translate}}</button>
</mat-dialog-actions>
+19 -1
View File
@@ -3,6 +3,7 @@ import { Component, OnInit, HostListener, HostBinding } from '@angular/core';
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
import { Title } from '@angular/platform-browser';
import { MatSnackBar } from '@angular/material/snack-bar';
import { MatDialog } from '@angular/material/dialog';
/** rxjs Imports */
import { merge } from 'rxjs';
@@ -20,6 +21,8 @@ import { ThemeStorageService } from './shared/theme-picker/theme-storage.service
import { AlertService } from './core/alert/alert.service';
import { AuthenticationService } from './core/authentication/authentication.service';
import { SettingsService } from './settings/settings.service';
import { IdleTimeoutService } from './home/timeout-dialog/idle-timeout.service';
import { SessionTimeoutDialogComponent } from './home/timeout-dialog/session-timeout-dialog.component';
/** Custom Items */
import { Alert } from './core/alert/alert.model';
@@ -95,6 +98,8 @@ export class WebAppComponent implements OnInit {
* @param {SettingsService} settingsService Settings Service.
* @param {AuthenticationService} authenticationService Authentication service.
* @param {Dates} dateUtils Dates service.
* @param {IdleTimeoutService} idle Idle timeout service.
* @param {MatDialog} dialog Dialog component.
*/
constructor(private router: Router,
private activatedRoute: ActivatedRoute,
@@ -106,7 +111,9 @@ export class WebAppComponent implements OnInit {
private settingsService: SettingsService,
private authenticationService: AuthenticationService,
private themingService: ThemingService,
private dateUtils: Dates) { }
private dateUtils: Dates,
private idle: IdleTimeoutService,
private dialog: MatDialog) { }
@HostBinding('class') public cssClass: string;
@@ -210,6 +217,17 @@ export class WebAppComponent implements OnInit {
this.settingsService.setTenantIdentifier(environment.fineractPlatformTenantId || 'default');
}
this.settingsService.setTenantIdentifiers(environment.fineractPlatformTenantIds.split(','));
// Subscribe to session timeout If IdleTimeout is higher than 0 (zero)
if (environment.session.timeout.idleTimeout > 0) {
this.idle.$onSessionTimeout.subscribe(() => {
if (this.authenticationService.getUserLoggedIn()) {
this.alertService.alert({type: 'Session timeout', message: this.translateService.instant('labels.text.Session timed out')});
this.dialog.open(SessionTimeoutDialogComponent);
this.logout();
}
});
}
}
logout() {
+4
View File
@@ -28,4 +28,8 @@
// Time in seconds for COB Catch-Up, default 30 seconds
window['env']['waitTimeForCOBCatchUp'] = '';
// Time in milliseconds for Session idle timeout, default 300000 seconds
window['env']['sessionIdleTimeout'] = '60000';
})(this);
+4
View File
@@ -28,4 +28,8 @@
// Time in seconds for COB Catch-Up, default 30 seconds
window['env']['waitTimeForCOBCatchUp'] = '$MIFOS_WAIT_TIME_FOR_CATCHUP';
// Time in milliseconds for Session idle timeout, default 300000 seconds
window['env']['sessionIdleTimeout'] = '$MIFOS_SESSION_IDLE_TIMEOUT';
})(this);
+3
View File
@@ -843,6 +843,7 @@
"Select Excel File": "Vyberte Soubor Excel",
"Selected Clients": "Vybraní klienti",
"Selected Groups": "Vybrané skupiny",
"Session Timeout": "Časový limit relace",
"Settings": "Nastavení",
"Share Accounts": "Sdílet účty",
"Share Products": "Sdílejte produkty",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "Konfigurace samoobslužné aplikace",
"Self Service Task Management": "Samoobslužná správa úloh",
"Self Service Users": "Samoobslužní uživatelé",
"Session timed out": "Časový limit relace vypršel",
"Session timed out after a period of inactivity": "Časový limit relace vypršel po určité době nečinnosti",
"Set or update office-level opening balances for GL accounts": "Nastavte nebo aktualizujte počáteční zůstatky na úrovni kanceláře pro účty HK",
"Settings": "Nastavení",
"Settle Cash": "Vyrovnat hotovost",
+3
View File
@@ -844,6 +844,7 @@
"Select Excel File": "Wählen Sie Excel-Datei",
"Selected Clients": "Ausgewählte Kunden",
"Selected Groups": "Ausgewählte Gruppen",
"Session Timeout": "Session-Timeout",
"Settings": "Einstellungen",
"Share Accounts": "Konten teilen",
"Share Products": "Produkte teilen",
@@ -2718,6 +2719,8 @@
"Self Service App Configuration": "Self-Service-App-Konfiguration",
"Self Service Task Management": "Self-Service-Aufgabenverwaltung",
"Self Service Users": "Self-Service-Benutzer",
"Session timed out": "Sitzung abgelaufen",
"Session timed out after a period of inactivity": "Die Sitzung ist nach einem Zeitraum der Inaktivität abgelaufen",
"Set or update office-level opening balances for GL accounts": "Legen Sie Eröffnungssalden auf Büroebene für Hauptbuchkonten fest oder aktualisieren Sie sie",
"Settings": "Einstellungen",
"Settle Cash": "Bargeld begleichen",
+3
View File
@@ -843,6 +843,7 @@
"Select Excel File": "Select Excel File",
"Selected Clients": "Selected Clients",
"Selected Groups": "Selected Groups",
"Session Timeout": "Session Timeout",
"Settings": "Settings",
"Share Accounts": "Share Accounts",
"Share Products": "Share Products",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "Self Service App Configuration",
"Self Service Task Management": "Self Service Task Management",
"Self Service Users": "Self Service Users",
"Session timed out": "Session timed out",
"Session timed out after a period of inactivity": "Session timed out after a period of inactivity",
"Set or update office-level opening balances for GL accounts": "Set or update office-level opening balances for GL accounts",
"Settings": "Settings",
"Settle Cash": "Settle Cash",
+3
View File
@@ -844,6 +844,7 @@
"Select Excel File": "Seleccionar archivo de Excel",
"Selected Clients": "Clientes seleccionados",
"Selected Groups": "Grupos seleccionados",
"Session Timeout": "Término de la Sesión",
"Settings": "Ajustes",
"Share Accounts": "Compartir cuentas",
"Share Products": "Compartir productos",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "Configuración de la aplicación de autoservicio",
"Self Service Task Management": "Gestión de tareas de autoservicio",
"Self Service Users": "Usuarios de autoservicio",
"Session timed out": "Sesión agotada",
"Session timed out after a period of inactivity": "La sesión se agotara después de un período de inactividad",
"Set or update office-level opening balances for GL accounts": "Establecer o actualizar saldos de apertura a nivel de oficina para cuentas del libro mayor",
"Settings": "Ajustes",
"Settle Cash": "Liquidar efectivo",
+3
View File
@@ -844,6 +844,7 @@
"Select Excel File": "Sélectionnez un fichier Excel",
"Selected Clients": "Clients sélectionnés",
"Selected Groups": "Groupes sélectionnés",
"Session Timeout": "Expiration de la session",
"Settings": "Paramètres",
"Share Accounts": "Partager des comptes",
"Share Products": "Partager des produits",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "Configuration de l'application libre-service",
"Self Service Task Management": "Gestion des tâches en libre-service",
"Self Service Users": "Utilisateurs libre-service",
"Session timed out": "Session expirée",
"Session timed out after a period of inactivity": "Session expirée après une période d'inactivité",
"Set or update office-level opening balances for GL accounts": "Définir ou mettre à jour les soldes d'ouverture au niveau du bureau pour les comptes GL",
"Settings": "Paramètres",
"Settle Cash": "Règlement en espèces",
+3
View File
@@ -844,6 +844,7 @@
"Select Excel File": "Seleziona File Excel",
"Selected Clients": "Clienti selezionati",
"Selected Groups": "Gruppi selezionati",
"Session Timeout": "Timeout della sessione",
"Settings": "Impostazioni",
"Share Accounts": "Condividi account",
"Share Products": "Condividi prodotti",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "Configurazione dell'app self-service",
"Self Service Task Management": "Gestione delle attività self-service",
"Self Service Users": "Utenti self-service",
"Session timed out": "Sessione scaduta",
"Session timed out after a period of inactivity": "Sessione scaduta dopo un periodo di inattività",
"Set or update office-level opening balances for GL accounts": "Imposta o aggiorna i saldi di apertura a livello di ufficio per i conti GL",
"Settings": "Impostazioni",
"Settle Cash": "Saldare in contanti",
+3
View File
@@ -845,6 +845,7 @@
"Select Excel File": "엑셀 파일 선택",
"Selected Clients": "선택된 클라이언트",
"Selected Groups": "선택된 그룹",
"Session Timeout": "세션 타임 아웃",
"Settings": "설정",
"Share Accounts": "계정 공유",
"Share Products": "제품 공유",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "셀프 서비스 앱 구성",
"Self Service Task Management": "셀프 서비스 작업 관리",
"Self Service Users": "셀프 서비스 사용자",
"Session timed out": "세션 시간이 초과되었습니다",
"Session timed out after a period of inactivity": "일정 기간 동안 활동이 없으면 세션 시간이 초과되었습니다.",
"Set or update office-level opening balances for GL accounts": "GL 계정에 대한 사무실 수준 기초 잔액 설정 또는 업데이트",
"Settings": "설정",
"Settle Cash": "현금 정산",
+3
View File
@@ -844,6 +844,7 @@
"Select Excel File": "Pasirinkite Excel failą",
"Selected Clients": "Atrinkti klientai",
"Selected Groups": "Pasirinktos grupės",
"Session Timeout": "Seanso skirtasis laikas",
"Settings": "Nustatymai",
"Share Accounts": "Bendrinti paskyras",
"Share Products": "Dalintis produktais",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "Savitarnos programos konfigūracija",
"Self Service Task Management": "Savitarnos užduočių valdymas",
"Self Service Users": "Savitarnos vartotojai",
"Session timed out": "Sesijos laikas baigėsi",
"Session timed out after a period of inactivity": "Po tam tikro neveiklumo laikotarpio baigėsi seanso laikas",
"Set or update office-level opening balances for GL accounts": "Nustatykite arba atnaujinkite biuro lygio pradinius GL sąskaitų likučius",
"Settings": "Nustatymai",
"Settle Cash": "Atsiskaityti grynaisiais",
+3
View File
@@ -844,6 +844,7 @@
"Select Excel File": "Atlasiet Excel failu",
"Selected Clients": "Izvēlētie klienti",
"Selected Groups": "Atlasītās grupas",
"Session Timeout": "Sesijas noildze",
"Settings": "Iestatījumi",
"Share Accounts": "Kopīgot kontus",
"Share Products": "Kopīgojiet produktus",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "Pašapkalpošanās lietotņu konfigurācija",
"Self Service Task Management": "Pašapkalpošanās uzdevumu pārvaldība",
"Self Service Users": "Pašapkalpošanās lietotāji",
"Session timed out": "Sesija beigusies",
"Session timed out after a period of inactivity": "Sesija beidzās pēc dīkstāves perioda",
"Set or update office-level opening balances for GL accounts": "Iestatiet vai atjauniniet biroja līmeņa sākuma atlikumus GL kontiem",
"Settings": "Iestatījumi",
"Settle Cash": "Norēķini skaidrā naudā",
+3
View File
@@ -844,6 +844,7 @@
"Select Excel File": "एक्सेल फाइल चयन गर्नुहोस्",
"Selected Clients": "चयन गरिएका ग्राहकहरू",
"Selected Groups": "चयन गरिएका समूहहरू",
"Session Timeout": "सत्र टाइमआउट",
"Settings": "सेटिङहरू",
"Share Accounts": "खाताहरू साझेदारी गर्नुहोस्",
"Share Products": "उत्पादनहरू साझेदारी गर्नुहोस्",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "सेल्फ सर्विस एप कन्फिगरेसन",
"Self Service Task Management": "स्वयं सेवा कार्य व्यवस्थापन",
"Self Service Users": "स्वयं सेवा प्रयोगकर्ताहरू",
"Session timed out": "सत्रको समय सकियो",
"Session timed out after a period of inactivity": "निष्क्रियताको अवधि पछि सत्रको समय सकियो",
"Set or update office-level opening balances for GL accounts": "GL खाताहरूका लागि अफिस-स्तर खोल्ने ब्यालेन्सहरू सेट वा अद्यावधिक गर्नुहोस्",
"Settings": "सेटिङहरू",
"Settle Cash": "नगद मिलाउनुहोस्",
+3
View File
@@ -844,6 +844,7 @@
"Select Excel File": "Selecione o arquivo Excel",
"Selected Clients": "Clientes Selecionados",
"Selected Groups": "Grupos Selecionados",
"Session Timeout": "Sessão expirada",
"Settings": "Configurações",
"Share Accounts": "Compartilhar contas",
"Share Products": "Compartilhe produtos",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "Configuração de aplicativo de autoatendimento",
"Self Service Task Management": "Gerenciamento de tarefas de autoatendimento",
"Self Service Users": "Usuários de autoatendimento",
"Session timed out": "A sessão expirou",
"Session timed out after a period of inactivity": "A sessão expirou após um período de inatividade",
"Set or update office-level opening balances for GL accounts": "Definir ou atualizar saldos iniciais em nível de escritório para contas contábeis",
"Settings": "Configurações",
"Settle Cash": "Liquidar dinheiro",
+3
View File
@@ -844,6 +844,7 @@
"Select Excel File": "Chagua Faili ya Excel",
"Selected Clients": "Wateja Waliochaguliwa",
"Selected Groups": "Vikundi Vilivyochaguliwa",
"Session Timeout": "Muda wa Kikao umekwisha",
"Settings": "Mipangilio",
"Share Accounts": "Shiriki Akaunti",
"Share Products": "Shiriki Bidhaa",
@@ -2719,6 +2720,8 @@
"Self Service App Configuration": "Usanidi wa Programu ya Kujihudumia",
"Self Service Task Management": "Usimamizi wa Kazi ya Kujihudumia",
"Self Service Users": "Watumiaji wa Kujihudumia",
"Session timed out": "Muda wa kipindi umekwisha",
"Session timed out after a period of inactivity": "Muda wa kipindi umekwisha baada ya muda wa kutofanya kazi",
"Set or update office-level opening balances for GL accounts": "Weka au usasishe masalio ya kufungua ngazi ya ofisi kwa akaunti za GL",
"Settings": "Mipangilio",
"Settle Cash": "Maliza Pesa",
+6 -1
View File
@@ -36,7 +36,12 @@ export const environment = {
// Time in seconds, default 60 seconds
waitTimeForNotifications: window['env']['waitTimeForNotifications'] || 60,
// Time in seconds, default 30 seconds
waitTimeForCOBCatchUp: window['env']['waitTimeForCOBCatchUp'] || 30
waitTimeForCOBCatchUp: window['env']['waitTimeForCOBCatchUp'] || 30,
session: {
timeout: {
idleTimeout: window['env']['sessionIdleTimeout'] || 300000, // 5 minutes
}
}
};
// Server URL
+6 -1
View File
@@ -41,7 +41,12 @@ export const environment = {
// Time in seconds, default 60 seconds
waitTimeForNotifications: window['env']['waitTimeForNotifications'] || 60,
// Time in seconds, default 30 seconds
waitTimeForCOBCatchUp: window['env']['waitTimeForCOBCatchUp'] || 30
waitTimeForCOBCatchUp: window['env']['waitTimeForCOBCatchUp'] || 30,
session: {
timeout: {
idleTimeout: window['env']['sessionIdleTimeout'] || 300000, // 5 minutes
}
}
};
// Server URL