@esfaenza/access-control 15.2.13 → 16.0.2

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.
Files changed (28) hide show
  1. package/{esm2020 → esm2022}/esfaenza-access-control.mjs +4 -4
  2. package/{esm2020 → esm2022}/lib/AccessControlRouteGuard.mjs +102 -102
  3. package/{esm2020 → esm2022}/lib/access-control.directive.mjs +52 -52
  4. package/{esm2020 → esm2022}/lib/access-control.module.mjs +30 -30
  5. package/{esm2020 → esm2022}/lib/access-control.pipe.mjs +31 -31
  6. package/{esm2020 → esm2022}/lib/access-control.service.mjs +197 -197
  7. package/{esm2020 → esm2022}/lib/context-aware.directive.mjs +42 -42
  8. package/{esm2020 → esm2022}/lib/models/AccessControlModuleConfig.mjs +5 -5
  9. package/{esm2020 → esm2022}/lib/models/ComponentContext.mjs +13 -13
  10. package/{esm2020 → esm2022}/lib/tokens.mjs +9 -9
  11. package/{esm2020 → esm2022}/public-api.mjs +12 -12
  12. package/{fesm2020 → fesm2022}/esfaenza-access-control.mjs +445 -445
  13. package/fesm2022/esfaenza-access-control.mjs.map +1 -0
  14. package/index.d.ts +5 -5
  15. package/lib/AccessControlRouteGuard.d.ts +60 -60
  16. package/lib/access-control.directive.d.ts +32 -32
  17. package/lib/access-control.module.d.ts +12 -12
  18. package/lib/access-control.pipe.d.ts +22 -22
  19. package/lib/access-control.service.d.ts +84 -84
  20. package/lib/context-aware.directive.d.ts +22 -22
  21. package/lib/models/AccessControlModuleConfig.d.ts +13 -13
  22. package/lib/models/ComponentContext.d.ts +12 -12
  23. package/lib/tokens.d.ts +9 -9
  24. package/package.json +8 -14
  25. package/public-api.d.ts +9 -9
  26. package/fesm2015/esfaenza-access-control.mjs +0 -478
  27. package/fesm2015/esfaenza-access-control.mjs.map +0 -1
  28. package/fesm2020/esfaenza-access-control.mjs.map +0 -1
@@ -2,471 +2,471 @@ import * as i0 from '@angular/core';
2
2
  import { InjectionToken, Injectable, Optional, Inject, Directive, Input, Pipe, NgModule } from '@angular/core';
3
3
  import * as i1 from '@esfaenza/extensions';
4
4
 
5
- /** Token che racchiude la chiave custom da controllare quando si effettuano controlli sul ComponentContext */
6
- const ACC_CUSTOMKEY = new InjectionToken('ACC_CUSTOMKEY');
7
- /** Token che indica la condizione di default da aggiungere ai check utente */
8
- const ACC_DEF_COND = new InjectionToken('ACC_DEF_COND');
9
- /** Token che indica l'operatore della condizione di default da aggiungere ai check utente */
10
- const ACC_DEF_COND_OP = new InjectionToken('ACC_DEF_COND_OP');
11
- /** Modalità di Debug */
5
+ /** Token che racchiude la chiave custom da controllare quando si effettuano controlli sul ComponentContext */
6
+ const ACC_CUSTOMKEY = new InjectionToken('ACC_CUSTOMKEY');
7
+ /** Token che indica la condizione di default da aggiungere ai check utente */
8
+ const ACC_DEF_COND = new InjectionToken('ACC_DEF_COND');
9
+ /** Token che indica l'operatore della condizione di default da aggiungere ai check utente */
10
+ const ACC_DEF_COND_OP = new InjectionToken('ACC_DEF_COND_OP');
11
+ /** Modalità di Debug */
12
12
  const ACC_DEBUG_MODE = new InjectionToken('ACC_DEBUG_MODE');
13
13
 
