ngx-sp-auth 4.21.1 → 4.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/ngx-sp-auth.mjs +192 -229
- package/fesm2022/ngx-sp-auth.mjs.map +1 -1
- package/lib/auth.service.d.ts +3 -7
- package/lib/interceptors/auth-aplic.interceptor.d.ts +8 -6
- package/lib/interceptors/auth-infra.interceptor.d.ts +5 -3
- package/lib/services/pesquisa-telas-global.service.d.ts +4 -4
- package/lib/storage/auth-storage.service.d.ts +2 -13
- package/lib/utils/auth-utils.service.d.ts +5 -5
- package/package.json +2 -2
package/fesm2022/ngx-sp-auth.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { importProvidersFrom, NgModule, InjectionToken, Inject, Injectable,
|
|
2
|
+
import { importProvidersFrom, NgModule, InjectionToken, Inject, Injectable, Component, EventEmitter, Output, Input, TemplateRef, ContentChild, ViewChild, inject } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/common/http';
|
|
4
|
-
import { HTTP_INTERCEPTORS,
|
|
4
|
+
import { HTTP_INTERCEPTORS, HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
|
5
5
|
import * as i1$2 from '@azure/msal-angular';
|
|
6
6
|
import { MsalInterceptor, MsalGuard, MsalModule, MSAL_GUARD_CONFIG } from '@azure/msal-angular';
|
|
7
7
|
import { LogLevel, PublicClientApplication, InteractionType } from '@azure/msal-browser';
|
|
8
|
-
import { BehaviorSubject, firstValueFrom, take, tap, Subject, Subscription, debounceTime, distinctUntilChanged, filter, switchMap, timer, map as map$1, of, lastValueFrom, from } from 'rxjs';
|
|
9
8
|
import { take as take$1, tap as tap$1, map, switchMap as switchMap$1 } from 'rxjs/operators';
|
|
10
9
|
import * as i1$1 from '@angular/router';
|
|
11
10
|
import { RouterLink, NavigationEnd, RouterOutlet } from '@angular/router';
|
|
11
|
+
import { BehaviorSubject, take, tap, Subject, Subscription, debounceTime, distinctUntilChanged, filter, switchMap, timer, map as map$1, firstValueFrom, of, lastValueFrom, from } from 'rxjs';
|
|
12
12
|
import * as i3 from 'ngx-sp-infra';
|
|
13
13
|
import { Utils, SearchInputComponent, InfraModule, FormUtils, Usuario, RetPasswordPolicy, RetCheckPassword, CheckPasswordRecord, PasswordPolicyComponent, LibIconsComponent, ContentContainerComponent } from 'ngx-sp-infra';
|
|
14
14
|
import { openDB, deleteDB } from 'idb';
|
|
@@ -512,85 +512,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
512
512
|
}]
|
|
513
513
|
}], ctorParameters: () => [{ type: LibCustomEnvironmentService }] });
|
|
514
514
|
|
|
515
|
-
class LibCustomLoginService {
|
|
516
|
-
constructor(_customLoginService) {
|
|
517
|
-
this._customLoginService = _customLoginService;
|
|
518
|
-
}
|
|
519
|
-
// #region Propriedade Customizadas para o Componente login.component.ts
|
|
520
|
-
get loginTitle() {
|
|
521
|
-
return this._customLoginService.loginTitle;
|
|
522
|
-
}
|
|
523
|
-
get loginSubtitle() {
|
|
524
|
-
return this._customLoginService.loginSubtitle;
|
|
525
|
-
}
|
|
526
|
-
get loginBackground() {
|
|
527
|
-
return this._customLoginService.loginBackground;
|
|
528
|
-
}
|
|
529
|
-
get loginLogotipo() {
|
|
530
|
-
return this._customLoginService.loginLogotipo;
|
|
531
|
-
}
|
|
532
|
-
get loginAltLogotipo() {
|
|
533
|
-
return this._customLoginService.loginAltLogotipo;
|
|
534
|
-
}
|
|
535
|
-
get loginPageTitle() {
|
|
536
|
-
return this._customLoginService.loginPageTitle;
|
|
537
|
-
}
|
|
538
|
-
get loginDesenvDomain() {
|
|
539
|
-
return this._customLoginService.loginDesenvDomain;
|
|
540
|
-
}
|
|
541
|
-
get loginDesenvUser() {
|
|
542
|
-
return this._customLoginService.loginDesenvUser;
|
|
543
|
-
}
|
|
544
|
-
get loginDesenvPassword() {
|
|
545
|
-
return this._customLoginService.loginDesenvPassword;
|
|
546
|
-
}
|
|
547
|
-
// #endregion Propriedade Customizadas para o Componente login.component.ts
|
|
548
|
-
// #region Métodos Customizadas para o Componente auth.service.ts
|
|
549
|
-
/**
|
|
550
|
-
* Método executado no auth.service.ts - método: login ()
|
|
551
|
-
* Utilizado para inicializações diversas
|
|
552
|
-
*/
|
|
553
|
-
authLogin() {
|
|
554
|
-
this._customLoginService.authLogin();
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* Método executado no auth.service.ts - método: logout ()
|
|
558
|
-
* Utilizado para inicializações diversas
|
|
559
|
-
*/
|
|
560
|
-
authLogout() {
|
|
561
|
-
this._customLoginService.authLogout();
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Método executado no auth.service.ts - método: login ()
|
|
565
|
-
* Utilizado para informar o redirecionamento para a tela inicial após o login ok
|
|
566
|
-
*
|
|
567
|
-
* @param router Objeto de Router que será utilizado
|
|
568
|
-
*/
|
|
569
|
-
authNavigateToPage(router) {
|
|
570
|
-
this._customLoginService.authNavigateToPage(router);
|
|
571
|
-
}
|
|
572
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, deps: [{ token: LIB_CUSTOM_LOGIN_SERVICE }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
573
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, providedIn: 'root' }); }
|
|
574
|
-
}
|
|
575
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, decorators: [{
|
|
576
|
-
type: Injectable,
|
|
577
|
-
args: [{ providedIn: 'root' }]
|
|
578
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
579
|
-
type: Inject,
|
|
580
|
-
args: [LIB_CUSTOM_LOGIN_SERVICE]
|
|
581
|
-
}] }] });
|
|
582
|
-
|
|
583
515
|
class AuthStorageService {
|
|
584
|
-
constructor(_httpBackend, _customStorageService, _indexedDBService, _customEnvironmentService
|
|
516
|
+
constructor(_httpBackend, _customStorageService, _indexedDBService, _customEnvironmentService) {
|
|
585
517
|
this._httpBackend = _httpBackend;
|
|
586
518
|
this._customStorageService = _customStorageService;
|
|
587
519
|
this._indexedDBService = _indexedDBService;
|
|
588
520
|
this._customEnvironmentService = _customEnvironmentService;
|
|
589
|
-
this.
|
|
590
|
-
this._router = _router;
|
|
591
|
-
this._BASE_URL = ''; // SpInfra2LoginWS
|
|
592
|
-
this._LOGOUT_BASE_URL = ''; // SpInfra2LoginWS
|
|
593
|
-
this._HTTP_HEADERS = new HttpHeaders().set('Content-Type', 'application/json');
|
|
521
|
+
this._BASE_URL = ''; // SpInfra2WS
|
|
594
522
|
this.__local_key = 'user_auth_v6';
|
|
595
523
|
// indica se objeto já está marcado para salvar os dados no local storage.
|
|
596
524
|
this.__isSaving = false;
|
|
@@ -637,10 +565,8 @@ class AuthStorageService {
|
|
|
637
565
|
// azureClientId
|
|
638
566
|
this.__azureClientId = "";
|
|
639
567
|
this._httpClient = new HttpClient(_httpBackend);
|
|
640
|
-
this._BASE_URL = `${_customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; //
|
|
641
|
-
this._BASE_URL = !_customEnvironmentService.production ? this._BASE_URL : `${_customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`;
|
|
642
|
-
this._LOGOUT_BASE_URL = `${_customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`; // SpInfra2LoginWS
|
|
643
|
-
this._BASE_URL = !_customEnvironmentService.production ? this._BASE_URL : `${_customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`; // SpInfra2LoginWS
|
|
568
|
+
this._BASE_URL = `${_customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; // SpInfra2WS
|
|
569
|
+
this._BASE_URL = !_customEnvironmentService.production ? this._BASE_URL : `${_customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`;
|
|
644
570
|
// Método com customizações para inicializações da storage
|
|
645
571
|
this._customStorageService.storageConstructor();
|
|
646
572
|
const expectedLocalAuthStorage = localStorage.getItem(this.__local_key);
|
|
@@ -913,22 +839,36 @@ class AuthStorageService {
|
|
|
913
839
|
// Chama a si próprio depois de um tempo igual ao tempo restante para o vencimento do token, para renovar o token ou deslogar o usuário.
|
|
914
840
|
setTimeout(this.reCheckLogin.bind(this, true), leftTime * 1000);
|
|
915
841
|
}
|
|
916
|
-
/**
|
|
917
|
-
* Realiza o logout do sistema, consumindo o endpoint de logout para remover os cookies e limpando as informações de autenticação armazenadas no localStorage.
|
|
918
|
-
* @returns Promise<boolean> indicando navegação para a tela de login após o logout.
|
|
919
|
-
*/
|
|
920
842
|
logout() {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
843
|
+
this.__isCheckingAuth = false;
|
|
844
|
+
this.isLoggedInSub.next(false);
|
|
845
|
+
this.__UrlRedirect = "/";
|
|
846
|
+
this.__ip = "";
|
|
847
|
+
this.__tenantId = 0;
|
|
848
|
+
this.__infraUsuarioId = "";
|
|
849
|
+
this.__infraEstabId = "";
|
|
850
|
+
this.__infraEstabNome = "";
|
|
851
|
+
this.__infraEmpresaId = "";
|
|
852
|
+
this.__infraEmpresaNome = "";
|
|
853
|
+
this.__user = "";
|
|
854
|
+
this.__userName = "";
|
|
855
|
+
this.__authToken = "";
|
|
856
|
+
this.__dominio = "";
|
|
857
|
+
this.__tokenPayload = {};
|
|
858
|
+
this.__isExternalLogin = false;
|
|
859
|
+
this.__infraInAuthTypeId = 0;
|
|
860
|
+
this.__infraIn2FaTypeId = null;
|
|
861
|
+
this.__is2FaEnabled = false;
|
|
862
|
+
this.__azureTenantId = "";
|
|
863
|
+
this.__azureClientId = "";
|
|
864
|
+
localStorage.removeItem(this.__local_key);
|
|
865
|
+
// Limpa o armazenamento local do navegador que contém os filtros de um produto específico
|
|
866
|
+
// Fecha a conexão local (se houver) antes de excluir a database para evitar o callback 'blocking'
|
|
867
|
+
this._indexedDBService.closeOpenConnection()
|
|
868
|
+
.then(() => this._indexedDBService.deleteDatabase())
|
|
869
|
+
.catch((err) => console.warn('logout() => falha ao limpar conexão', err));
|
|
870
|
+
// Método com customizações para finalizações da storage
|
|
871
|
+
this._customStorageService.storageLogout();
|
|
932
872
|
}
|
|
933
873
|
getNewTokenBack() {
|
|
934
874
|
let token = {
|
|
@@ -941,14 +881,15 @@ class AuthStorageService {
|
|
|
941
881
|
};
|
|
942
882
|
const url = `${this._BASE_URL}/GetNewToken`;
|
|
943
883
|
const headers = new HttpHeaders()
|
|
944
|
-
.set('Content-Type', 'application/json')
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
884
|
+
.set('Content-Type', 'application/json')
|
|
885
|
+
.set('Authorization', `Basic ${btoa(`${localStorage.getItem('configServerUser')}:${localStorage.getItem('configServerPassword')}`)}`);
|
|
886
|
+
return this._httpClient
|
|
887
|
+
.post(url, token, { 'headers': headers })
|
|
888
|
+
.pipe(take(1), tap((response) => {
|
|
889
|
+
if (response.Error) {
|
|
890
|
+
throw Error(response.ErrorMessage);
|
|
891
|
+
}
|
|
892
|
+
}));
|
|
952
893
|
}
|
|
953
894
|
getNewToken() {
|
|
954
895
|
return new Promise((resolve, reject) => {
|
|
@@ -985,37 +926,6 @@ class AuthStorageService {
|
|
|
985
926
|
}
|
|
986
927
|
}
|
|
987
928
|
}
|
|
988
|
-
onLogout() {
|
|
989
|
-
this.__isCheckingAuth = false;
|
|
990
|
-
this.isLoggedInSub.next(false);
|
|
991
|
-
this.__UrlRedirect = "/";
|
|
992
|
-
this.__ip = "";
|
|
993
|
-
this.__tenantId = 0;
|
|
994
|
-
this.__infraUsuarioId = "";
|
|
995
|
-
this.__infraEstabId = "";
|
|
996
|
-
this.__infraEstabNome = "";
|
|
997
|
-
this.__infraEmpresaId = "";
|
|
998
|
-
this.__infraEmpresaNome = "";
|
|
999
|
-
this.__user = "";
|
|
1000
|
-
this.__userName = "";
|
|
1001
|
-
this.__authToken = "";
|
|
1002
|
-
this.__dominio = "";
|
|
1003
|
-
this.__tokenPayload = {};
|
|
1004
|
-
this.__isExternalLogin = false;
|
|
1005
|
-
this.__infraInAuthTypeId = 0;
|
|
1006
|
-
this.__infraIn2FaTypeId = null;
|
|
1007
|
-
this.__is2FaEnabled = false;
|
|
1008
|
-
this.__azureTenantId = "";
|
|
1009
|
-
this.__azureClientId = "";
|
|
1010
|
-
localStorage.removeItem(this.__local_key);
|
|
1011
|
-
// Limpa o armazenamento local do navegador que contém os filtros de um produto específico
|
|
1012
|
-
// Fecha a conexão local (se houver) antes de excluir a database para evitar o callback 'blocking'
|
|
1013
|
-
this._indexedDBService.closeOpenConnection()
|
|
1014
|
-
.then(() => this._indexedDBService.deleteDatabase())
|
|
1015
|
-
.catch((err) => console.warn('logout() => falha ao limpar conexão', err));
|
|
1016
|
-
// Método com customizações para finalizações da storage
|
|
1017
|
-
this._customStorageService.storageLogout();
|
|
1018
|
-
}
|
|
1019
929
|
isPrePortal() {
|
|
1020
930
|
// Identifica se a origem é PrePortal
|
|
1021
931
|
var url = new URL(window.location.href);
|
|
@@ -1032,46 +942,114 @@ class AuthStorageService {
|
|
|
1032
942
|
return false;
|
|
1033
943
|
}
|
|
1034
944
|
}
|
|
1035
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, deps: [{ token: i1.HttpBackend }, { token: LibCustomStorageService }, { token: IndexedDBService }, { token: LibCustomEnvironmentService }
|
|
945
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, deps: [{ token: i1.HttpBackend }, { token: LibCustomStorageService }, { token: IndexedDBService }, { token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1036
946
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, providedIn: 'root' }); }
|
|
1037
947
|
}
|
|
1038
948
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthStorageService, decorators: [{
|
|
1039
949
|
type: Injectable,
|
|
1040
950
|
args: [{ providedIn: 'root' }]
|
|
1041
|
-
}], ctorParameters: () => [{ type: i1.HttpBackend }, { type: LibCustomStorageService }, { type: IndexedDBService }, { type: LibCustomEnvironmentService }
|
|
951
|
+
}], ctorParameters: () => [{ type: i1.HttpBackend }, { type: LibCustomStorageService }, { type: IndexedDBService }, { type: LibCustomEnvironmentService }] });
|
|
952
|
+
|
|
953
|
+
class LibCustomLoginService {
|
|
954
|
+
constructor(_customLoginService) {
|
|
955
|
+
this._customLoginService = _customLoginService;
|
|
956
|
+
}
|
|
957
|
+
// #region Propriedade Customizadas para o Componente login.component.ts
|
|
958
|
+
get loginTitle() {
|
|
959
|
+
return this._customLoginService.loginTitle;
|
|
960
|
+
}
|
|
961
|
+
get loginSubtitle() {
|
|
962
|
+
return this._customLoginService.loginSubtitle;
|
|
963
|
+
}
|
|
964
|
+
get loginBackground() {
|
|
965
|
+
return this._customLoginService.loginBackground;
|
|
966
|
+
}
|
|
967
|
+
get loginLogotipo() {
|
|
968
|
+
return this._customLoginService.loginLogotipo;
|
|
969
|
+
}
|
|
970
|
+
get loginAltLogotipo() {
|
|
971
|
+
return this._customLoginService.loginAltLogotipo;
|
|
972
|
+
}
|
|
973
|
+
get loginPageTitle() {
|
|
974
|
+
return this._customLoginService.loginPageTitle;
|
|
975
|
+
}
|
|
976
|
+
get loginDesenvDomain() {
|
|
977
|
+
return this._customLoginService.loginDesenvDomain;
|
|
978
|
+
}
|
|
979
|
+
get loginDesenvUser() {
|
|
980
|
+
return this._customLoginService.loginDesenvUser;
|
|
981
|
+
}
|
|
982
|
+
get loginDesenvPassword() {
|
|
983
|
+
return this._customLoginService.loginDesenvPassword;
|
|
984
|
+
}
|
|
985
|
+
// #endregion Propriedade Customizadas para o Componente login.component.ts
|
|
986
|
+
// #region Métodos Customizadas para o Componente auth.service.ts
|
|
987
|
+
/**
|
|
988
|
+
* Método executado no auth.service.ts - método: login ()
|
|
989
|
+
* Utilizado para inicializações diversas
|
|
990
|
+
*/
|
|
991
|
+
authLogin() {
|
|
992
|
+
this._customLoginService.authLogin();
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Método executado no auth.service.ts - método: logout ()
|
|
996
|
+
* Utilizado para inicializações diversas
|
|
997
|
+
*/
|
|
998
|
+
authLogout() {
|
|
999
|
+
this._customLoginService.authLogout();
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Método executado no auth.service.ts - método: login ()
|
|
1003
|
+
* Utilizado para informar o redirecionamento para a tela inicial após o login ok
|
|
1004
|
+
*
|
|
1005
|
+
* @param router Objeto de Router que será utilizado
|
|
1006
|
+
*/
|
|
1007
|
+
authNavigateToPage(router) {
|
|
1008
|
+
this._customLoginService.authNavigateToPage(router);
|
|
1009
|
+
}
|
|
1010
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, deps: [{ token: LIB_CUSTOM_LOGIN_SERVICE }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1011
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, providedIn: 'root' }); }
|
|
1012
|
+
}
|
|
1013
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: LibCustomLoginService, decorators: [{
|
|
1014
|
+
type: Injectable,
|
|
1015
|
+
args: [{ providedIn: 'root' }]
|
|
1016
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
1017
|
+
type: Inject,
|
|
1018
|
+
args: [LIB_CUSTOM_LOGIN_SERVICE]
|
|
1019
|
+
}] }] });
|
|
1042
1020
|
|
|
1043
1021
|
class AuthUtilService {
|
|
1044
|
-
constructor(
|
|
1045
|
-
this.
|
|
1046
|
-
this.
|
|
1022
|
+
constructor(router, authStorageService, checkUrlAndMethodService, messageService, _customEnvironmentService) {
|
|
1023
|
+
this.router = router;
|
|
1024
|
+
this.authStorageService = authStorageService;
|
|
1025
|
+
this.checkUrlAndMethodService = checkUrlAndMethodService;
|
|
1026
|
+
this.messageService = messageService;
|
|
1047
1027
|
this._customEnvironmentService = _customEnvironmentService;
|
|
1048
|
-
this._message = _message;
|
|
1049
|
-
this._router = _router;
|
|
1050
1028
|
}
|
|
1051
1029
|
// Exibe a mensagem de erro de uma requisição http
|
|
1052
1030
|
showHttpError(error) {
|
|
1053
1031
|
if (error.error instanceof ErrorEvent) {
|
|
1054
1032
|
// Erro ocorreu no lado do cliente
|
|
1055
|
-
this.
|
|
1033
|
+
this.messageService.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1056
1034
|
}
|
|
1057
1035
|
else {
|
|
1058
1036
|
// Erro ocorreu no lado do servidor
|
|
1059
1037
|
let isUnauthorizedAccess = error.status === 401;
|
|
1060
1038
|
if (isUnauthorizedAccess) {
|
|
1061
|
-
let isFromAplic = this.
|
|
1039
|
+
let isFromAplic = this.checkUrlAndMethodService.needsAuthRequest(error.url, "*", this._customEnvironmentService.needsAuthAplic);
|
|
1062
1040
|
if (isFromAplic) {
|
|
1063
|
-
// Comentado pois neste projeto esta alteração de valores não realizava o logout como deveria corretamente...
|
|
1064
|
-
// this.authStorageService.isLoggedInSub.next(false);
|
|
1065
|
-
// this.authStorageService.urlRedirect = "/";
|
|
1066
1041
|
// Remove a autenticação do usuário.
|
|
1067
|
-
this.
|
|
1042
|
+
this.authStorageService.isLoggedInSub.next(false);
|
|
1043
|
+
this.authStorageService.urlRedirect = "/";
|
|
1044
|
+
let promise = this.router.navigate(["/auth/login"]);
|
|
1045
|
+
promise.then(this.showExpiredAccess.bind(this));
|
|
1068
1046
|
}
|
|
1069
1047
|
else {
|
|
1070
|
-
this.
|
|
1048
|
+
this.messageService.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1071
1049
|
}
|
|
1072
1050
|
}
|
|
1073
1051
|
else {
|
|
1074
|
-
this.
|
|
1052
|
+
this.messageService.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1075
1053
|
}
|
|
1076
1054
|
}
|
|
1077
1055
|
}
|
|
@@ -1079,33 +1057,32 @@ class AuthUtilService {
|
|
|
1079
1057
|
showHTTPErrorOS(error) {
|
|
1080
1058
|
if (error.error instanceof ErrorEvent) {
|
|
1081
1059
|
// Erro ocorreu no lado do cliente
|
|
1082
|
-
this.
|
|
1083
|
-
this.
|
|
1060
|
+
this.router.navigate(["/auth/login"]).then(e => {
|
|
1061
|
+
this.messageService.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1084
1062
|
});
|
|
1085
1063
|
}
|
|
1086
1064
|
else {
|
|
1087
1065
|
// Erro ocorreu no lado do servidor
|
|
1088
1066
|
let isUnauthorizedAccess = error.status === 401;
|
|
1089
1067
|
if (isUnauthorizedAccess) {
|
|
1090
|
-
let isFromAplic = this.
|
|
1068
|
+
let isFromAplic = this.checkUrlAndMethodService.needsAuthRequest(error.url, "*", this._customEnvironmentService.needsAuthAplic);
|
|
1091
1069
|
if (isFromAplic) {
|
|
1092
|
-
// Comentado pois neste projeto esta alteração de valores não realizava o logout como deveria corretamente...
|
|
1093
|
-
// this.authStorageService.isLoggedInSub.next(false);
|
|
1094
|
-
// this.authStorageService.urlRedirect = "/";
|
|
1095
1070
|
// Remove a autenticação do usuário.
|
|
1096
|
-
this.
|
|
1097
|
-
|
|
1071
|
+
this.authStorageService.isLoggedInSub.next(false);
|
|
1072
|
+
this.authStorageService.urlRedirect = "/";
|
|
1073
|
+
this.router.navigate(["/auth/login"]).then(e => {
|
|
1074
|
+
this.messageService.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1098
1075
|
});
|
|
1099
1076
|
}
|
|
1100
1077
|
else {
|
|
1101
|
-
this.
|
|
1102
|
-
this.
|
|
1078
|
+
this.router.navigate(["/auth/login"]).then(e => {
|
|
1079
|
+
this.messageService.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1103
1080
|
});
|
|
1104
1081
|
}
|
|
1105
1082
|
}
|
|
1106
1083
|
else {
|
|
1107
|
-
this.
|
|
1108
|
-
this.
|
|
1084
|
+
this.router.navigate(["/auth/login"]).then(e => {
|
|
1085
|
+
this.messageService.showAlertDanger(Utils.getHttpErrorMessage(error));
|
|
1109
1086
|
});
|
|
1110
1087
|
}
|
|
1111
1088
|
}
|
|
@@ -1113,14 +1090,14 @@ class AuthUtilService {
|
|
|
1113
1090
|
// Mostra uma mensagem de sessão expirada.
|
|
1114
1091
|
showExpiredAccess(navigationResult) {
|
|
1115
1092
|
if (navigationResult) {
|
|
1116
|
-
this.
|
|
1093
|
+
this.messageService.showAlertWarning("Sessão expirada, logue-se novamente.");
|
|
1117
1094
|
}
|
|
1118
1095
|
}
|
|
1119
1096
|
// Obtém o hostName
|
|
1120
1097
|
getHostName() {
|
|
1121
1098
|
return this._customEnvironmentService.hostName;
|
|
1122
1099
|
}
|
|
1123
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, deps: [{ token:
|
|
1100
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, deps: [{ token: i1$1.Router }, { token: AuthStorageService }, { token: i3.CheckUrlAndMethodService }, { token: i3.MessageService }, { token: LibCustomEnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1124
1101
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, providedIn: 'root' }); }
|
|
1125
1102
|
}
|
|
1126
1103
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: AuthUtilService, decorators: [{
|
|
@@ -1128,7 +1105,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
1128
1105
|
args: [{
|
|
1129
1106
|
providedIn: 'root'
|
|
1130
1107
|
}]
|
|
1131
|
-
}], ctorParameters: () => [{ type:
|
|
1108
|
+
}], ctorParameters: () => [{ type: i1$1.Router }, { type: AuthStorageService }, { type: i3.CheckUrlAndMethodService }, { type: i3.MessageService }, { type: LibCustomEnvironmentService }] });
|
|
1132
1109
|
|
|
1133
1110
|
class AuthService {
|
|
1134
1111
|
// #endregion PRIVATE
|
|
@@ -1145,23 +1122,20 @@ class AuthService {
|
|
|
1145
1122
|
// #region ==========> PROPERTIES <==========
|
|
1146
1123
|
// #region PRIVATE
|
|
1147
1124
|
this._pendingWarning = null;
|
|
1148
|
-
this._AUTH_BASE_URL = ''; // SpInfra2AuthWS
|
|
1149
1125
|
this._BASE_URL = ''; // SpInfra2WS
|
|
1126
|
+
this._AUTH_BASE_URL = ''; // SpInfra2AuthWS
|
|
1150
1127
|
this._BASE_OS_URL = ''; // SpInfra2LoginWS
|
|
1151
|
-
this._LOGOUT_BASE_URL = ''; // SpInfra2LoginWS
|
|
1152
1128
|
this._HTTP_HEADERS = new HttpHeaders().set('Content-Type', 'application/json');
|
|
1153
1129
|
this.ip = "undefined";
|
|
1154
1130
|
this.city = "undefined";
|
|
1155
1131
|
this.state = "undefined";
|
|
1156
1132
|
this.country = "undefined";
|
|
1133
|
+
this._BASE_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; // SpInfra2WS
|
|
1157
1134
|
this._AUTH_BASE_URL = `${this._customEnvironmentService.SpInfra2AuthWS}/Auth`; // SpInfra2AuthWS
|
|
1158
|
-
this._BASE_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`; // SpInfra2LoginWS
|
|
1159
1135
|
this._BASE_OS_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LoginIntegradoOS`; // SpInfra2LoginWS
|
|
1160
|
-
this._LOGOUT_BASE_URL = `${this._customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`; // SpInfra2LoginWS
|
|
1161
|
-
this._AUTH_BASE_URL = !this._customEnvironmentService.production ? this._AUTH_BASE_URL : `${this._customEnvironmentService.SpInfra2AuthWS}/Auth`;
|
|
1162
1136
|
this._BASE_URL = !this._customEnvironmentService.production ? this._BASE_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LoginSisproERP`;
|
|
1137
|
+
this._AUTH_BASE_URL = !this._customEnvironmentService.production ? this._AUTH_BASE_URL : `${this._customEnvironmentService.SpInfra2AuthWS}/Auth`;
|
|
1163
1138
|
this._BASE_OS_URL = !this._customEnvironmentService.production ? this._BASE_OS_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LoginIntegradoOS`;
|
|
1164
|
-
this._LOGOUT_BASE_URL = !this._customEnvironmentService.production ? this._LOGOUT_BASE_URL : `${this._customEnvironmentService.SpInfra2LoginWS}/LogoutSisproErp`;
|
|
1165
1139
|
this.getParms();
|
|
1166
1140
|
}
|
|
1167
1141
|
// #region ==========> SERVICE METHODS <==========
|
|
@@ -1219,10 +1193,8 @@ class AuthService {
|
|
|
1219
1193
|
if (response.Error) {
|
|
1220
1194
|
throw Error(response.ErrorMessage);
|
|
1221
1195
|
}
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
// localStorage.setItem('configServerUser', response.User);
|
|
1225
|
-
// localStorage.setItem('configServerPassword', response.Password);
|
|
1196
|
+
localStorage.setItem('configServerUser', response.User);
|
|
1197
|
+
localStorage.setItem('configServerPassword', response.Password);
|
|
1226
1198
|
this._authStorageService.tenantId = response.TenantId;
|
|
1227
1199
|
this._authStorageService.dominio = response.Domain;
|
|
1228
1200
|
this._authStorageService.infraInAuthTypeId = response.InfraInAuthTypeId;
|
|
@@ -1466,22 +1438,14 @@ class AuthService {
|
|
|
1466
1438
|
}
|
|
1467
1439
|
}));
|
|
1468
1440
|
}
|
|
1469
|
-
/**
|
|
1470
|
-
* Realiza o logout do sistema, consumindo o endpoint de logout para remover os cookies e limpando as informações de autenticação armazenadas no localStorage.
|
|
1471
|
-
* @returns Promise<boolean> indicando navegação para a tela de login após o logout.
|
|
1472
|
-
*/
|
|
1441
|
+
/** Realiza o logout do sistema, removendo tokens do localStorage e limpando cache */
|
|
1473
1442
|
logout() {
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
localStorage.removeItem('configServerPassword');
|
|
1481
|
-
// Método com customizações para inicializações do Logout
|
|
1482
|
-
this._customLoginService.authLogout();
|
|
1483
|
-
});
|
|
1484
|
-
return this._router.navigate(["/auth/login"]);
|
|
1443
|
+
this._authStorageService.logout();
|
|
1444
|
+
localStorage.removeItem('configsServerUser');
|
|
1445
|
+
localStorage.removeItem('configsServerPassword');
|
|
1446
|
+
// Método com customizações para inicializações do Logout
|
|
1447
|
+
this._customLoginService.authLogout();
|
|
1448
|
+
this._router.navigate(["/auth/login"]);
|
|
1485
1449
|
}
|
|
1486
1450
|
validateAuthentication2Fa(code) {
|
|
1487
1451
|
let Code2Fa = {
|
|
@@ -2008,12 +1972,16 @@ class PesquisaTelasGlobalService {
|
|
|
2008
1972
|
// #region PUBLIC
|
|
2009
1973
|
// #endregion PUBLIC
|
|
2010
1974
|
// #endregion ==========> PROPERTIES <==========
|
|
2011
|
-
constructor(_appRef, _injector, _httpClient, _customEnvironmentService, _authUtils) {
|
|
1975
|
+
constructor(_componentFactoryResolver, _appRef, _injector, _httpClient, _customEnvironmentService, _authUtils) {
|
|
1976
|
+
this._componentFactoryResolver = _componentFactoryResolver;
|
|
2012
1977
|
this._appRef = _appRef;
|
|
2013
1978
|
this._injector = _injector;
|
|
2014
1979
|
this._httpClient = _httpClient;
|
|
2015
1980
|
this._customEnvironmentService = _customEnvironmentService;
|
|
2016
1981
|
this._authUtils = _authUtils;
|
|
1982
|
+
// #region ==========> PROPERTIES <==========
|
|
1983
|
+
// #region PRIVATE
|
|
1984
|
+
// #region GERENCIAMENTO DINÂMICO DO COMPONENTE
|
|
2017
1985
|
/**
|
|
2018
1986
|
* Referência ao componente dinâmico criado.
|
|
2019
1987
|
* Usado para gerenciar o ciclo de vida e estado do componente.
|
|
@@ -2135,7 +2103,7 @@ class PesquisaTelasGlobalService {
|
|
|
2135
2103
|
*
|
|
2136
2104
|
* Este método utiliza a API baixo nível do Angular para criar um componente dinamicamente e anexá-lo ao DOM. O processo envolve:
|
|
2137
2105
|
*
|
|
2138
|
-
* 1. Criar o componente via
|
|
2106
|
+
* 1. Criar o componente via ComponentFactoryResolver
|
|
2139
2107
|
* 2. Configurar suas propriedades iniciais
|
|
2140
2108
|
* 3. Registrá-lo no mecanismo de detecção de mudanças do Angular
|
|
2141
2109
|
* 4. Anexá-lo ao DOM (fora da hierarquia normal de componentes)
|
|
@@ -2151,18 +2119,24 @@ class PesquisaTelasGlobalService {
|
|
|
2151
2119
|
if (this._componentRef) {
|
|
2152
2120
|
return;
|
|
2153
2121
|
}
|
|
2154
|
-
// 1.
|
|
2155
|
-
|
|
2156
|
-
//
|
|
2122
|
+
// 1. Resolve a fábrica do componente - primeiro passo para criar
|
|
2123
|
+
// um componente dinamicamente no Angular. A fábrica contém os metadados
|
|
2124
|
+
// necessários para instanciar o componente.
|
|
2125
|
+
const componentFactory = this._componentFactoryResolver.resolveComponentFactory(SearchInputComponent);
|
|
2126
|
+
// 2. Cria uma nova instância do componente usando o injector raiz
|
|
2127
|
+
// Isso garante que o componente tenha acesso aos mesmos serviços
|
|
2128
|
+
// que componentes criados normalmente via template
|
|
2129
|
+
this._componentRef = componentFactory.create(this._injector);
|
|
2130
|
+
// 3. Registra a view do componente no ApplicationRef
|
|
2157
2131
|
// Isso é CRÍTICO: sem este passo, o componente não participaria
|
|
2158
2132
|
// do ciclo de detecção de mudanças do Angular
|
|
2159
2133
|
this._appRef.attachView(this._componentRef.hostView);
|
|
2160
|
-
//
|
|
2134
|
+
// 4. Obtém o elemento DOM raiz do componente e o anexa ao body
|
|
2161
2135
|
// Como este componente é criado fora da hierarquia normal,
|
|
2162
2136
|
// precisamos anexá-lo manualmente ao DOM
|
|
2163
2137
|
const domElem = this._componentRef.hostView.rootNodes[0];
|
|
2164
2138
|
document.body.appendChild(domElem);
|
|
2165
|
-
//
|
|
2139
|
+
// 5. Configura os listeners dos eventos do componente
|
|
2166
2140
|
// Em vez de tratar o hide() diretamente aqui, encaminhamos o evento para o Subject _onClose$ e guardamos a subscription para poder removê-la quando escondermos o componente.
|
|
2167
2141
|
this._componentCloseSub = this._componentRef.instance.onClose.subscribe(() => this._onClose$.next());
|
|
2168
2142
|
// Em vez de tratar o getTelas() diretamente aqui, encaminhamos o evento para o Subject _onSearch$ e guardamos a subscription para poder removê-la quando escondermos o componente.
|
|
@@ -2206,16 +2180,13 @@ class PesquisaTelasGlobalService {
|
|
|
2206
2180
|
// #endregion GERENCIAMENTO DO COMPONENTE
|
|
2207
2181
|
showErrorMessage(response) { if (response.Error)
|
|
2208
2182
|
throw Error(response.ErrorMessage); }
|
|
2209
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, deps: [{ token: i0.ApplicationRef }, { token: i0.Injector }, { token: i1.HttpClient }, { token: LibCustomEnvironmentService }, { token: AuthUtilService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2183
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, deps: [{ token: i0.ComponentFactoryResolver }, { token: i0.ApplicationRef }, { token: i0.Injector }, { token: i1.HttpClient }, { token: LibCustomEnvironmentService }, { token: AuthUtilService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2210
2184
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, providedIn: 'root' }); }
|
|
2211
2185
|
}
|
|
2212
2186
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: PesquisaTelasGlobalService, decorators: [{
|
|
2213
2187
|
type: Injectable,
|
|
2214
2188
|
args: [{ providedIn: 'root' }]
|
|
2215
|
-
}], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.Injector }, { type: i1.HttpClient }, { type: LibCustomEnvironmentService }, { type: AuthUtilService }]
|
|
2216
|
-
type: ViewChild,
|
|
2217
|
-
args: ['container', { read: ViewContainerRef, static: true }]
|
|
2218
|
-
}] } });
|
|
2189
|
+
}], ctorParameters: () => [{ type: i0.ComponentFactoryResolver }, { type: i0.ApplicationRef }, { type: i0.Injector }, { type: i1.HttpClient }, { type: LibCustomEnvironmentService }, { type: AuthUtilService }] });
|
|
2219
2190
|
|
|
2220
2191
|
class ErrorMenuNotAllowed {
|
|
2221
2192
|
constructor(router, authStorageService) {
|
|
@@ -4684,13 +4655,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
4684
4655
|
;
|
|
4685
4656
|
|
|
4686
4657
|
/**
|
|
4687
|
-
* Intercepta uma chamada HTTP para inserir o usuário logado
|
|
4658
|
+
* \brief Intercepta uma chamada HTTP para inserir o usuário logado no header em conjunto
|
|
4659
|
+
* com o login para uso da API.
|
|
4660
|
+
*
|
|
4688
4661
|
* Depende do serviço de autenticação.
|
|
4689
|
-
*/
|
|
4662
|
+
*/
|
|
4690
4663
|
class AuthAplicInterceptor {
|
|
4691
|
-
constructor(
|
|
4692
|
-
this.
|
|
4693
|
-
this.
|
|
4664
|
+
constructor(authCheckService, token, _customEnvironmentService) {
|
|
4665
|
+
this.authCheckService = authCheckService;
|
|
4666
|
+
this.token = token;
|
|
4694
4667
|
this._customEnvironmentService = _customEnvironmentService;
|
|
4695
4668
|
}
|
|
4696
4669
|
intercept(req, next) {
|
|
@@ -4699,16 +4672,12 @@ class AuthAplicInterceptor {
|
|
|
4699
4672
|
}
|
|
4700
4673
|
async handle(req, next) {
|
|
4701
4674
|
let changedReq = req;
|
|
4702
|
-
if (this.
|
|
4675
|
+
if (this.authCheckService.needsAuthRequest(req.url, req.method, this._customEnvironmentService.needsAuthAplic)) {
|
|
4703
4676
|
// Verifica se o Token precisa ser renovado
|
|
4704
|
-
await this.
|
|
4677
|
+
await this.token.renewToken();
|
|
4705
4678
|
// Adiciona as autenticações necessárias ao servidor.
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
changedReq = req.clone({
|
|
4709
|
-
headers: headers,
|
|
4710
|
-
withCredentials: true // Parâmetro necessário para utilização dos Cookies HttpOnly
|
|
4711
|
-
});
|
|
4679
|
+
let headers = req.headers.set('Authorization', `Bearer ${this.token.authToken}`);
|
|
4680
|
+
changedReq = req.clone({ headers: headers });
|
|
4712
4681
|
}
|
|
4713
4682
|
return await lastValueFrom(next.handle(changedReq));
|
|
4714
4683
|
}
|
|
@@ -4720,27 +4689,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
4720
4689
|
args: [{ providedIn: 'root' }]
|
|
4721
4690
|
}], ctorParameters: () => [{ type: i3.CheckUrlAndMethodService }, { type: AuthStorageService }, { type: LibCustomEnvironmentService }] });
|
|
4722
4691
|
|
|
4723
|
-
/**
|
|
4692
|
+
/**
|
|
4693
|
+
* \brief Intercepta uma chamada HTTP para inserir a autenticação da Sispro.
|
|
4694
|
+
*/
|
|
4724
4695
|
class AuthInfraInterceptor {
|
|
4725
|
-
constructor(
|
|
4726
|
-
this.
|
|
4696
|
+
constructor(authCheckService, _customEnvironmentService) {
|
|
4697
|
+
this.authCheckService = authCheckService;
|
|
4727
4698
|
this._customEnvironmentService = _customEnvironmentService;
|
|
4728
4699
|
}
|
|
4729
4700
|
intercept(req, next) {
|
|
4730
4701
|
let changedReq = req;
|
|
4731
|
-
if (this.
|
|
4732
|
-
// Instanciado inicialmente com os headers da requisição original, para não perder nenhum header que já tenha sido adicionado
|
|
4733
|
-
let headers = req.headers;
|
|
4702
|
+
if (this.authCheckService.needsAuthRequest(req.url, req.method, this._customEnvironmentService.needsAuthInfra)) {
|
|
4734
4703
|
// Adiciona as autenticações necessárias ao servidor. Autenticação básica.
|
|
4735
|
-
|
|
4736
|
-
if (localStorage.getItem('configServerUser') && localStorage.getItem('configServerPassword')) {
|
|
4737
|
-
headers = req.headers.set("Authorization", `Basic ${btoa(`${localStorage.getItem('configServerUser')}:${localStorage.getItem('configServerPassword')}`)}
|
|
4704
|
+
let headers = req.headers.set("Authorization", `Basic ${btoa(`${localStorage.getItem('configServerUser')}:${localStorage.getItem('configServerPassword')}`)}
|
|
4738
4705
|
`);
|
|
4739
|
-
}
|
|
4740
|
-
changedReq = req.clone({
|
|
4741
|
-
headers: headers,
|
|
4742
|
-
withCredentials: true // Parâmetro necessário para utilização dos Cookies HttpOnly
|
|
4743
|
-
});
|
|
4706
|
+
changedReq = req.clone({ headers: headers });
|
|
4744
4707
|
}
|
|
4745
4708
|
return next.handle(changedReq);
|
|
4746
4709
|
}
|