ssi-security-commons 0.0.20 → 0.16.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/esm2022/lib/alert/alert.component.mjs +28 -0
- package/{esm2020 → esm2022}/lib/services/auth-interceptor.service.mjs +7 -7
- package/{esm2020 → esm2022}/lib/services/crypto.service.mjs +4 -4
- package/esm2022/lib/services/messages.service.mjs +209 -0
- package/{esm2020 → esm2022}/lib/services/session.service.mjs +4 -4
- package/esm2022/lib/ssi-security-commons.component.mjs +13 -0
- package/esm2022/lib/ssi-security-commons.module.mjs +53 -0
- package/{esm2020 → esm2022}/lib/ssi-security-commons.service.mjs +4 -4
- package/{fesm2020 → fesm2022}/ssi-security-commons.mjs +55 -57
- package/fesm2022/ssi-security-commons.mjs.map +1 -0
- package/lib/alert/alert.component.d.ts +2 -2
- package/lib/ssi-security-commons.component.d.ts +1 -1
- package/package.json +10 -16
- package/esm2020/lib/alert/alert.component.mjs +0 -27
- package/esm2020/lib/services/messages.service.mjs +0 -209
- package/esm2020/lib/ssi-security-commons.component.mjs +0 -17
- package/esm2020/lib/ssi-security-commons.module.mjs +0 -55
- package/fesm2015/ssi-security-commons.mjs +0 -768
- package/fesm2015/ssi-security-commons.mjs.map +0 -1
- package/fesm2020/ssi-security-commons.mjs.map +0 -1
- /package/{esm2020 → esm2022}/lib/user.model.mjs +0 -0
- /package/{esm2020 → esm2022}/public-api.mjs +0 -0
- /package/{esm2020 → esm2022}/ssi-security-commons.mjs +0 -0
- /package/{ssi-security-commons.d.ts → index.d.ts} +0 -0
|
@@ -1,768 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, Component, Inject, NgModule } from '@angular/core';
|
|
3
|
-
import * as i1 from '@angular/material/dialog';
|
|
4
|
-
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
|
|
5
|
-
import * as i2$1 from '@angular/material/snack-bar';
|
|
6
|
-
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
|
7
|
-
import * as CryptoJS from 'crypto-js';
|
|
8
|
-
import * as i2 from '@angular/material/button';
|
|
9
|
-
import { MatButtonModule } from '@angular/material/button';
|
|
10
|
-
import { __awaiter } from 'tslib';
|
|
11
|
-
import * as i1$1 from '@angular/common/http';
|
|
12
|
-
import { HttpHeaders, HttpResponse, HttpErrorResponse } from '@angular/common/http';
|
|
13
|
-
import { map, catchError, switchMap, filter, take } from 'rxjs/operators';
|
|
14
|
-
import { CrossStorageClient } from 'cross-storage';
|
|
15
|
-
import { BehaviorSubject, throwError } from 'rxjs';
|
|
16
|
-
import * as i2$2 from '@angular/router';
|
|
17
|
-
|
|
18
|
-
class SsiSecurityCommonsService {
|
|
19
|
-
}
|
|
20
|
-
SsiSecurityCommonsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
21
|
-
SsiSecurityCommonsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsService, providedIn: 'root' });
|
|
22
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsService, decorators: [{
|
|
23
|
-
type: Injectable,
|
|
24
|
-
args: [{
|
|
25
|
-
providedIn: 'root'
|
|
26
|
-
}]
|
|
27
|
-
}] });
|
|
28
|
-
|
|
29
|
-
class SsiSecurityCommonsComponent {
|
|
30
|
-
}
|
|
31
|
-
SsiSecurityCommonsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
32
|
-
SsiSecurityCommonsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.3", type: SsiSecurityCommonsComponent, selector: "lib-ssi-security-commons", ngImport: i0, template: ` <p>ssi-security-commons works!</p>
|
|
33
|
-
`, isInline: true });
|
|
34
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsComponent, decorators: [{
|
|
35
|
-
type: Component,
|
|
36
|
-
args: [{
|
|
37
|
-
selector: 'lib-ssi-security-commons',
|
|
38
|
-
template: ` <p>ssi-security-commons works!</p>
|
|
39
|
-
`,
|
|
40
|
-
styles: []
|
|
41
|
-
}]
|
|
42
|
-
}] });
|
|
43
|
-
|
|
44
|
-
class CryptoService {
|
|
45
|
-
constructor() {
|
|
46
|
-
this.secret = '&E)H@McQfThWmZq4';
|
|
47
|
-
this.configuration = {
|
|
48
|
-
mode: CryptoJS.mode.ECB
|
|
49
|
-
};
|
|
50
|
-
const hash = CryptoJS.SHA1(this.secret);
|
|
51
|
-
this.key = CryptoJS.lib.WordArray.create(hash.words.slice(0, 16 / 4));
|
|
52
|
-
}
|
|
53
|
-
encrypt(text) {
|
|
54
|
-
return CryptoJS.AES.encrypt(text, this.key, this.configuration).toString();
|
|
55
|
-
}
|
|
56
|
-
decrypt(text) {
|
|
57
|
-
return CryptoJS.AES.decrypt(text, this.key, this.configuration).toString(CryptoJS.enc.Utf8);
|
|
58
|
-
}
|
|
59
|
-
encryptWithSecret(text, secret) {
|
|
60
|
-
const hash = CryptoJS.SHA1(secret);
|
|
61
|
-
const key = CryptoJS.lib.WordArray.create(hash.words.slice(0, 16 / 4));
|
|
62
|
-
return CryptoJS.AES.encrypt(text, key, this.configuration).toString();
|
|
63
|
-
}
|
|
64
|
-
decryptWithSecret(text, secret) {
|
|
65
|
-
const hash = CryptoJS.SHA1(secret);
|
|
66
|
-
const key = CryptoJS.lib.WordArray.create(hash.words.slice(0, 16 / 4));
|
|
67
|
-
return CryptoJS.AES.decrypt(text, key, this.configuration).toString(CryptoJS.enc.Utf8);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
CryptoService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: CryptoService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
71
|
-
CryptoService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: CryptoService });
|
|
72
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: CryptoService, decorators: [{
|
|
73
|
-
type: Injectable
|
|
74
|
-
}], ctorParameters: function () { return []; } });
|
|
75
|
-
|
|
76
|
-
class AlertComponent {
|
|
77
|
-
constructor(dialogRef, data) {
|
|
78
|
-
this.dialogRef = dialogRef;
|
|
79
|
-
this.data = data;
|
|
80
|
-
}
|
|
81
|
-
onConfirm() {
|
|
82
|
-
this.dialogRef.close(true);
|
|
83
|
-
}
|
|
84
|
-
onCancel() {
|
|
85
|
-
this.dialogRef.close(null);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
AlertComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AlertComponent, deps: [{ token: i1.MatDialogRef }, { token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component });
|
|
89
|
-
AlertComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.3", type: AlertComponent, selector: "lib-app-alert", ngImport: i0, template: "<h1 mat-dialog-title>{{data.title?data.title:'Alert'}}</h1>\n<div mat-dialog-content class=\"alert-min-width\">\n <div>\n {{data.message}}\n </div>\n</div>\n<div mat-dialog-actions align=\"end\">\n <button *ngIf=\"data?.cancelText\" mat-button (click)=\"onCancel()\">{{data.cancelText ? data.cancelText : 'Cancel'}}</button>\n <button mat-button color=\"primary\" (click)=\"onConfirm()\">{{data.okText ? data.okText : 'OK'}}</button>\n</div>\n", styles: [""], components: [{ type: i2.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }] });
|
|
90
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AlertComponent, decorators: [{
|
|
91
|
-
type: Component,
|
|
92
|
-
args: [{ selector: 'lib-app-alert', template: "<h1 mat-dialog-title>{{data.title?data.title:'Alert'}}</h1>\n<div mat-dialog-content class=\"alert-min-width\">\n <div>\n {{data.message}}\n </div>\n</div>\n<div mat-dialog-actions align=\"end\">\n <button *ngIf=\"data?.cancelText\" mat-button (click)=\"onCancel()\">{{data.cancelText ? data.cancelText : 'Cancel'}}</button>\n <button mat-button color=\"primary\" (click)=\"onConfirm()\">{{data.okText ? data.okText : 'OK'}}</button>\n</div>\n", styles: [""] }]
|
|
93
|
-
}], ctorParameters: function () {
|
|
94
|
-
return [{ type: i1.MatDialogRef }, { type: undefined, decorators: [{
|
|
95
|
-
type: Inject,
|
|
96
|
-
args: [MAT_DIALOG_DATA]
|
|
97
|
-
}] }];
|
|
98
|
-
} });
|
|
99
|
-
|
|
100
|
-
class SessionService {
|
|
101
|
-
constructor(http, environment) {
|
|
102
|
-
this.http = http;
|
|
103
|
-
this.loginUrl = 'http://localhost:4200/login';
|
|
104
|
-
this.endPoint = environment.endPoint;
|
|
105
|
-
this.applicationId = environment.applicationId;
|
|
106
|
-
const urlHub = environment.sessionHub;
|
|
107
|
-
console.log(urlHub);
|
|
108
|
-
this.storage = new CrossStorageClient(urlHub, { timeout: 5000 });
|
|
109
|
-
}
|
|
110
|
-
checkSessionData() {
|
|
111
|
-
const promise = new Promise((resolve, reject) => {
|
|
112
|
-
let data;
|
|
113
|
-
let token;
|
|
114
|
-
let refreshToken;
|
|
115
|
-
const self = this;
|
|
116
|
-
this.storage.onConnect().then(function () {
|
|
117
|
-
return self.storage.get('USERDATA', 'TOKEN', 'REFRESH_TOKEN');
|
|
118
|
-
}).then(function (res) {
|
|
119
|
-
console.log(res);
|
|
120
|
-
data = res[0];
|
|
121
|
-
token = res[1];
|
|
122
|
-
refreshToken = res[2];
|
|
123
|
-
if (data && token && refreshToken) {
|
|
124
|
-
const user = JSON.parse(data);
|
|
125
|
-
self.saveCredentials(token, refreshToken);
|
|
126
|
-
self.saveUserData(user);
|
|
127
|
-
self.checkAppPermissions().then((res1) => {
|
|
128
|
-
console.log(res1);
|
|
129
|
-
resolve('OK');
|
|
130
|
-
}, (err) => {
|
|
131
|
-
console.error(err);
|
|
132
|
-
reject(err);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
self.destroyCredentials();
|
|
137
|
-
self.destroyUserData();
|
|
138
|
-
self.getLoginUrl().subscribe(res1 => {
|
|
139
|
-
console.log(res1);
|
|
140
|
-
self.loginUrl = res1.data;
|
|
141
|
-
const url = window.location.href;
|
|
142
|
-
if (url.indexOf('/login') < 0 && url.indexOf('/forgot') < 0 && url.indexOf('/reset') < 0) {
|
|
143
|
-
window.location.href = self.loginUrl + '?continue=' + encodeURIComponent(url);
|
|
144
|
-
}
|
|
145
|
-
resolve('NOK');
|
|
146
|
-
}, (err) => {
|
|
147
|
-
console.error(err);
|
|
148
|
-
reject(err);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}).catch(function (err) {
|
|
152
|
-
console.error(err);
|
|
153
|
-
reject(err);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
return promise;
|
|
157
|
-
}
|
|
158
|
-
reviewSessionData() {
|
|
159
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
const value = yield this.checkSessionData();
|
|
161
|
-
console.log(`async result: ${value}`);
|
|
162
|
-
return value;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
setUserdata(userdata) {
|
|
166
|
-
this.userdata = userdata;
|
|
167
|
-
}
|
|
168
|
-
setTokens(token, refreshToken) {
|
|
169
|
-
this.token = token;
|
|
170
|
-
this.refreshToken = refreshToken;
|
|
171
|
-
}
|
|
172
|
-
getUserdata() {
|
|
173
|
-
return this.userdata;
|
|
174
|
-
}
|
|
175
|
-
setRefreshToken(refreshToken) {
|
|
176
|
-
this.refreshToken = refreshToken;
|
|
177
|
-
window.localStorage.setItem('REFRESH_TOKEN', refreshToken);
|
|
178
|
-
this.storage.onConnect().then(() => {
|
|
179
|
-
return this.storage.set('REFRESH_TOKEN', refreshToken);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
getRefreshToken() {
|
|
183
|
-
return this.refreshToken;
|
|
184
|
-
}
|
|
185
|
-
setToken(token) {
|
|
186
|
-
this.token = token;
|
|
187
|
-
window.localStorage.setItem('TOKEN', token);
|
|
188
|
-
this.storage.onConnect().then(() => {
|
|
189
|
-
return this.storage.set('TOKEN', token);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
getToken() {
|
|
193
|
-
return this.token;
|
|
194
|
-
}
|
|
195
|
-
destroyCredentials() {
|
|
196
|
-
this.token = undefined;
|
|
197
|
-
this.refreshToken = undefined;
|
|
198
|
-
window.localStorage.removeItem('TOKEN');
|
|
199
|
-
window.localStorage.removeItem('REFRESH_TOKEN');
|
|
200
|
-
this.storage.onConnect().then(() => {
|
|
201
|
-
return this.storage.del('TOKEN', 'REFRESH_TOKEN');
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
destroyUserData() {
|
|
205
|
-
this.userdata = undefined;
|
|
206
|
-
window.localStorage.removeItem('USERDATA');
|
|
207
|
-
this.storage.onConnect().then(() => {
|
|
208
|
-
return this.storage.del('USERDATA');
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
saveCredentials(token, refreshToken) {
|
|
212
|
-
this.token = token;
|
|
213
|
-
this.refreshToken = refreshToken;
|
|
214
|
-
window.localStorage.setItem('TOKEN', token);
|
|
215
|
-
window.localStorage.setItem('REFRESH_TOKEN', refreshToken);
|
|
216
|
-
this.storage.onConnect().then(() => {
|
|
217
|
-
return this.storage.set('TOKEN', token);
|
|
218
|
-
});
|
|
219
|
-
this.storage.onConnect().then(() => {
|
|
220
|
-
return this.storage.set('REFRESH_TOKEN', refreshToken);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
saveUserData(userdata) {
|
|
224
|
-
this.userdata = userdata;
|
|
225
|
-
window.localStorage.setItem('USERDATA', JSON.stringify(this.userdata));
|
|
226
|
-
this.storage.onConnect().then(() => {
|
|
227
|
-
return this.storage.set('USERDATA', JSON.stringify(this.userdata));
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
isLoggedIn() {
|
|
231
|
-
return !!this.userdata;
|
|
232
|
-
}
|
|
233
|
-
logout() {
|
|
234
|
-
return new Promise((resolve, reject) => {
|
|
235
|
-
var _a;
|
|
236
|
-
this.logoutApi((_a = this.userdata) === null || _a === void 0 ? void 0 : _a.userId).subscribe(res => {
|
|
237
|
-
console.log(res);
|
|
238
|
-
this.destroyCredentials();
|
|
239
|
-
this.destroyUserData();
|
|
240
|
-
this.goToLogin();
|
|
241
|
-
resolve(null);
|
|
242
|
-
}, (err) => {
|
|
243
|
-
this.destroyCredentials();
|
|
244
|
-
this.destroyUserData();
|
|
245
|
-
console.error(err);
|
|
246
|
-
reject(err);
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
getNewToken(refreshToken) {
|
|
251
|
-
console.log('getNewToken');
|
|
252
|
-
const httpOptions = {
|
|
253
|
-
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
|
|
254
|
-
};
|
|
255
|
-
return this.http.post(this.endPoint + '/auth/refresh-token', { refreshToken }, httpOptions);
|
|
256
|
-
}
|
|
257
|
-
getLoginUrl() {
|
|
258
|
-
return this.http.get(this.endPoint + '/auth/login/url')
|
|
259
|
-
.pipe(map(res => res));
|
|
260
|
-
}
|
|
261
|
-
getHomeUrl() {
|
|
262
|
-
return this.http.get(this.endPoint + '/auth/home/url')
|
|
263
|
-
.pipe(map(res => res));
|
|
264
|
-
}
|
|
265
|
-
logoutApi(userId) {
|
|
266
|
-
return this.http.post(this.endPoint + '/auth/logout', { userId })
|
|
267
|
-
.pipe(map(res => res));
|
|
268
|
-
}
|
|
269
|
-
goToLogin() {
|
|
270
|
-
this.getLoginUrl().subscribe(res => {
|
|
271
|
-
console.log(res);
|
|
272
|
-
const loginUrl = res.data;
|
|
273
|
-
window.location.href = loginUrl;
|
|
274
|
-
}, (err) => {
|
|
275
|
-
console.error(err);
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
loadSessionData() {
|
|
279
|
-
const data = window.localStorage.getItem('USERDATA');
|
|
280
|
-
const token = window.localStorage.getItem('TOKEN');
|
|
281
|
-
const refreshToken = window.localStorage.getItem('REFRESH_TOKEN');
|
|
282
|
-
if (data && token && refreshToken) {
|
|
283
|
-
const user = JSON.parse(data);
|
|
284
|
-
this.setTokens(token, refreshToken);
|
|
285
|
-
this.setUserdata(user);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
userHasOptionsInApp(userId, applicationId) {
|
|
289
|
-
return this.http.get(this.endPoint + `/security/option/${applicationId}/${userId}`)
|
|
290
|
-
.pipe(map(res => res));
|
|
291
|
-
}
|
|
292
|
-
checkAppPermissions() {
|
|
293
|
-
const promise = new Promise((resolve, reject) => {
|
|
294
|
-
var _a, _b;
|
|
295
|
-
console.log((_a = this.userdata) === null || _a === void 0 ? void 0 : _a.userId, this.applicationId);
|
|
296
|
-
if (this.applicationId) {
|
|
297
|
-
this.userHasOptionsInApp((_b = this.userdata) === null || _b === void 0 ? void 0 : _b.userId, this.applicationId).subscribe(res => {
|
|
298
|
-
console.log(res);
|
|
299
|
-
if (res.data) {
|
|
300
|
-
resolve('ok');
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
this.getHomeUrl().subscribe(res1 => {
|
|
304
|
-
console.log(res1);
|
|
305
|
-
const homeUrl = res1.data;
|
|
306
|
-
window.location.href = homeUrl;
|
|
307
|
-
reject('nok');
|
|
308
|
-
}, (err) => {
|
|
309
|
-
console.error(err);
|
|
310
|
-
reject('nok');
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
}, (err) => {
|
|
314
|
-
console.error(err);
|
|
315
|
-
reject('nok');
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
resolve('ok');
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
return promise;
|
|
323
|
-
}
|
|
324
|
-
// eslint-disable-next-line max-len
|
|
325
|
-
getOptionsUser(applicationId, type, language, entityCode, parentOptionId, includeData) {
|
|
326
|
-
var _a;
|
|
327
|
-
const param = {
|
|
328
|
-
userId: (_a = this.userdata) === null || _a === void 0 ? void 0 : _a.userId,
|
|
329
|
-
applicationId,
|
|
330
|
-
type,
|
|
331
|
-
language,
|
|
332
|
-
entityCode,
|
|
333
|
-
parentOptionId,
|
|
334
|
-
includeData
|
|
335
|
-
};
|
|
336
|
-
return this.http.post(this.endPoint + '/security/option/user', param)
|
|
337
|
-
.pipe(map(res => res));
|
|
338
|
-
}
|
|
339
|
-
registerException(param) {
|
|
340
|
-
const headers = new HttpHeaders().set('skipError', 'true');
|
|
341
|
-
return this.http.post(this.endPoint + '/auth/exception/log', param, { headers })
|
|
342
|
-
.pipe(map(res => res));
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
SessionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SessionService, deps: [{ token: i1$1.HttpClient }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
346
|
-
SessionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SessionService });
|
|
347
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SessionService, decorators: [{
|
|
348
|
-
type: Injectable
|
|
349
|
-
}], ctorParameters: function () {
|
|
350
|
-
return [{ type: i1$1.HttpClient }, { type: undefined, decorators: [{
|
|
351
|
-
type: Inject,
|
|
352
|
-
args: ['environment']
|
|
353
|
-
}] }];
|
|
354
|
-
} });
|
|
355
|
-
|
|
356
|
-
class MessagesService {
|
|
357
|
-
constructor(auth,
|
|
358
|
-
// private router: Router,
|
|
359
|
-
snackBar, dialog, environment) {
|
|
360
|
-
this.auth = auth;
|
|
361
|
-
this.snackBar = snackBar;
|
|
362
|
-
this.dialog = dialog;
|
|
363
|
-
this.applicationId = environment.applicationId;
|
|
364
|
-
}
|
|
365
|
-
// eslint-disable-next-line max-lines-per-function
|
|
366
|
-
showErrorMessage(error, request) {
|
|
367
|
-
console.log('error: ', error);
|
|
368
|
-
this.registerLog(error, request);
|
|
369
|
-
const msgs = this.getInterceptorMessages();
|
|
370
|
-
switch (error.status) {
|
|
371
|
-
case 302: {
|
|
372
|
-
this.messageSnackError(error);
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
case 400: {
|
|
376
|
-
this.showSnackError(error.message, ['snack-error']);
|
|
377
|
-
break;
|
|
378
|
-
}
|
|
379
|
-
case 403: {
|
|
380
|
-
this.goNavigateLogin(msgs);
|
|
381
|
-
break;
|
|
382
|
-
}
|
|
383
|
-
case 404: {
|
|
384
|
-
this.showSnackError(msgs.auth_interceptor.not_found, ['snack-error']);
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
case 409: {
|
|
388
|
-
this.messageAlertDialog(error, msgs);
|
|
389
|
-
break;
|
|
390
|
-
}
|
|
391
|
-
case 412: {
|
|
392
|
-
this.showSnackError(error.error.responseMessage, ['snack-error']);
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
case 422: {
|
|
396
|
-
this.messageAlertDialog(error, msgs);
|
|
397
|
-
break;
|
|
398
|
-
}
|
|
399
|
-
case 428: {
|
|
400
|
-
this.showSnackError(error.error.responseMessage, ['snack-error']);
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
case 500: {
|
|
404
|
-
this.messageAlertDialog(error, msgs);
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
case 503: {
|
|
408
|
-
this.showSnackError(msgs.auth_interceptor.unavailable, ['snack-error']);
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
case -1: {
|
|
412
|
-
this.showSnackError(msgs.auth_interceptor.connection_error);
|
|
413
|
-
break;
|
|
414
|
-
}
|
|
415
|
-
case 0: {
|
|
416
|
-
this.showSnackError(msgs.auth_interceptor.connection_error);
|
|
417
|
-
break;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
messageSnackError(error) {
|
|
422
|
-
const errorMessage = error.error && error.error.responseMessage ? error.error.responseMessage :
|
|
423
|
-
error.error.message ? error.error.message : error.message;
|
|
424
|
-
this.showSnackError(errorMessage, ['snack-error']);
|
|
425
|
-
}
|
|
426
|
-
goNavigateLogin(msgs) {
|
|
427
|
-
// if (this.router.url !== '/login') {
|
|
428
|
-
this.showSnackError(msgs.auth_interceptor.session_lost, ['snack-error']);
|
|
429
|
-
// this.router.navigate(['/login']);
|
|
430
|
-
this.auth.destroyCredentials();
|
|
431
|
-
this.auth.getLoginUrl().subscribe(res => {
|
|
432
|
-
console.log(res);
|
|
433
|
-
const loginUrl = res.data;
|
|
434
|
-
const url = window.location.href;
|
|
435
|
-
if (url.indexOf(loginUrl) < 0) {
|
|
436
|
-
window.location.href = loginUrl + '?continue=' + encodeURIComponent(url);
|
|
437
|
-
}
|
|
438
|
-
}, (err) => {
|
|
439
|
-
console.error(err);
|
|
440
|
-
});
|
|
441
|
-
// }
|
|
442
|
-
}
|
|
443
|
-
messageAlertDialog(error, msgs) {
|
|
444
|
-
console.log(error);
|
|
445
|
-
let message = '';
|
|
446
|
-
if (error.description) {
|
|
447
|
-
message = error.description;
|
|
448
|
-
if (error.exception) {
|
|
449
|
-
message = message + '\n\n' + msgs.auth_interceptor.code + ': ' + error.exception;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
else if (error.error.responseMessage) {
|
|
453
|
-
message = error.error.responseMessage;
|
|
454
|
-
if (error.error.exceptionId) {
|
|
455
|
-
message = message + '\n\n' + msgs.auth_interceptor.code + ': ' + error.error.exceptionId;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
else if (error.error.message) {
|
|
459
|
-
message = error.error.message;
|
|
460
|
-
if (error.error.exceptionId) {
|
|
461
|
-
message = message + '\n\n' + msgs.auth_interceptor.code + ': ' + error.error.exceptionId;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
else if (error.message) {
|
|
465
|
-
message = error.message;
|
|
466
|
-
if (error.error.exceptionId) {
|
|
467
|
-
message = message + '\n\n' + msgs.auth_interceptor.code + ': ' + error.error.exceptionId;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
message = msgs.auth_interceptor.message;
|
|
472
|
-
}
|
|
473
|
-
this.dialog.open(AlertComponent, {
|
|
474
|
-
disableClose: true,
|
|
475
|
-
data: { title: msgs.auth_interceptor.title, message }
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
showSnackError(message, panelClass = []) {
|
|
479
|
-
console.log(message);
|
|
480
|
-
setTimeout(() => {
|
|
481
|
-
this.snackBar.open(message, undefined, {
|
|
482
|
-
duration: 5000,
|
|
483
|
-
panelClass,
|
|
484
|
-
verticalPosition: 'top'
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
setInterceptorMessages(message) {
|
|
489
|
-
this.interceptorMessages = message;
|
|
490
|
-
}
|
|
491
|
-
// eslint-disable-next-line max-lines-per-function
|
|
492
|
-
getInterceptorMessages() {
|
|
493
|
-
if (!this.interceptorMessages) {
|
|
494
|
-
const lang = window.localStorage.getItem('LANG');
|
|
495
|
-
const messagesEn = {
|
|
496
|
-
auth_interceptor: {
|
|
497
|
-
session_lost: 'Session lost, you have to login again.',
|
|
498
|
-
not_found: 'Resource not found',
|
|
499
|
-
title: 'We are sorry!',
|
|
500
|
-
message: 'We had a problem trying to process your request.',
|
|
501
|
-
code: 'Code',
|
|
502
|
-
unavailable: 'Service unavailable, please try again in a few minutes.',
|
|
503
|
-
connection_error: 'Could not connect to server, please check your network connection.'
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
const messagesEs = {
|
|
507
|
-
auth_interceptor: {
|
|
508
|
-
session_lost: 'Su sesión expiró, debe iniciar sesión nuevamente.',
|
|
509
|
-
not_found: 'Recurso no encontrado',
|
|
510
|
-
title: '¡Lo sentimos!',
|
|
511
|
-
message: 'Tuvimos un problema al tratar de procesar su solicitud.',
|
|
512
|
-
code: 'Código',
|
|
513
|
-
unavailable: 'Servicio no disponible, inténtelo de nuevo en unos minutos.',
|
|
514
|
-
connection_error: 'No se pudo conectar al servidor, verifique su conexión de red.'
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
if (lang && lang === 'en') {
|
|
518
|
-
this.interceptorMessages = messagesEn;
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
this.interceptorMessages = messagesEs;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
return this.interceptorMessages;
|
|
525
|
-
}
|
|
526
|
-
registerLog(error, request) {
|
|
527
|
-
const u = this.auth.getUserdata();
|
|
528
|
-
const param = {
|
|
529
|
-
httpStatus: error.status,
|
|
530
|
-
httpStatusText: error.statusText,
|
|
531
|
-
errorMessage: error.message,
|
|
532
|
-
currentUrl: window.location.href,
|
|
533
|
-
requestUrl: request.urlWithParams ? request.urlWithParams : undefined,
|
|
534
|
-
requestBody: request.body ? JSON.stringify(request.body) : undefined,
|
|
535
|
-
userId: u ? u.userId : undefined,
|
|
536
|
-
applicationId: this.applicationId,
|
|
537
|
-
requestDate: new Date()
|
|
538
|
-
};
|
|
539
|
-
this.auth.registerException(param).subscribe({
|
|
540
|
-
next: (response) => {
|
|
541
|
-
console.log('registerException', response);
|
|
542
|
-
},
|
|
543
|
-
error: (err) => {
|
|
544
|
-
console.error('registerException', err);
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
MessagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: MessagesService, deps: [{ token: SessionService }, { token: i2$1.MatSnackBar }, { token: i1.MatDialog }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
550
|
-
MessagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: MessagesService });
|
|
551
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: MessagesService, decorators: [{
|
|
552
|
-
type: Injectable
|
|
553
|
-
}], ctorParameters: function () {
|
|
554
|
-
return [{ type: SessionService }, { type: i2$1.MatSnackBar }, { type: i1.MatDialog }, { type: undefined, decorators: [{
|
|
555
|
-
type: Inject,
|
|
556
|
-
args: ['environment']
|
|
557
|
-
}] }];
|
|
558
|
-
} });
|
|
559
|
-
|
|
560
|
-
class SsiSecurityCommonsModule {
|
|
561
|
-
static forRoot(environment) {
|
|
562
|
-
return {
|
|
563
|
-
ngModule: SsiSecurityCommonsModule,
|
|
564
|
-
providers: [{ provide: 'environment', useValue: environment }]
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
SsiSecurityCommonsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
569
|
-
SsiSecurityCommonsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsModule, declarations: [SsiSecurityCommonsComponent,
|
|
570
|
-
AlertComponent], imports: [MatSnackBarModule,
|
|
571
|
-
MatDialogModule,
|
|
572
|
-
MatButtonModule], exports: [SsiSecurityCommonsComponent] });
|
|
573
|
-
SsiSecurityCommonsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsModule, providers: [
|
|
574
|
-
MessagesService,
|
|
575
|
-
SessionService,
|
|
576
|
-
CryptoService
|
|
577
|
-
], imports: [[
|
|
578
|
-
MatSnackBarModule,
|
|
579
|
-
MatDialogModule,
|
|
580
|
-
MatButtonModule
|
|
581
|
-
]] });
|
|
582
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsModule, decorators: [{
|
|
583
|
-
type: NgModule,
|
|
584
|
-
args: [{
|
|
585
|
-
declarations: [
|
|
586
|
-
SsiSecurityCommonsComponent,
|
|
587
|
-
AlertComponent
|
|
588
|
-
],
|
|
589
|
-
imports: [
|
|
590
|
-
MatSnackBarModule,
|
|
591
|
-
MatDialogModule,
|
|
592
|
-
MatButtonModule
|
|
593
|
-
],
|
|
594
|
-
exports: [
|
|
595
|
-
SsiSecurityCommonsComponent
|
|
596
|
-
],
|
|
597
|
-
providers: [
|
|
598
|
-
MessagesService,
|
|
599
|
-
SessionService,
|
|
600
|
-
CryptoService
|
|
601
|
-
]
|
|
602
|
-
}]
|
|
603
|
-
}] });
|
|
604
|
-
|
|
605
|
-
/* eslint-disable */
|
|
606
|
-
class AuthInterceptor {
|
|
607
|
-
constructor(cryptoService) {
|
|
608
|
-
this.cryptoService = cryptoService;
|
|
609
|
-
console.log('AuthInterceptor constructor');
|
|
610
|
-
}
|
|
611
|
-
intercept(request, next) {
|
|
612
|
-
//console.log('intercept');
|
|
613
|
-
const token = window.localStorage.getItem('TOKEN');
|
|
614
|
-
//console.log(token);
|
|
615
|
-
//console.log(request);
|
|
616
|
-
let encrypt = request.headers.get('encrypted');
|
|
617
|
-
if (encrypt && encrypt === 'true') {
|
|
618
|
-
let body = request.body;
|
|
619
|
-
let bodyStr = JSON.stringify(body);
|
|
620
|
-
var newBody = {
|
|
621
|
-
encrypted: this.cryptoService.encrypt(bodyStr)
|
|
622
|
-
};
|
|
623
|
-
request = request.clone({
|
|
624
|
-
body: newBody
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
if (token) {
|
|
628
|
-
request = request.clone({
|
|
629
|
-
setHeaders: {
|
|
630
|
-
Authorization: 'Bearer ' + token,
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
return next.handle(request);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
AuthInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AuthInterceptor, deps: [{ token: CryptoService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
638
|
-
AuthInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AuthInterceptor });
|
|
639
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AuthInterceptor, decorators: [{
|
|
640
|
-
type: Injectable
|
|
641
|
-
}], ctorParameters: function () { return [{ type: CryptoService }]; } });
|
|
642
|
-
class ResponseInterceptor {
|
|
643
|
-
constructor(injector, router, cryptoService, sessionService) {
|
|
644
|
-
this.injector = injector;
|
|
645
|
-
this.router = router;
|
|
646
|
-
this.cryptoService = cryptoService;
|
|
647
|
-
this.sessionService = sessionService;
|
|
648
|
-
this.isRefreshing = false;
|
|
649
|
-
this.refreshTokenSubject = new BehaviorSubject(null);
|
|
650
|
-
//console.log('ResponseInterceptor constructor');
|
|
651
|
-
setTimeout(() => {
|
|
652
|
-
this.messages = this.injector.get(MessagesService);
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
intercept(request, next) {
|
|
656
|
-
return next.handle(request).pipe(map((event) => {
|
|
657
|
-
if (event instanceof HttpResponse) {
|
|
658
|
-
//console.log(request.headers.get('encrypted'));
|
|
659
|
-
let encrypt = request.headers.get('encrypted');
|
|
660
|
-
if (encrypt && encrypt === 'true' && event.body.encrypted) {
|
|
661
|
-
event = event.clone({ body: this.decryptBody(event.body) });
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
return event;
|
|
665
|
-
}), catchError(error => {
|
|
666
|
-
var _a;
|
|
667
|
-
if (error instanceof HttpErrorResponse) {
|
|
668
|
-
console.error(error);
|
|
669
|
-
let nerror = error;
|
|
670
|
-
/*let encrypt = request.headers.get('encrypted');
|
|
671
|
-
if(encrypt && encrypt === 'true'){
|
|
672
|
-
nerror = new HttpErrorResponse({
|
|
673
|
-
error: this.decryptBody(error.error),
|
|
674
|
-
headers: error.headers,
|
|
675
|
-
status: error.status,
|
|
676
|
-
statusText: error.statusText,
|
|
677
|
-
url: error.url || request.urlWithParams || undefined,
|
|
678
|
-
});
|
|
679
|
-
}*/
|
|
680
|
-
if (nerror.status === 401) {
|
|
681
|
-
console.log(this.router.url);
|
|
682
|
-
if (this.router.url != '/login' && this.router.url.indexOf('/login') < 0) {
|
|
683
|
-
console.log('401--->' + request.url);
|
|
684
|
-
return this.handle401Error(request, next);
|
|
685
|
-
}
|
|
686
|
-
else {
|
|
687
|
-
return throwError(nerror);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
else {
|
|
691
|
-
let skipError = request.headers.get('skipError');
|
|
692
|
-
if (skipError && skipError === 'true') {
|
|
693
|
-
return throwError(nerror);
|
|
694
|
-
}
|
|
695
|
-
else {
|
|
696
|
-
(_a = this.messages) === null || _a === void 0 ? void 0 : _a.showErrorMessage(nerror, request);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}));
|
|
701
|
-
}
|
|
702
|
-
decryptBody(body) {
|
|
703
|
-
let encrypted = body.encrypted;
|
|
704
|
-
let strJson = this.cryptoService.decrypt(encrypted);
|
|
705
|
-
return JSON.parse(strJson);
|
|
706
|
-
}
|
|
707
|
-
handle401Error(request, next) {
|
|
708
|
-
//console.log('handle401Error');
|
|
709
|
-
//console.log(this.isRefreshing);
|
|
710
|
-
if (!this.isRefreshing) {
|
|
711
|
-
this.isRefreshing = true;
|
|
712
|
-
this.refreshTokenSubject.next(null);
|
|
713
|
-
const refreshToken = this.sessionService.getRefreshToken();
|
|
714
|
-
//console.log(refreshToken);
|
|
715
|
-
if (refreshToken) {
|
|
716
|
-
return this.sessionService.getNewToken(refreshToken).pipe(switchMap((res) => {
|
|
717
|
-
console.log('refresh token response');
|
|
718
|
-
console.log(res);
|
|
719
|
-
this.isRefreshing = false;
|
|
720
|
-
this.sessionService.setToken(res.data.accessToken);
|
|
721
|
-
this.sessionService.setRefreshToken(res.data.refreshToken);
|
|
722
|
-
this.refreshTokenSubject.next(res.data.accessToken);
|
|
723
|
-
return next.handle(this.addTokenHeader(request, res.data.accessToken));
|
|
724
|
-
}), catchError((err) => {
|
|
725
|
-
this.isRefreshing = false;
|
|
726
|
-
this.sessionService.logout();
|
|
727
|
-
//this.router.navigate(['/login']);
|
|
728
|
-
this.goToLogin();
|
|
729
|
-
return throwError(err);
|
|
730
|
-
}));
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
else {
|
|
734
|
-
return this.refreshTokenSubject.pipe(filter(token => token !== null), take(1), switchMap((token) => next.handle(this.addTokenHeader(request, token))));
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
addTokenHeader(request, token) {
|
|
738
|
-
return request.clone({ headers: request.headers.set('Authorization', 'Bearer ' + token) });
|
|
739
|
-
}
|
|
740
|
-
goToLogin() {
|
|
741
|
-
this.sessionService.getLoginUrl().subscribe(res => {
|
|
742
|
-
console.log(res);
|
|
743
|
-
const loginUrl = res.data;
|
|
744
|
-
const url = window.location.href;
|
|
745
|
-
if (url.indexOf(loginUrl) < 0) {
|
|
746
|
-
window.location.href = loginUrl + '?continue=' + encodeURIComponent(url);
|
|
747
|
-
}
|
|
748
|
-
}, (err) => {
|
|
749
|
-
console.error(err);
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
ResponseInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ResponseInterceptor, deps: [{ token: i0.Injector }, { token: i2$2.Router }, { token: CryptoService }, { token: SessionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
754
|
-
ResponseInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ResponseInterceptor });
|
|
755
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ResponseInterceptor, decorators: [{
|
|
756
|
-
type: Injectable
|
|
757
|
-
}], ctorParameters: function () { return [{ type: i0.Injector }, { type: i2$2.Router }, { type: CryptoService }, { type: SessionService }]; } });
|
|
758
|
-
|
|
759
|
-
/*
|
|
760
|
-
* Public API Surface of ssi-security-commons
|
|
761
|
-
*/
|
|
762
|
-
|
|
763
|
-
/**
|
|
764
|
-
* Generated bundle index. Do not edit.
|
|
765
|
-
*/
|
|
766
|
-
|
|
767
|
-
export { AuthInterceptor, CryptoService, MessagesService, ResponseInterceptor, SessionService, SsiSecurityCommonsComponent, SsiSecurityCommonsModule, SsiSecurityCommonsService };
|
|
768
|
-
//# sourceMappingURL=ssi-security-commons.mjs.map
|