14
- // Angular
15
- /**
16
- * Entrypoint di tutte le operazioni esposte dalla libreria access-control
17
- */
18
- class AccessControlService {
19
- /** @ignore */
20
- constructor(ACC_DEF_COND, ACC_DEF_COND_OP, emb) {
21
- this.ACC_DEF_COND = ACC_DEF_COND;
22
- this.ACC_DEF_COND_OP = ACC_DEF_COND_OP;
23
- this.emb = emb;
24
- /**
25
- * Indica se l'Identity è stata inizializzata
26
- */
27
- this.Initialized = false;
28
- /**
29
- * Indica se sono state effettuate inizializzazioni di Custom Permissions
30
- */
31
- this.InitializedCustom = false;
32
- /** @ignore */
33
- this.cache = {};
34
- /** @ignore */
35
- this.taggedItemsCache = [];
36
- }
37
- /**
38
- * Inizializza l'Identity del servizio con il modello specificato
39
- *
40
- * @params {{ Roles: string[], Permissions: string[] }} identity Identità applicativa con ruoli e permessi
41
- */
42
- initializeIdentity(identity) {
43
- this.Identity = identity;
44
- this.Initialized = true;
45
- }
46
- /**
47
- * Inizializza i permessi Custom del servizio con il modello specificato
48
- *
49
- * @param {{ key: string, items: string[] }[]} customPermissions Permessi Custom
50
- */
51
- initializeCustomPermissions(customPermissions) {
52
- for (let i = 0; i < customPermissions.length; i++) {
53
- if (customPermissions[i].key.length > 1) {
54
- console.error("[@esfaenza/access-control] Custom permission initialized with keys longer than a single characters. Ignoring EVERYTHING.");
55
- return;
56
- }
57
- }
58
- // Custom permission sull'embedding aggiunta automaticamente se non presente
59
- if (!customPermissions.find(t => t.key === "X"))
60
- customPermissions.push({ key: "X", items: [this.emb.Embedded ? "1" : "0"] });
61
- this.taggedItemsCache = customPermissions;
62
- this.InitializedCustom = true;
63
- }
64
- /**
65
- * Indica se nella sessione attuale esiste un utente loggato. Fa un semplice controllo di presenza sull'Identity
66
- */
67
- isLoggedIn() {
68
- return !!this.Identity;
69
- }
70
- /**
71
- * Expression è scritta tipo --> R:Role1 && P:Permission1 || (R:Role2 && P:Permission1)
72
- * Quindi piuttosto che implementarsi un parser della madonna in stile Alessandro prendo la strada stronza e veloce con l'eval :P
73
- *
74
- * @ignore
75
- */
76
- hasACExpression(expression, absolute = false) {
77
- if (!this.Initialized)
78
- console.error("Access Control System has not been initialized. Call this.accessControl.initialize(..., ...) before using the service");
79
- if (!expression)
80
- return true;
81
- if (!this.Identity) {
82
- console.warn("Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default");
83
- return true;
84
- }
85
- // Espressione già valutata, non serve rivalutarla
86
- if (this.cache[expression])
87
- return this.cache[expression];
88
- var RolesPermissionsRegexp = /!?.:[^|&()]+/g;
89
- var matches = expression.match(RolesPermissionsRegexp);
90
- if (!matches)
91
- throw "Espressione Access Control non valida: " + expression + ". Assicurarsi che sia scritta in modo corretto";
92
- // Per condizioni dirette sull'embedding si considera sempre che siano operazioni assolute
93
- if (expression == 'X:0' || expression == 'X:1')
94
- absolute = true;
95
- matches.forEach(t => {
96
- var splits = t.split(':');
97
- // Per ruoli e permessi, se ho condizioni di default e l'espressione non è assoluta, wrappo ogni elemento con le espressioni di default
98
- // Per le custom permissions invece, dato che sono cose staccate da ruoli e permessi, non ha mai senso farlo
99
- if (splits[0] == "R" || splits[0] == "!R") {
100
- if (this.ACC_DEF_COND && this.ACC_DEF_COND_OP && !absolute) {
101
- let tmpReplace = `(${t} ${this.ACC_DEF_COND_OP} ${this.ACC_DEF_COND})`;
102
- var matches2 = tmpReplace.match(RolesPermissionsRegexp);
103
- matches2.forEach(t2 => {
104
- var splits2 = t2.split(':');
105
- if (splits2[0] == "R" || splits2[0] == "!R")
106
- tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasRole('" + splits2[1].trim() + "')");
107
- else if (splits2[0] == "P" || splits2[0] == "!P")
108
- tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasPermission('" + splits2[1].trim() + "')");
109
- else
110
- tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasCustom('" + splits2[1].trim() + "')");
111
- });
112
- expression = expression.replace(t.trim(), tmpReplace);
113
- }
114
- else
115
- expression = expression.replace(t.trim(), (t.startsWith("!") ? '!' : '') + "this.hasRole('" + splits[1].trim() + "')");
116
- }
117
- else if (splits[0] == "P" || splits[0] == "!P") {
118
- if (this.ACC_DEF_COND && this.ACC_DEF_COND_OP && !absolute) {
119
- let tmpReplace = `(${t} ${this.ACC_DEF_COND_OP} ${this.ACC_DEF_COND})`;
120
- var matches2 = tmpReplace.match(RolesPermissionsRegexp);
121
- matches2.forEach(t2 => {
122
- var splits2 = t2.split(':');
123
- if (splits2[0] == "R" || splits2[0] == "!R")
124
- tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasRole('" + splits2[1].trim() + "')");
125
- else if (splits2[0] == "P" || splits2[0] == "!P")
126
- tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasPermission('" + splits2[1].trim() + "')");
127
- else
128
- tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasCustom('" + splits2[1].trim() + "')");
129
- });
130
- expression = expression.replace(t.trim(), tmpReplace);
131
- }
132
- else
133
- expression = expression.replace(t.trim(), (t.startsWith("!") ? '!' : '') + "this.hasPermission('" + splits[1].trim() + "')");
134
- }
135
- else
136
- expression = expression.replace(t.trim(), (t.startsWith("!") ? '!' : '') + "this.hasCustom('" + splits[1].trim() + "', '" + ((t.startsWith("!") ? splits[0].trim().charAt(1) : splits[0].trim())) + "')");
137
- });
138
- var ret = eval(expression);
139
- // Cache valore
140
- this.cache[expression] = ret;
141
- return ret;
142
- }
143
- /**
144
- * Utilizzato da hasACExpression dentro eval
145
- *
146
- * @ignore
147
- */
148
- hasRole(role) {
149
- if (!this.Identity) {
150
- console.warn("Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default");
151
- return true;
152
- }
153
- return this.Identity.Roles && this.Identity.Roles.length > 0 && this.Identity.Roles.indexOf(role) != -1;
154
- }
155
- /**
156
- * Utilizzato da hasACExpression dentro eval
157
- *
158
- * @ignore
159
- */
160
- hasPermission(permission) {
161
- if (!this.Identity) {
162
- console.warn("Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default");
163
- return true;
164
- }
165
- return this.Identity.Permissions && this.Identity.Permissions.length > 0 && this.Identity.Permissions.indexOf(permission) != -1;
166
- }
167
- /**
168
- * Utilizzato da hasACExpression dentro eval
169
- *
170
- * @ignore
171
- */
172
- hasCustom(value, tag) {
173
- var items = this.taggedItemsCache.find(t => t.key == tag)?.items;
174
- if (!items)
175
- return true;
176
- else if (items.length == 0)
177
- return false;
178
- else {
179
- var found = items.find(t => t == value);
180
- return found != null && found != undefined;
181
- }
182
- }
183
- /**
184
- * Entry point che controlla un'espressione identificante un permesso, ad esempio "P:visualizzazione" controlla che l'utente collegato abbia un permesso che si chiama "visualizzazione"
185
- */
186
- has(expr, absolute = false) {
187
- return this.hasACExpression(expr, absolute);
188
- }
189
- }
190
- AccessControlServicefac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlService, deps: [{ token: ACC_DEF_COND, optional: true }, { token: ACC_DEF_COND_OP, optional: true }, { token: i1.AppEmbeddingExtensions }], target: i0.ɵɵFactoryTarget.Injectable });
191
- AccessControlService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlService, providedIn: "root" });
192
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlService, decorators: [{
193
- type: Injectable,
194
- args: [{ providedIn: "root" }]
195
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
196
- type: Optional
197
- }, {
198
- type: Inject,
199
- args: [ACC_DEF_COND]
200
- }] }, { type: undefined, decorators: [{
201
- type: Optional
202
- }, {
203
- type: Inject,
204
- args: [ACC_DEF_COND_OP]
14
+ // Angular
15
+ /**
16
+ * Entrypoint di tutte le operazioni esposte dalla libreria access-control
17
+ */
18
+ class AccessControlService {
19
+ /** @ignore */
20
+ constructor(ACC_DEF_COND, ACC_DEF_COND_OP, emb) {
21
+ this.ACC_DEF_COND = ACC_DEF_COND;
22
+ this.ACC_DEF_COND_OP = ACC_DEF_COND_OP;
23
+ this.emb = emb;
24
+ /**
25
+ * Indica se l'Identity è stata inizializzata
26
+ */
27
+ this.Initialized = false;
28
+ /**
29
+ * Indica se sono state effettuate inizializzazioni di Custom Permissions
30
+ */
31
+ this.InitializedCustom = false;
32
+ /** @ignore */
33
+ this.cache = {};
34
+ /** @ignore */
35
+ this.taggedItemsCache = [];
36
+ }
37
+ /**
38
+ * Inizializza l'Identity del servizio con il modello specificato
39
+ *
40
+ * @params {{ Roles: string[], Permissions: string[] }} identity Identità applicativa con ruoli e permessi
41
+ */
42
+ initializeIdentity(identity) {
43
+ this.Identity = identity;
44
+ this.Initialized = true;
45
+ }
46
+ /**
47
+ * Inizializza i permessi Custom del servizio con il modello specificato
48
+ *
49
+ * @param {{ key: string, items: string[] }[]} customPermissions Permessi Custom
50
+ */
51
+ initializeCustomPermissions(customPermissions) {
52
+ for (let i = 0; i < customPermissions.length; i++) {
53
+ if (customPermissions[i].key.length > 1) {
54
+ console.error("[@esfaenza/access-control] Custom permission initialized with keys longer than a single characters. Ignoring EVERYTHING.");
55
+ return;
56
+ }
57
+ }
58
+ // Custom permission sull'embedding aggiunta automaticamente se non presente
59
+ if (!customPermissions.find(t => t.key === "X"))
60
+ customPermissions.push({ key: "X", items: [this.emb.Embedded ? "1" : "0"] });
61
+ this.taggedItemsCache = customPermissions;
62
+ this.InitializedCustom = true;
63
+ }
64
+ /**
65
+ * Indica se nella sessione attuale esiste un utente loggato. Fa un semplice controllo di presenza sull'Identity
66
+ */
67
+ isLoggedIn() {
68
+ return !!this.Identity;
69
+ }
70
+ /**
71
+ * Expression è scritta tipo --> R:Role1 && P:Permission1 || (R:Role2 && P:Permission1)
72
+ * Quindi piuttosto che implementarsi un parser della madonna in stile Alessandro prendo la strada stronza e veloce con l'eval :P
73
+ *
74
+ * @ignore
75
+ */
76
+ hasACExpression(expression, absolute = false) {
77
+ if (!this.Initialized)
78
+ console.error("Access Control System has not been initialized. Call this.accessControl.initialize(..., ...) before using the service");
79
+ if (!expression)
80
+ return true;
81
+ if (!this.Identity) {
82
+ console.warn("Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default");
83
+ return true;
84
+ }
85
+ // Espressione già valutata, non serve rivalutarla
86
+ if (this.cache[expression])
87
+ return this.cache[expression];
88
+ var RolesPermissionsRegexp = /!?.:[^|&()]+/g;
89
+ var matches = expression.match(RolesPermissionsRegexp);
90
+ if (!matches)
91
+ throw "Espressione Access Control non valida: " + expression + ". Assicurarsi che sia scritta in modo corretto";
92
+ // Per condizioni dirette sull'embedding si considera sempre che siano operazioni assolute
93
+ if (expression == 'X:0' || expression == 'X:1')
94
+ absolute = true;
95
+ matches.forEach(t => {
96
+ var splits = t.split(':');
97
+ // Per ruoli e permessi, se ho condizioni di default e l'espressione non è assoluta, wrappo ogni elemento con le espressioni di default
98
+ // Per le custom permissions invece, dato che sono cose staccate da ruoli e permessi, non ha mai senso farlo
99
+ if (splits[0] == "R" || splits[0] == "!R") {
100
+ if (this.ACC_DEF_COND && this.ACC_DEF_COND_OP && !absolute) {
101
+ let tmpReplace = `(${t} ${this.ACC_DEF_COND_OP} ${this.ACC_DEF_COND})`;
102
+ var matches2 = tmpReplace.match(RolesPermissionsRegexp);
103
+ matches2.forEach(t2 => {
104
+ var splits2 = t2.split(':');
105
+ if (splits2[0] == "R" || splits2[0] == "!R")
106
+ tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasRole('" + splits2[1].trim() + "')");
107
+ else if (splits2[0] == "P" || splits2[0] == "!P")
108
+ tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasPermission('" + splits2[1].trim() + "')");
109
+ else
110
+ tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasCustom('" + splits2[1].trim() + "')");
111
+ });
112
+ expression = expression.replace(t.trim(), tmpReplace);
113
+ }
114
+ else
115
+ expression = expression.replace(t.trim(), (t.startsWith("!") ? '!' : '') + "this.hasRole('" + splits[1].trim() + "')");
116
+ }
117
+ else if (splits[0] == "P" || splits[0] == "!P") {
118
+ if (this.ACC_DEF_COND && this.ACC_DEF_COND_OP && !absolute) {
119
+ let tmpReplace = `(${t} ${this.ACC_DEF_COND_OP} ${this.ACC_DEF_COND})`;
120
+ var matches2 = tmpReplace.match(RolesPermissionsRegexp);
121
+ matches2.forEach(t2 => {
122
+ var splits2 = t2.split(':');
123
+ if (splits2[0] == "R" || splits2[0] == "!R")
124
+ tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasRole('" + splits2[1].trim() + "')");
125
+ else if (splits2[0] == "P" || splits2[0] == "!P")
126
+ tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasPermission('" + splits2[1].trim() + "')");
127
+ else
128
+ tmpReplace = tmpReplace.replace(t2.trim(), (t2.startsWith("!") ? '!' : '') + "this.hasCustom('" + splits2[1].trim() + "')");
129
+ });
130
+ expression = expression.replace(t.trim(), tmpReplace);
131
+ }
132
+ else
133
+ expression = expression.replace(t.trim(), (t.startsWith("!") ? '!' : '') + "this.hasPermission('" + splits[1].trim() + "')");
134
+ }
135
+ else
136
+ expression = expression.replace(t.trim(), (t.startsWith("!") ? '!' : '') + "this.hasCustom('" + splits[1].trim() + "', '" + ((t.startsWith("!") ? splits[0].trim().charAt(1) : splits[0].trim())) + "')");
137
+ });
138
+ var ret = eval(expression);
139
+ // Cache valore
140
+ this.cache[expression] = ret;
141
+ return ret;
142
+ }
143
+ /**
144
+ * Utilizzato da hasACExpression dentro eval
145
+ *
146
+ * @ignore
147
+ */
148
+ hasRole(role) {
149
+ if (!this.Identity) {
150
+ console.warn("Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default");
151
+ return true;
152
+ }
153
+ return this.Identity.Roles && this.Identity.Roles.length > 0 && this.Identity.Roles.indexOf(role) != -1;
154
+ }
155
+ /**
156
+ * Utilizzato da hasACExpression dentro eval
157
+ *
158
+ * @ignore
159
+ */
160
+ hasPermission(permission) {
161
+ if (!this.Identity) {
162
+ console.warn("Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default");
163
+ return true;
164
+ }
165
+ return this.Identity.Permissions && this.Identity.Permissions.length > 0 && this.Identity.Permissions.indexOf(permission) != -1;
166
+ }
167
+ /**
168
+ * Utilizzato da hasACExpression dentro eval
169
+ *
170
+ * @ignore
171
+ */
172
+ hasCustom(value, tag) {
173
+ var items = this.taggedItemsCache.find(t => t.key == tag)?.items;
174
+ if (!items)
175
+ return true;
176
+ else if (items.length == 0)
177
+ return false;
178
+ else {
179
+ var found = items.find(t => t == value);
180
+ return found != null && found != undefined;
181
+ }
182
+ }
183
+ /**
184
+ * Entry point che controlla un'espressione identificante un permesso, ad esempio "P:visualizzazione" controlla che l'utente collegato abbia un permesso che si chiama "visualizzazione"
185
+ */
186
+ has(expr, absolute = false) {
187
+ return this.hasACExpression(expr, absolute);
188
+ }
189
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlService, deps: [{ token: ACC_DEF_COND, optional: true }, { token: ACC_DEF_COND_OP, optional: true }, { token: i1.AppEmbeddingExtensions }], target: i0.ɵɵFactoryTarget.Injectable }); }
190
+ static { thisprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlService, providedIn: "root" }); }
191
+ }
192
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlService, decorators: [{
193
+ type: Injectable,
194
+ args: [{ providedIn: "root" }]
195
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
196
+ type: Optional
197
+ }, {
198
+ type: Inject,
199
+ args: [ACC_DEF_COND]
200
+ }] }, { type: undefined, decorators: [{
201
+ type: Optional
202
+ }, {
203
+ type: Inject,
204
+ args: [ACC_DEF_COND_OP]
205
205
  }] }, { type: i1.AppEmbeddingExtensions }]; } });
206
206
 
207
- // Angular
208
- /**
209
- * Direttiva che permette di gestire il controllo accessi su componenti HTML.
210
- *
211
- * Per gli esempi di utilizzo fare riferimento al README.
212
- */
213
- class AccessControlDirective {
214
- /**
215
- * Costruttore
216
- *
217
- * @ignore
218
- */
219
- constructor(templateRef, viewContainer, _ac) {
220
- this.templateRef = templateRef;
221
- this.viewContainer = viewContainer;
222
- this._ac = _ac;
223
- /**
224
- * Espressione da processare scritta come {Chiave}:{Valore}
225
- *
226
- * Le {Chiave} disponibili sono di default "R" per i ruoli e "P" per i permessi. È possibile espanderle con le Custom Permissions.
227
- *
228
- * Nelle ultime versioni del template è anche presente di default la custom permission "X" che indica se l'applicaizone è Esterna o no
229
- */
230
- this.ac = null;
231
- /** Indica che l'esporessione **ac** è assoluta, cioè che non può essere modificata internamente ad esempio per aggiungere condizioni di default */
232
- this.acAbsolute = false;
233
- }
234
- ngOnInit() {
235
- var allow = this._ac.has(this.ac, this.acAbsolute);
236
- //Se ho i permessi, proseguo creando la vista nel DOM, altrimenti rimuovo il template
237
- if (allow)
238
- this.viewContainer.createEmbeddedView(this.templateRef);
239
- else
240
- this.viewContainer.clear();
241
- }
242
- }
243
- AccessControlDirectivefac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: AccessControlService }], target: i0.ɵɵFactoryTarget.Directive });
244
- AccessControlDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: AccessControlDirective, selector: "[ac]", inputs: { ac: "ac", acAbsolute: "acAbsolute" }, ngImport: i0 });
245
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlDirective, decorators: [{
246
- type: Directive,
247
- args: [{
248
- selector: '[ac]',
249
- }]
250
- }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: AccessControlService }]; }, propDecorators: { ac: [{
251
- type: Input
252
- }], acAbsolute: [{
253
- type: Input
207
+ // Angular
208
+ /**
209
+ * Direttiva che permette di gestire il controllo accessi su componenti HTML.
210
+ *
211
+ * Per gli esempi di utilizzo fare riferimento al README.
212
+ */
213
+ class AccessControlDirective {
214
+ /**
215
+ * Costruttore
216
+ *
217
+ * @ignore
218
+ */
219
+ constructor(templateRef, viewContainer, _ac) {
220
+ this.templateRef = templateRef;
221
+ this.viewContainer = viewContainer;
222
+ this._ac = _ac;
223
+ /**
224
+ * Espressione da processare scritta come {Chiave}:{Valore}
225
+ *
226
+ * Le {Chiave} disponibili sono di default "R" per i ruoli e "P" per i permessi. È possibile espanderle con le Custom Permissions.
227
+ *
228
+ * Nelle ultime versioni del template è anche presente di default la custom permission "X" che indica se l'applicaizone è Esterna o no
229
+ */
230
+ this.ac = null;
231
+ /** Indica che l'esporessione **ac** è assoluta, cioè che non può essere modificata internamente ad esempio per aggiungere condizioni di default */
232
+ this.acAbsolute = false;
233
+ }
234
+ ngOnInit() {
235
+ var allow = this._ac.has(this.ac, this.acAbsolute);
236
+ //Se ho i permessi, proseguo creando la vista nel DOM, altrimenti rimuovo il template
237
+ if (allow)
238
+ this.viewContainer.createEmbeddedView(this.templateRef);
239
+ else
240
+ this.viewContainer.clear();
241
+ }
242
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: AccessControlService }], target: i0.ɵɵFactoryTarget.Directive }); }
243
+ static { thisdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: AccessControlDirective, selector: "[ac]", inputs: { ac: "ac", acAbsolute: "acAbsolute" }, ngImport: i0 }); }
244
+ }
245
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlDirective, decorators: [{
246
+ type: Directive,
247
+ args: [{
248
+ selector: '[ac]',
249
+ }]
250
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: AccessControlService }]; }, propDecorators: { ac: [{
251
+ type: Input
252
+ }], acAbsolute: [{
253
+ type: Input
254
254
  }] } });
255
255
 
256
- /**
257
- * Token da iniettare per ogni singolo componente per cui si vuole disattivare/attivare massivamente degli input in maniera contestuale
258
- */
259
- class ComponentContext {
260
- }
261
- ComponentContextfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ComponentContext, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
262
- ComponentContext.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ComponentContext });
263
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ComponentContext, decorators: [{
264
- type: Injectable
256
+ /**
257
+ * Token da iniettare per ogni singolo componente per cui si vuole disattivare/attivare massivamente degli input in maniera contestuale
258
+ */
259
+ class ComponentContext {
260
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ComponentContext, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
261
+ static { thisprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ComponentContext }); }
262
+ }
263
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ComponentContext, decorators: [{
264
+ type: Injectable
265
265
  }] });
266
266
 
267
- // Angular
268
- /**
269
- * Direttiva che permette di capire se l'elemento HTML su cui è utilizzata dev'essere disabilitato o no.
270
- *
271
- * Non ha effetto sugli elementi dichiarati in componenti che non dichiarano alcun ComponentContext
272
- */
273
- class ContextAwareDirective {
274
- /**
275
- * Costruttore
276
- *
277
- * @ignore
278
- */
279
- constructor(element, context, ac, ACC_CUSTOMKEY) {
280
- this.context = context;
281
- this.ac = ac;
282
- this.ACC_CUSTOMKEY = ACC_CUSTOMKEY;
283
- var allow = !this.context || !this.context.name || !this.ACC_CUSTOMKEY || this.ac.has(this.ACC_CUSTOMKEY + ":" + this.context.name);
284
- if (!allow)
285
- element.nativeElement.setAttribute("enabled", "true");
286
- }
287
- }
288
- ContextAwareDirectivefac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextAwareDirective, deps: [{ token: i0.ElementRef }, { token: ComponentContext, optional: true }, { token: AccessControlService }, { token: ACC_CUSTOMKEY, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
289
- ContextAwareDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: ContextAwareDirective, selector: "[contextAware]", ngImport: i0 });
290
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ContextAwareDirective, decorators: [{
291
- type: Directive,
292
- args: [{
293
- selector: '[contextAware]',
294
- }]
295
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ComponentContext, decorators: [{
296
- type: Optional
297
- }] }, { type: AccessControlService }, { type: undefined, decorators: [{
298
- type: Optional
299
- }, {
300
- type: Inject,
301
- args: [ACC_CUSTOMKEY]
267
+ // Angular
268
+ /**
269
+ * Direttiva che permette di capire se l'elemento HTML su cui è utilizzata dev'essere disabilitato o no.
270
+ *
271
+ * Non ha effetto sugli elementi dichiarati in componenti che non dichiarano alcun ComponentContext
272
+ */
273
+ class ContextAwareDirective {
274
+ /**
275
+ * Costruttore
276
+ *
277
+ * @ignore
278
+ */
279
+ constructor(element, context, ac, ACC_CUSTOMKEY) {
280
+ this.context = context;
281
+ this.ac = ac;
282
+ this.ACC_CUSTOMKEY = ACC_CUSTOMKEY;
283
+ var allow = !this.context || !this.context.name || !this.ACC_CUSTOMKEY || this.ac.has(this.ACC_CUSTOMKEY + ":" + this.context.name);
284
+ if (!allow)
285
+ element.nativeElement.setAttribute("enabled", "true");
286
+ }
287
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ContextAwareDirective, deps: [{ token: i0.ElementRef }, { token: ComponentContext, optional: true }, { token: AccessControlService }, { token: ACC_CUSTOMKEY, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
288
+ static { thisdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: ContextAwareDirective, selector: "[contextAware]", ngImport: i0 }); }
289
+ }
290
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ContextAwareDirective, decorators: [{
291
+ type: Directive,
292
+ args: [{
293
+ selector: '[contextAware]',
294
+ }]
295
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ComponentContext, decorators: [{
296
+ type: Optional
297
+ }] }, { type: AccessControlService }, { type: undefined, decorators: [{
298
+ type: Optional
299
+ }, {
300
+ type: Inject,
301
+ args: [ACC_CUSTOMKEY]
302
302
  }] }]; } });
303
303
 
304
- // Angular
305
- /**
306
- * Pipe che restituisce **true** quando il controllo sugli accessi ha successo, false altrimenti
307
- *
308
- * Per gli esempi di utilizzo fare riferimento al README.
309
- */
310
- class AccessControlPipe {
311
- /** @ignore Costruttore */
312
- constructor(_ac) {
313
- this._ac = _ac;
314
- }
315
- /**
316
- * Trasforma l'espressione ac in un booleano
317
- * @param value Espressione ac
318
- * @param absolute Indica se valutare **ac** in maniera assoluta o meno
319
- * @returns **true** se la condizione è verificata, **false** altrimenti
320
- */
321
- transform(value, absolute) {
322
- return this._ac.has(value, absolute);
323
- }
324
- }
325
- AccessControlPipefac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlPipe, deps: [{ token: AccessControlService }], target: i0.ɵɵFactoryTarget.Pipe });
326
- AccessControlPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: AccessControlPipe, name: "ac" });
327
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlPipe, decorators: [{
328
- type: Pipe,
329
- args: [{ name: 'ac' }]
304
+ // Angular
305
+ /**
306
+ * Pipe che restituisce **true** quando il controllo sugli accessi ha successo, false altrimenti
307
+ *
308
+ * Per gli esempi di utilizzo fare riferimento al README.
309
+ */
310
+ class AccessControlPipe {
311
+ /** @ignore Costruttore */
312
+ constructor(_ac) {
313
+ this._ac = _ac;
314
+ }
315
+ /**
316
+ * Trasforma l'espressione ac in un booleano
317
+ * @param value Espressione ac
318
+ * @param absolute Indica se valutare **ac** in maniera assoluta o meno
319
+ * @returns **true** se la condizione è verificata, **false** altrimenti
320
+ */
321
+ transform(value, absolute) {
322
+ return this._ac.has(value, absolute);
323
+ }
324
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlPipe, deps: [{ token: AccessControlService }], target: i0.ɵɵFactoryTarget.Pipe }); }
325
+ static { thispipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: AccessControlPipe, name: "ac" }); }
326
+ }
327
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlPipe, decorators: [{
328
+ type: Pipe,
329
+ args: [{ name: 'ac' }]
330
330
  }], ctorParameters: function () { return [{ type: AccessControlService }]; } });
331
331
 
332
- class AccessControlModule {
333
- static forRoot(config) {
334
- return {
335
- ngModule: AccessControlModule,
336
- providers: [
337
- { provide: ACC_CUSTOMKEY, useValue: config?.contextAwareKey || null },
338
- { provide: ACC_DEF_COND, useValue: config?.defaultCondition || null },
339
- { provide: ACC_DEF_COND_OP, useValue: config?.defaultConditionLogicalOperator || '||' },
340
- { provide: ACC_DEBUG_MODE, useValue: config?.debugMode || false },
341
- ]
342
- };
343
- }
344
- }
345
- AccessControlModulefac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
346
- AccessControlModulemod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: AccessControlModule, declarations: [AccessControlDirective, ContextAwareDirective, AccessControlPipe], exports: [AccessControlDirective, ContextAwareDirective, AccessControlPipe] });
347
- AccessControlModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlModule });
348
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AccessControlModule, decorators: [{
349
- type: NgModule,
350
- args: [{
351
- declarations: [AccessControlDirective, ContextAwareDirective, AccessControlPipe],
352
- exports: [AccessControlDirective, ContextAwareDirective, AccessControlPipe]
353
- }]
332
+ class AccessControlModule {
333
+ static forRoot(config) {
334
+ return {
335
+ ngModule: AccessControlModule,
336
+ providers: [
337
+ { provide: ACC_CUSTOMKEY, useValue: config?.contextAwareKey || null },
338
+ { provide: ACC_DEF_COND, useValue: config?.defaultCondition || null },
339
+ { provide: ACC_DEF_COND_OP, useValue: config?.defaultConditionLogicalOperator || '||' },
340
+ { provide: ACC_DEBUG_MODE, useValue: config?.debugMode || false },
341
+ ]
342
+ };
343
+ }
344
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
345
+ static { thismod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: AccessControlModule, declarations: [AccessControlDirective, ContextAwareDirective, AccessControlPipe], exports: [AccessControlDirective, ContextAwareDirective, AccessControlPipe] }); }
346
+ static { thisinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlModule }); }
347
+ }
348
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AccessControlModule, decorators: [{
349
+ type: NgModule,
350
+ args: [{
351
+ declarations: [AccessControlDirective, ContextAwareDirective, AccessControlPipe],
352
+ exports: [AccessControlDirective, ContextAwareDirective, AccessControlPipe]
353
+ }]
354
354
  }] });
355
355
 
356
- /**
357
- * Configurazione Modulo AccessControl. Se non fornita verrà generata automaticamente con locale 'it-IT'
358
- */
359
- class AccessControlModuleConfig {
356
+ /**
357
+ * Configurazione Modulo AccessControl. Se non fornita verrà generata automaticamente con locale 'it-IT'
358
+ */
359
+ class AccessControlModuleConfig {
360
360
  }
361
361
 
362
- /**
363
- * Router Guard base per proteggere l'accesso alle route dell'applicazione. Per utilizzarla è sufficiente ereditarla e, nel costruttore della classe
364
- * che la ereditavalorizzare la variabile Routes con le route permesse dal modulo e il permesso per cui si vuole riservare l'accesso. Ad esempio:
365
- *
366
- * ```typescript
367
- * @Injectable()
368
- * export class HasAuthGuardComponent extends BaseRouterGuard {
369
- * constructor(acc: AccessControlService, router: Router, ms: MessageService, ts: BaseTokenService) {
370
- * super(ms, acc, router, ts);
371
- * this.Routes = [
372
- * { route: "page_route", permission: "P:perm_one" },
373
- * { route: "*", permission: "R:role_one" }
374
- * ]
375
- * }
376
- * }
377
- * ```
378
- */
379
- class AccessControlRouteGuard {
380
- /**
381
- * @ignore
382
- */
383
- constructor(msgService, ac, router) {
384
- this.msgService = msgService;
385
- this.ac = ac;
386
- this.router = router;
387
- /**
388
- * Route di login che serve per reindirizzare alla pagina di login in caso di fallimento del controllo sui Permessi
389
- *
390
- * @default
391
- */
392
- this.LoginRoute = "login";
393
- /**
394
- * Permette di specificare delle Route sempre consentite, anche a livello di "Radice". Ad esempio la Root "test" permetterà
395
- * l'accesso a tutte le route che anche solo iniziano per "test"
396
- */
397
- this.AlwaysAllowedRoots = [];
398
- /**
399
- * Lista di Route con la loro espressione di controllo per valutare i permessi
400
- */
401
- this.Routes = [];
402
- }
403
- /**
404
- * @ignore
405
- */
406
- canActivateChild(route, _) {
407
- var url = route.url.join('/');
408
- //Se l'applicazione non è pronta e non sto navigando nelle pagine consentite
409
- if (!this.ac.Initialized && !this.AlwaysAllowedRoots.find(r => url.indexOf(r) != -1))
410
- return Promise.resolve(false);
411
- var routeMatched = false;
412
- for (let i = 0; i < this.Routes.length; i++) {
413
- let r = this.Routes[i];
414
- //Se faccio match con la route significa che ho navigato in una delle route conosciute, altrimenti avverto ma lascio andare
415
- if (url.indexOf(r.route) != -1) {
416
- routeMatched = true;
417
- return this.handleMatch(url, r);
418
- }
419
- }
420
- //Se non faccio nessun match ma ho una route wildcard (*) prendo quella e controllo su quella
421
- if (!routeMatched) {
422
- var wildcardRoute = this.Routes.find(r => r.route == "*");
423
- if (wildcardRoute)
424
- return this.handleMatch(url, wildcardRoute);
425
- else
426
- console.log("Navigaizone avvenuta su route sconosciuta: " + url);
427
- }
428
- return Promise.resolve(true);
429
- }
430
- /**
431
- * @ignore
432
- */
433
- handleMatch(fromurl, r) {
434
- let identity = this.ac.Identity;
435
- if (this.ac.has(r.permission) ||
436
- (
437
- // Considero anche la possibilità di avere l'access control inizializzato ma che l'account scope non sia ancora presente
438
- // in questo caso suppongo sia un hard refresh e mi fido del fatto che l'utente possa entrarci
439
- // TODO: Fixare meglio concatenando una promise che va a prendere l'account scope se serve
440
- this.ac.Initialized &&
441
- (!identity.Roles || identity.Roles.length == 0) &&
442
- (!identity.Permissions || identity.Permissions.length == 0)))
443
- return Promise.resolve(true);
444
- else {
445
- //Se sono nel sito originale (non ho aperto un newtab) blocco la navigazione
446
- //Se ho aperto una nuova tab invece rispedisco al login
447
- if (window.history.length > 2 && this.ac.isLoggedIn()) {
448
- this.msgService.simpleError("Page Unauthorized");
449
- return Promise.resolve(false);
450
- }
451
- else {
452
- this.onRedirectInProgress();
453
- this.router.navigate([this.LoginRoute, { fromUrl: fromurl }]);
454
- }
455
- }
456
- }
457
- /**
458
- * Callback che viene eseguito prima che la Guard reindirizzi al login
459
- */
460
- onRedirectInProgress() {
461
- }
362
+ /**
363
+ * Router Guard base per proteggere l'accesso alle route dell'applicazione. Per utilizzarla è sufficiente ereditarla e, nel costruttore della classe
364
+ * che la ereditavalorizzare la variabile Routes con le route permesse dal modulo e il permesso per cui si vuole riservare l'accesso. Ad esempio:
365
+ *
366
+ * ```typescript
367
+ * @Injectable()
368
+ * export class HasAuthGuardComponent extends BaseRouterGuard {
369
+ * constructor(acc: AccessControlService, router: Router, ms: MessageService, ts: BaseTokenService) {
370
+ * super(ms, acc, router, ts);
371
+ * this.Routes = [
372
+ * { route: "page_route", permission: "P:perm_one" },
373
+ * { route: "*", permission: "R:role_one" }
374
+ * ]
375
+ * }
376
+ * }
377
+ * ```
378
+ */
379
+ class AccessControlRouteGuard {
380
+ /**
381
+ * @ignore
382
+ */
383
+ constructor(msgService, ac, router) {
384
+ this.msgService = msgService;
385
+ this.ac = ac;
386
+ this.router = router;
387
+ /**
388
+ * Route di login che serve per reindirizzare alla pagina di login in caso di fallimento del controllo sui Permessi
389
+ *
390
+ * @default
391
+ */
392
+ this.LoginRoute = "login";
393
+ /**
394
+ * Permette di specificare delle Route sempre consentite, anche a livello di "Radice". Ad esempio la Root "test" permetterà
395
+ * l'accesso a tutte le route che anche solo iniziano per "test"
396
+ */
397
+ this.AlwaysAllowedRoots = [];
398
+ /**
399
+ * Lista di Route con la loro espressione di controllo per valutare i permessi
400
+ */
401
+ this.Routes = [];
402
+ }
403
+ /**
404
+ * @ignore
405
+ */
406
+ canActivateChild(route, _) {
407
+ var url = route.url.join('/');
408
+ //Se l'applicazione non è pronta e non sto navigando nelle pagine consentite
409
+ if (!this.ac.Initialized && !this.AlwaysAllowedRoots.find(r => url.indexOf(r) != -1))
410
+ return Promise.resolve(false);
411
+ var routeMatched = false;
412
+ for (let i = 0; i < this.Routes.length; i++) {
413
+ let r = this.Routes[i];
414
+ //Se faccio match con la route significa che ho navigato in una delle route conosciute, altrimenti avverto ma lascio andare
415
+ if (url.indexOf(r.route) != -1) {
416
+ routeMatched = true;
417
+ return this.handleMatch(url, r);
418
+ }
419
+ }
420
+ //Se non faccio nessun match ma ho una route wildcard (*) prendo quella e controllo su quella
421
+ if (!routeMatched) {
422
+ var wildcardRoute = this.Routes.find(r => r.route == "*");
423
+ if (wildcardRoute)
424
+ return this.handleMatch(url, wildcardRoute);
425
+ else
426
+ console.log("Navigaizone avvenuta su route sconosciuta: " + url);
427
+ }
428
+ return Promise.resolve(true);
429
+ }
430
+ /**
431
+ * @ignore
432
+ */
433
+ handleMatch(fromurl, r) {
434
+ let identity = this.ac.Identity;
435
+ if (this.ac.has(r.permission) ||
436
+ (
437
+ // Considero anche la possibilità di avere l'access control inizializzato ma che l'account scope non sia ancora presente
438
+ // in questo caso suppongo sia un hard refresh e mi fido del fatto che l'utente possa entrarci
439
+ // TODO: Fixare meglio concatenando una promise che va a prendere l'account scope se serve
440
+ this.ac.Initialized &&
441
+ (!identity.Roles || identity.Roles.length == 0) &&
442
+ (!identity.Permissions || identity.Permissions.length == 0)))
443
+ return Promise.resolve(true);
444
+ else {
445
+ //Se sono nel sito originale (non ho aperto un newtab) blocco la navigazione
446
+ //Se ho aperto una nuova tab invece rispedisco al login
447
+ if (window.history.length > 2 && this.ac.isLoggedIn()) {
448
+ this.msgService.simpleError("Page Unauthorized");
449
+ return Promise.resolve(false);
450
+ }
451
+ else {
452
+ this.onRedirectInProgress();
453
+ this.router.navigate([this.LoginRoute, { fromUrl: fromurl }]);
454
+ }
455
+ }
456
+ }
457
+ /**
458
+ * Callback che viene eseguito prima che la Guard reindirizzi al login
459
+ */
460
+ onRedirectInProgress() {
461
+ }
462
462
  }
463
463
 
464
- /*
465
- * Public API Surface of access-control
464
+ /*
465
+ * Public API Surface of access-control
466
466
  */
467
467
 
468
- /**
469
- * Generated bundle index. Do not edit.
468
+ /**
469
+ * Generated bundle index. Do not edit.
470
470
  */
471
471
 
472
472
  export { ACC_CUSTOMKEY, ACC_DEBUG_MODE, ACC_DEF_COND, ACC_DEF_COND_OP, AccessControlDirective, AccessControlModule, AccessControlModuleConfig, AccessControlPipe, AccessControlRouteGuard, AccessControlService, ComponentContext, ContextAwareDirective };