@esfaenza/access-control 12.2.7 → 13.1.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 (35) hide show
  1. package/esfaenza-access-control.d.ts +1 -1
  2. package/esm2020/esfaenza-access-control.mjs +5 -0
  3. package/esm2020/lib/AccessControlRouteGuard.mjs +122 -0
  4. package/esm2020/lib/access-control.directive.mjs +47 -0
  5. package/esm2020/lib/access-control.module.mjs +33 -0
  6. package/esm2020/lib/access-control.service.mjs +133 -0
  7. package/esm2020/lib/context-aware.directive.mjs +42 -0
  8. package/{esm2015/lib/models/AccessControlModuleConfig.js → esm2020/lib/models/AccessControlModuleConfig.mjs} +0 -0
  9. package/esm2020/lib/models/ComponentContext.mjs +13 -0
  10. package/{esm2015/lib/tokens.js → esm2020/lib/tokens.mjs} +0 -0
  11. package/esm2020/public-api.mjs +12 -0
  12. package/fesm2015/{esfaenza-access-control.js → esfaenza-access-control.mjs} +66 -52
  13. package/fesm2015/esfaenza-access-control.mjs.map +1 -0
  14. package/fesm2020/esfaenza-access-control.mjs +392 -0
  15. package/fesm2020/esfaenza-access-control.mjs.map +1 -0
  16. package/lib/AccessControlRouteGuard.d.ts +3 -0
  17. package/lib/access-control.directive.d.ts +3 -0
  18. package/lib/access-control.module.d.ts +7 -0
  19. package/lib/access-control.service.d.ts +3 -0
  20. package/lib/context-aware.directive.d.ts +3 -0
  21. package/lib/models/ComponentContext.d.ts +3 -0
  22. package/package.json +23 -11
  23. package/public-api.d.ts +1 -0
  24. package/bundles/esfaenza-access-control.umd.js +0 -413
  25. package/bundles/esfaenza-access-control.umd.js.map +0 -1
  26. package/esfaenza-access-control.metadata.json +0 -1
  27. package/esm2015/esfaenza-access-control.js +0 -6
  28. package/esm2015/lib/AccessControlRouteGuard.js +0 -120
  29. package/esm2015/lib/access-control.directive.js +0 -50
  30. package/esm2015/lib/access-control.module.js +0 -28
  31. package/esm2015/lib/access-control.service.js +0 -132
  32. package/esm2015/lib/context-aware.directive.js +0 -39
  33. package/esm2015/lib/models/ComponentContext.js +0 -10
  34. package/esm2015/public-api.js +0 -11
  35. package/fesm2015/esfaenza-access-control.js.map +0 -1
@@ -1,7 +1,8 @@
1
1
  import { LocalizationService, LocalizationModule } from '@esfaenza/localizations';
2
- import { InjectionToken, Injectable, Optional, Inject, Directive, TemplateRef, ViewContainerRef, Input, ElementRef, NgModule } from '@angular/core';
3
- import { Router } from '@angular/router';
4
- import { MessageService } from '@esfaenza/extensions';
2
+ import * as i0 from '@angular/core';
3
+ import { InjectionToken, Injectable, Optional, Inject, Directive, Input, NgModule } from '@angular/core';
4
+ import * as i1 from '@esfaenza/extensions';
5
+ import * as i3 from '@angular/router';
5
6
 
6
7
  /**
7
8
  * Token che racchiude il locale scelto per l'applicazione
@@ -138,10 +139,11 @@ class AccessControlService {
138
139
  return this.hasACExpression(expr);
139
140
  }
140
141
  }
141
- AccessControlService.decorators = [
142
- { type: Injectable }
143
- ];
144
- AccessControlService.ctorParameters = () => [];
142
+ AccessControlService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
143
+ AccessControlService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlService });
144
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlService, decorators: [{
145
+ type: Injectable
146
+ }], ctorParameters: function () { return []; } });
145
147
 
146
148
  /**
147
149
  * Router Guard base per proteggere l'accesso alle route dell'applicazione. Per utilizzarla è sufficiente ereditarla e, nel costruttore della classe
@@ -245,15 +247,18 @@ class AccessControlRouteGuard {
245
247
  onRedirectInProgress() {
246
248
  }
247
249
  }
248
- AccessControlRouteGuard.decorators = [
249
- { type: Injectable }
250
- ];
251
- AccessControlRouteGuard.ctorParameters = () => [
252
- { type: MessageService },
253
- { type: AccessControlService },
254
- { type: Router },
255
- { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ACC_LOCALE,] }] }
256
- ];
250
+ AccessControlRouteGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlRouteGuard, deps: [{ token: i1.MessageService }, { token: AccessControlService }, { token: i3.Router }, { token: ACC_LOCALE, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
251
+ AccessControlRouteGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlRouteGuard });
252
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlRouteGuard, decorators: [{
253
+ type: Injectable
254
+ }], ctorParameters: function () {
255
+ return [{ type: i1.MessageService }, { type: AccessControlService }, { type: i3.Router }, { type: undefined, decorators: [{
256
+ type: Optional
257
+ }, {
258
+ type: Inject,
259
+ args: [ACC_LOCALE]
260
+ }] }];
261
+ } });
257
262
 
258
263
  // Angular
259
264
  /**
@@ -288,28 +293,27 @@ class AccessControlDirective {
288
293
  this.viewContainer.clear();
289
294
  }
290
295
  }
291
- AccessControlDirective.decorators = [
292
- { type: Directive, args: [{
293
- selector: '[ac]',
294
- },] }
295
- ];
296
- AccessControlDirective.ctorParameters = () => [
297
- { type: TemplateRef },
298
- { type: ViewContainerRef },
299
- { type: AccessControlService }
300
- ];
301
- AccessControlDirective.propDecorators = {
302
- ac: [{ type: Input }]
303
- };
296
+ AccessControlDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: AccessControlService }], target: i0.ɵɵFactoryTarget.Directive });
297
+ AccessControlDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.1.1", type: AccessControlDirective, selector: "[ac]", inputs: { ac: "ac" }, ngImport: i0 });
298
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlDirective, decorators: [{
299
+ type: Directive,
300
+ args: [{
301
+ selector: '[ac]',
302
+ }]
303
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: AccessControlService }]; }, propDecorators: { ac: [{
304
+ type: Input
305
+ }] } });
304
306
 
305
307
  /**
306
308
  * Token da iniettare per ogni singolo componente per cui si vuole disattivare/attivare massivamente degli input in maniera contestuale
307
309
  */
308
310
  class ComponentContext {
309
311
  }
310
- ComponentContext.decorators = [
311
- { type: Injectable }
312
- ];
312
+ ComponentContext.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ComponentContext, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
313
+ ComponentContext.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ComponentContext });
314
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ComponentContext, decorators: [{
315
+ type: Injectable
316
+ }] });
313
317
 
314
318
  // Angular
315
319
  /**
@@ -332,17 +336,23 @@ class ContextAwareDirective {
332
336
  element.nativeElement.setAttribute("enabled", "true");
333
337
  }
334
338
  }
335
- ContextAwareDirective.decorators = [
336
- { type: Directive, args: [{
337
- selector: '[contextAware]',
338
- },] }
339
- ];
340
- ContextAwareDirective.ctorParameters = () => [
341
- { type: ElementRef },
342
- { type: ComponentContext, decorators: [{ type: Optional }] },
343
- { type: AccessControlService },
344
- { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ACC_CUSTOMKEY,] }] }
345
- ];
339
+ ContextAwareDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ContextAwareDirective, deps: [{ token: i0.ElementRef }, { token: ComponentContext, optional: true }, { token: AccessControlService }, { token: ACC_CUSTOMKEY, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
340
+ ContextAwareDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.1.1", type: ContextAwareDirective, selector: "[contextAware]", ngImport: i0 });
341
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ContextAwareDirective, decorators: [{
342
+ type: Directive,
343
+ args: [{
344
+ selector: '[contextAware]',
345
+ }]
346
+ }], ctorParameters: function () {
347
+ return [{ type: i0.ElementRef }, { type: ComponentContext, decorators: [{
348
+ type: Optional
349
+ }] }, { type: AccessControlService }, { type: undefined, decorators: [{
350
+ type: Optional
351
+ }, {
352
+ type: Inject,
353
+ args: [ACC_CUSTOMKEY]
354
+ }] }];
355
+ } });
346
356
 
347
357
  class AccessControlModule {
348
358
  static forRoot(config) {
@@ -357,13 +367,17 @@ class AccessControlModule {
357
367
  };
358
368
  }
359
369
  }
360
- AccessControlModule.decorators = [
361
- { type: NgModule, args: [{
362
- imports: [LocalizationModule],
363
- declarations: [AccessControlDirective, ContextAwareDirective],
364
- exports: [AccessControlDirective, ContextAwareDirective]
365
- },] }
366
- ];
370
+ AccessControlModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
371
+ AccessControlModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlModule, declarations: [AccessControlDirective, ContextAwareDirective], imports: [LocalizationModule], exports: [AccessControlDirective, ContextAwareDirective] });
372
+ AccessControlModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlModule, imports: [[LocalizationModule]] });
373
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlModule, decorators: [{
374
+ type: NgModule,
375
+ args: [{
376
+ imports: [LocalizationModule],
377
+ declarations: [AccessControlDirective, ContextAwareDirective],
378
+ exports: [AccessControlDirective, ContextAwareDirective]
379
+ }]
380
+ }] });
367
381
 
368
382
  /**
369
383
  * Configurazione Modulo AccessControl. Se non fornita verrà generata automaticamente con locale 'it-IT'
@@ -379,5 +393,5 @@ class AccessControlModuleConfig {
379
393
  * Generated bundle index. Do not edit.
380
394
  */
381
395
 
382
- export { ACC_CUSTOMKEY, ACC_LOCALE, AccessControlDirective, AccessControlModule, AccessControlModuleConfig, AccessControlRouteGuard, AccessControlService, ComponentContext, ContextAwareDirective as ɵa };
383
- //# sourceMappingURL=esfaenza-access-control.js.map
396
+ export { ACC_CUSTOMKEY, ACC_LOCALE, AccessControlDirective, AccessControlModule, AccessControlModuleConfig, AccessControlRouteGuard, AccessControlService, ComponentContext, ContextAwareDirective };
397
+ //# sourceMappingURL=esfaenza-access-control.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esfaenza-access-control.mjs","sources":["../../../projects/access-control/src/lib/tokens.ts","../../../projects/access-control/src/lib/access-control.service.ts","../../../projects/access-control/src/lib/AccessControlRouteGuard.ts","../../../projects/access-control/src/lib/access-control.directive.ts","../../../projects/access-control/src/lib/models/ComponentContext.ts","../../../projects/access-control/src/lib/context-aware.directive.ts","../../../projects/access-control/src/lib/access-control.module.ts","../../../projects/access-control/src/lib/models/AccessControlModuleConfig.ts","../../../projects/access-control/src/public-api.ts","../../../projects/access-control/src/esfaenza-access-control.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\r\n\r\n/**\r\n * Token che racchiude il locale scelto per l'applicazione\r\n */\r\nexport const ACC_LOCALE: InjectionToken<string> = new InjectionToken<string>('ACC_LOCALE');\r\n\r\n/**\r\n * Token che racchiude la chiave custom da controllare quando si effettuano controlli sul ComponentContext\r\n */\r\nexport const ACC_CUSTOMKEY: InjectionToken<string> = new InjectionToken<string>('ACC_CUSTOMKEY');","// Angular\r\nimport { Injectable } from \"@angular/core\";\r\n\r\n/**\r\n * Entrypoint di tutte le operazioni esposte dalla libreria access-control\r\n */\r\n@Injectable()\r\nexport class AccessControlService {\r\n\r\n /**\r\n * Indica se l'Identity è stata inizializzata\r\n */\r\n public Initialized: boolean = false;\r\n\r\n /**\r\n * Indica se sono state effettuate inizializzazioni di Custom Permissions\r\n */\r\n public InitializedCustom: boolean = false;\r\n\r\n /** @ignore */\r\n private cache: {} = {};\r\n\r\n /** @ignore */\r\n private taggedItemsCache: { key: string, items: string[] }[] = [];\r\n\r\n /**\r\n * Identity associata a quest'istanza del Servizio Access Control, utile se si vuole avere accesso a Ruoli e Permessi direttamente da qui, per qualsivoglia motivo\r\n */\r\n public Identity: { Roles: string[], Permissions: string[] };\r\n\r\n /** @ignore */\r\n constructor() { }\r\n\r\n /**\r\n * Inizializza l'Identity del servizio con il modello specificato\r\n * \r\n * @params {{ Roles: string[], Permissions: string[] }} identity Identità applicativa con ruoli e permessi\r\n */\r\n public initializeIdentity(identity: { Roles: string[], Permissions: string[] }) {\r\n this.Identity = identity;\r\n this.Initialized = true;\r\n }\r\n\r\n /**\r\n * Inizializza i permessi Custom del servizio con il modello specificato\r\n * \r\n * @param {{ key: string, items: string[] }[]} customPermissions Permessi Custom\r\n */\r\n public initializeCustomPermissions(customPermissions: { key: string, items: string[] }[]) {\r\n this.taggedItemsCache = customPermissions;\r\n this.InitializedCustom = true;\r\n }\r\n\r\n /**\r\n * Indica se nella sessione attuale esiste un utente loggato. Fa un semplice controllo di presenza sull'Identity\r\n */\r\n public isLoggedIn() {\r\n return !!this.Identity;\r\n }\r\n\r\n /**\r\n * Expression è scritta tipo --> R:Role1 && P:Permission1 || (R:Role2 && P:Permission1)\r\n * Quindi piuttosto che implementarsi un parser della madonna in stile Alessandro prendo la strada stronza e veloce con l'eval :P\r\n * \r\n * @ignore\r\n */\r\n private hasACExpression(expression: string): boolean {\r\n if (!this.Initialized)\r\n console.error(\"Access Control System has not been initialized. Call this.accessControl.initialize(..., ...) before using the service\");\r\n\r\n if (!expression)\r\n return true;\r\n\r\n if (!this.Identity) {\r\n console.warn(\"Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default\")\r\n return true;\r\n }\r\n\r\n //Espressione già valutata, non serve rivalutarla\r\n if (this.cache[expression])\r\n return this.cache[expression];\r\n\r\n var RolesPermissionsRegexp = /.:[^|&()]+/g;\r\n\r\n var matches = expression.match(RolesPermissionsRegexp);\r\n \r\n if (!matches)\r\n throw \"Espressione Access Control non valida: \" + expression + \". Assicurarsi che sia scritta in modo corretto\";\r\n\r\n matches.forEach(t => {\r\n var splits = t.split(':');\r\n if (splits[0] == \"R\")\r\n expression = expression.replace(t.trim(), \"this.hasRole('\" + splits[1].trim() + \"')\");\r\n else if (splits[0] == \"P\")\r\n expression = expression.replace(t.trim(), \"this.hasPermission('\" + splits[1].trim() + \"')\");\r\n else\r\n expression = expression.replace(t.trim(), \"this.hasCustom('\" + splits[1].trim() + \"', '\" + splits[0].trim() + \"')\");\r\n });\r\n\r\n var ret = <boolean>eval(expression);\r\n // Cache valore\r\n this.cache[expression] = ret;\r\n return ret;\r\n }\r\n\r\n /**\r\n * Utilizzato da hasACExpression\r\n * \r\n * @ignore\r\n */\r\n private hasRole(role: string): boolean {\r\n if (!this.Identity) {\r\n console.warn(\"Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default\")\r\n return true;\r\n }\r\n return this.Identity.Roles && this.Identity.Roles.length > 0 && this.Identity.Roles.indexOf(role) != -1;\r\n }\r\n\r\n /**\r\n * Utilizzato da hasACExpression\r\n * \r\n * @ignore\r\n */\r\n private hasPermission(permission: string): boolean {\r\n if (!this.Identity) {\r\n console.warn(\"Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default\")\r\n return true;\r\n }\r\n return this.Identity.Permissions && this.Identity.Permissions.length > 0 && this.Identity.Permissions.indexOf(permission) != -1;\r\n }\r\n\r\n /**\r\n * Utilizzato da hasACExpression\r\n * \r\n * @ignore\r\n */\r\n private hasCustom(value: string, tag: string): boolean {\r\n var items = this.taggedItemsCache.find(t => t.key == tag)?.items;\r\n if (!items)\r\n return true;\r\n else if (items.length == 0)\r\n return false;\r\n else\r\n return !!items.find(t => t == value);\r\n }\r\n\r\n /**\r\n * 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\"\r\n */\r\n public has(expr: string) {\r\n return this.hasACExpression(expr);\r\n }\r\n}","//Angular\r\nimport { ActivatedRouteSnapshot, CanActivateChild, RouterStateSnapshot } from \"@angular/router\";\r\nimport { Injectable, Optional, Inject } from \"@angular/core\";\r\nimport { Router } from \"@angular/router\";\r\n\r\n//Libs\r\nimport { LocalizationService } from \"@esfaenza/localizations\";\r\nimport { MessageService } from \"@esfaenza/extensions\";\r\n\r\n//Models\r\nimport { ACC_LOCALE } from \"./tokens\";\r\nimport { AccessControlService } from './access-control.service';\r\n\r\n/**\r\n * Router Guard base per proteggere l'accesso alle route dell'applicazione. Per utilizzarla è sufficiente ereditarla e, nel costruttore della classe\r\n * che la ereditavalorizzare la variabile Routes con le route permesse dal modulo e il permesso per cui si vuole riservare l'accesso. Ad esempio:\r\n * \r\n * ```typescript\r\n * @Injectable()\r\n * export class HasAuthGuardComponent extends BaseRouterGuard {\r\n * constructor(acc: AccessControlService, router: Router, ms: MessageService, ts: BaseTokenService) {\r\n * super(ms, acc, router, ts);\r\n * this.Routes = [\r\n * { route: \"page_route\", permission: \"P:perm_one\" },\r\n * { route: \"*\", permission: \"R:role_one\" }\r\n * ]\r\n * }\r\n * }\r\n * ```\r\n */\r\n@Injectable()\r\nexport class AccessControlRouteGuard implements CanActivateChild {\r\n /**\r\n * @ignore\r\n */\r\n private lc: LocalizationService;\r\n\r\n /**\r\n * Route di login che serve per reindirizzare alla pagina di login in caso di fallimento del controllo sui Permessi\r\n * \r\n * @default\r\n */\r\n protected LoginRoute : string = \"login\";\r\n\r\n /**\r\n * Permette di specificare delle Route sempre consentite, anche a livello di \"Radice\". Ad esempio la Root \"test\" permetterà\r\n * l'accesso a tutte le route che anche solo iniziano per \"test\"\r\n */\r\n protected AlwaysAllowedRoots: string[] = [];\r\n \r\n /**\r\n * Lista di Route con la loro espressione di controllo per valutare i permessi\r\n */\r\n protected Routes: { route: any; permission: string; }[] = [];\r\n\r\n /**\r\n * @ignore\r\n */\r\n constructor(private msgService : MessageService, private ac: AccessControlService, private router: Router, @Optional() @Inject(ACC_LOCALE) LOCALE: string) {\r\n this.lc = new LocalizationService(LOCALE ?? 'it-IT');\r\n }\r\n\r\n /**\r\n * @ignore\r\n */\r\n canActivateChild(route: ActivatedRouteSnapshot, _: RouterStateSnapshot): Promise<boolean> {\r\n var url = route.url.join('/');\r\n //Se l'applicazione non è pronta e non sto navigando nelle pagine consentite\r\n if (!this.ac.Initialized && !this.AlwaysAllowedRoots.find(r => url.indexOf(r) != -1))\r\n return Promise.resolve(false);\r\n \r\n var routeMatched: boolean = false;\r\n for (let i = 0; i < this.Routes.length; i++) {\r\n let r = this.Routes[i];\r\n //Se faccio match con la route significa che ho navigato in una delle route conosciute, altrimenti avverto ma lascio andare\r\n if (url.indexOf(r.route) != -1) {\r\n routeMatched = true;\r\n return this.handleMatch(url, r);\r\n }\r\n }\r\n //Se non faccio nessun match ma ho una route wildcard (*) prendo quella e controllo su quella\r\n if (!routeMatched) {\r\n var wildcardRoute = this.Routes.find(r => r.route == \"*\");\r\n if (wildcardRoute)\r\n return this.handleMatch(url, wildcardRoute);\r\n else\r\n console.log(\"Navigaizone avvenuta su route sconosciuta: \" + url);\r\n }\r\n return Promise.resolve(true);\r\n }\r\n\r\n /**\r\n * @ignore\r\n */\r\n private handleMatch(fromurl: string, r: any) {\r\n let identity = this.ac.Identity;\r\n\r\n if (this.ac.has(r.permission) ||\r\n (\r\n // Considero anche la possibilità di avere l'access control inizializzato ma che l'account scope non sia ancora presente\r\n // in questo caso suppongo sia un hard refresh e mi fido del fatto che l'utente possa entrarci\r\n // TODO: Fixare meglio concatenando una promise che va a prendere l'account scope se serve\r\n this.ac.Initialized &&\r\n (!identity.Roles || identity.Roles.length == 0) &&\r\n (!identity.Permissions || identity.Permissions.length == 0)\r\n ))\r\n return Promise.resolve(true);\r\n else {\r\n //Se sono nel sito originale (non ho aperto un newtab) blocco la navigazione\r\n //Se ho aperto una nuova tab invece rispedisco al login\r\n if (window.history.length > 2 && this.ac.isLoggedIn()) {\r\n this.msgService.simpleError(this.lc.loc(\"You don't have the required permissions to view this page. The navigation has been blocked\"));\r\n return Promise.resolve(false);\r\n }\r\n else {\r\n this.onRedirectInProgress();\r\n this.router.navigate([this.LoginRoute, { fromUrl: fromurl }]);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Callback che viene eseguito prima che la Guard reindirizzi al login\r\n */\r\n protected onRedirectInProgress() {\r\n }\r\n}","// Angular\r\nimport { Directive, Input, TemplateRef, ViewContainerRef } from \"@angular/core\";\r\n\r\n// Configurazioni\r\nimport { AccessControlService } from \"./access-control.service\";\r\n\r\n/**\r\n * Direttiva che permette di gestire il controllo accessi su componenti HTML. \r\n * \r\n * Per gli esempi di utilizzo fare riferimento al README.\r\n */\r\n@Directive({\r\n selector: '[ac]',\r\n})\r\nexport class AccessControlDirective {\r\n \r\n /**\r\n * Costruttore \r\n * \r\n * @ignore\r\n */\r\n constructor(private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef, private _ac: AccessControlService) { }\r\n\r\n /**\r\n * Input autoreferenziale per la direttiva\r\n * \r\n * @param {string} expression espressione da processare scritta come {Chiave}:{Valore}\r\n * \r\n * Le {Chiave} disponibili sono di default \"R\" per i ruoli e \"P\" per i permessi. È possibile espanderle con le Custom Permissions\r\n */\r\n @Input() set ac(expression: string) {\r\n var allow = this._ac.has(expression);\r\n\r\n //Se ho i permessi, proseguo creando la vista nel DOM, altrimenti rimuovo il template\r\n\r\n if (allow) this.viewContainer.createEmbeddedView(this.templateRef);\r\n else this.viewContainer.clear();\r\n }\r\n}","import { Injectable } from '@angular/core';\r\n\r\n/**\r\n * Token da iniettare per ogni singolo componente per cui si vuole disattivare/attivare massivamente degli input in maniera contestuale\r\n */\r\n@Injectable()\r\nexport class ComponentContext{\r\n /**\r\n * Nome del Contesto assegnato al Componente\r\n */\r\n name : string;\r\n}","// Angular\r\nimport { Directive, ElementRef, Optional, Inject } from \"@angular/core\";\r\n\r\n// Configurazioni\r\nimport { AccessControlService } from \"./access-control.service\";\r\nimport { ACC_CUSTOMKEY } from \"./tokens\"\r\n\r\n// Classi\r\nimport { ComponentContext } from \"./models/ComponentContext\";\r\n\r\n/**\r\n * Direttiva che permette di capire se l'elemento HTML su cui è utilizzata dev'essere disabilitato o no.\r\n * \r\n * Non ha effetto sugli elementi dichiarati in componenti che non dichiarano alcun ComponentContext\r\n */\r\n@Directive({\r\n selector: '[contextAware]',\r\n})\r\nexport class ContextAwareDirective {\r\n \r\n /**\r\n * Costruttore \r\n * \r\n * @ignore\r\n */\r\n constructor(element: ElementRef, @Optional() private context: ComponentContext, private ac: AccessControlService, @Optional() @Inject(ACC_CUSTOMKEY) private ACC_CUSTOMKEY: string) {\r\n var allow = !this.context || !this.context.name || !this.ACC_CUSTOMKEY || this.ac.has(this.ACC_CUSTOMKEY + \":\" + this.context.name,);\r\n\r\n if (!allow)\r\n element.nativeElement.setAttribute(\"enabled\", \"true\");\r\n }\r\n}","import { LocalizationModule } from '@esfaenza/localizations';\r\nimport { NgModule, ModuleWithProviders } from '@angular/core';\r\n\r\nimport { ACC_LOCALE, ACC_CUSTOMKEY} from './tokens';\r\n\r\nimport { AccessControlModuleConfig } from './models/AccessControlModuleConfig';\r\nimport { AccessControlService } from './access-control.service';\r\nimport { AccessControlRouteGuard } from './AccessControlRouteGuard';\r\nimport { AccessControlDirective } from './access-control.directive';\r\nimport { ContextAwareDirective } from './context-aware.directive';\r\n\r\n@NgModule({\r\n imports: [LocalizationModule],\r\n declarations: [AccessControlDirective, ContextAwareDirective],\r\n exports:[AccessControlDirective, ContextAwareDirective]\r\n})\r\nexport class AccessControlModule {\r\n static forRoot(config?: AccessControlModuleConfig): ModuleWithProviders<AccessControlModule> {\r\n return {\r\n ngModule: AccessControlModule,\r\n providers: [\r\n AccessControlService,\r\n AccessControlRouteGuard,\r\n { provide: ACC_LOCALE, useValue: config?.locale || 'it-IT' },\r\n { provide: ACC_CUSTOMKEY, useValue: config?.customKey || null }\r\n ]\r\n };\r\n }\r\n}","/**\r\n * Configurazione Modulo AccessControl. Se non fornita verrà generata automaticamente con locale 'it-IT'\r\n */\r\nexport class AccessControlModuleConfig {\r\n\r\n /**\r\n * locale dell'applicazione in forma standard, ad esempio \"it-IT\", \"en-US\", etc...\r\n * \r\n * Attualmente si supportano solo le lingue Italiano e Inglese\r\n */\r\n locale: string;\r\n\r\n /**\r\n * Chiave custom su cui la **contextAwareDirective** si basa per controllare se l'elemento è abilitato o meno\r\n */\r\n customKey: string;\r\n}","/*\r\n * Public API Surface of access-control\r\n */\r\n\r\nexport * from './lib/access-control.module';\r\nexport * from './lib/access-control.service';\r\nexport * from './lib/access-control.directive'\r\nexport * from './lib/context-aware.directive';\r\nexport * from \"./lib/models/AccessControlModuleConfig\";\r\nexport * from \"./lib/AccessControlRouteGuard\";\r\nexport * from \"./lib/tokens\";\r\nexport * from \"./lib/models/ComponentContext\";","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAEA;;;MAGa,UAAU,GAA2B,IAAI,cAAc,CAAS,YAAY,EAAE;AAE3F;;;MAGa,aAAa,GAA2B,IAAI,cAAc,CAAS,eAAe;;ACV/F;AAGA;;;MAIa,oBAAoB;;IAwB/B;;;;QAnBO,gBAAW,GAAY,KAAK,CAAC;;;;QAK7B,sBAAiB,GAAY,KAAK,CAAC;;QAGlC,UAAK,GAAO,EAAE,CAAC;;QAGf,qBAAgB,GAAuC,EAAE,CAAC;KAQjD;;;;;;IAOV,kBAAkB,CAAC,QAAoD;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MAAM,uBAAN,MAAM,CAAE,SAAS,KAAI,IAAI,EAAE;aAChE;SACF,CAAC;KACH;;gHAXU,mBAAmB;iHAAnB,mBAAmB,iBAHf,sBAAsB,EAAE,qBAAqB,aADlD,kBAAkB,aAEnB,sBAAsB,EAAE,qBAAqB;iHAE3C,mBAAmB,YAJrB,CAAC,kBAAkB,CAAC;2FAIlB,mBAAmB;kBAL/B,QAAQ;mBAAC;oBACR,OAAO,EAAE,CAAC,kBAAkB,CAAC;oBAC7B,YAAY,EAAE,CAAC,sBAAsB,EAAE,qBAAqB,CAAC;oBAC7D,OAAO,EAAC,CAAC,sBAAsB,EAAE,qBAAqB,CAAC;iBACxD;;;ACfD;;;MAGa,yBAAyB;;;ACHtC;;;;ACAA;;;;;;"}
@@ -0,0 +1,392 @@
1
+ import { LocalizationService, LocalizationModule } from '@esfaenza/localizations';
2
+ import * as i0 from '@angular/core';
3
+ import { InjectionToken, Injectable, Optional, Inject, Directive, Input, NgModule } from '@angular/core';
4
+ import * as i1 from '@esfaenza/extensions';
5
+ import * as i3 from '@angular/router';
6
+
7
+ /**
8
+ * Token che racchiude il locale scelto per l'applicazione
9
+ */
10
+ const ACC_LOCALE = new InjectionToken('ACC_LOCALE');
11
+ /**
12
+ * Token che racchiude la chiave custom da controllare quando si effettuano controlli sul ComponentContext
13
+ */
14
+ const ACC_CUSTOMKEY = new InjectionToken('ACC_CUSTOMKEY');
15
+
16
+ // Angular
17
+ /**
18
+ * Entrypoint di tutte le operazioni esposte dalla libreria access-control
19
+ */
20
+ class AccessControlService {
21
+ /** @ignore */
22
+ constructor() {
23
+ /**
24
+ * Indica se l'Identity è stata inizializzata
25
+ */
26
+ this.Initialized = false;
27
+ /**
28
+ * Indica se sono state effettuate inizializzazioni di Custom Permissions
29
+ */
30
+ this.InitializedCustom = false;
31
+ /** @ignore */
32
+ this.cache = {};
33
+ /** @ignore */
34
+ this.taggedItemsCache = [];
35
+ }
36
+ /**
37
+ * Inizializza l'Identity del servizio con il modello specificato
38
+ *
39
+ * @params {{ Roles: string[], Permissions: string[] }} identity Identità applicativa con ruoli e permessi
40
+ */
41
+ initializeIdentity(identity) {
42
+ this.Identity = identity;
43
+ this.Initialized = true;
44
+ }
45
+ /**
46
+ * Inizializza i permessi Custom del servizio con il modello specificato
47
+ *
48
+ * @param {{ key: string, items: string[] }[]} customPermissions Permessi Custom
49
+ */
50
+ initializeCustomPermissions(customPermissions) {
51
+ this.taggedItemsCache = customPermissions;
52
+ this.InitializedCustom = true;
53
+ }
54
+ /**
55
+ * Indica se nella sessione attuale esiste un utente loggato. Fa un semplice controllo di presenza sull'Identity
56
+ */
57
+ isLoggedIn() {
58
+ return !!this.Identity;
59
+ }
60
+ /**
61
+ * Expression è scritta tipo --> R:Role1 && P:Permission1 || (R:Role2 && P:Permission1)
62
+ * Quindi piuttosto che implementarsi un parser della madonna in stile Alessandro prendo la strada stronza e veloce con l'eval :P
63
+ *
64
+ * @ignore
65
+ */
66
+ hasACExpression(expression) {
67
+ if (!this.Initialized)
68
+ console.error("Access Control System has not been initialized. Call this.accessControl.initialize(..., ...) before using the service");
69
+ if (!expression)
70
+ return true;
71
+ if (!this.Identity) {
72
+ console.warn("Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default");
73
+ return true;
74
+ }
75
+ //Espressione già valutata, non serve rivalutarla
76
+ if (this.cache[expression])
77
+ return this.cache[expression];
78
+ var RolesPermissionsRegexp = /.:[^|&()]+/g;
79
+ var matches = expression.match(RolesPermissionsRegexp);
80
+ if (!matches)
81
+ throw "Espressione Access Control non valida: " + expression + ". Assicurarsi che sia scritta in modo corretto";
82
+ matches.forEach(t => {
83
+ var splits = t.split(':');
84
+ if (splits[0] == "R")
85
+ expression = expression.replace(t.trim(), "this.hasRole('" + splits[1].trim() + "')");
86
+ else if (splits[0] == "P")
87
+ expression = expression.replace(t.trim(), "this.hasPermission('" + splits[1].trim() + "')");
88
+ else
89
+ expression = expression.replace(t.trim(), "this.hasCustom('" + splits[1].trim() + "', '" + splits[0].trim() + "')");
90
+ });
91
+ var ret = eval(expression);
92
+ // Cache valore
93
+ this.cache[expression] = ret;
94
+ return ret;
95
+ }
96
+ /**
97
+ * Utilizzato da hasACExpression
98
+ *
99
+ * @ignore
100
+ */
101
+ hasRole(role) {
102
+ if (!this.Identity) {
103
+ console.warn("Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default");
104
+ return true;
105
+ }
106
+ return this.Identity.Roles && this.Identity.Roles.length > 0 && this.Identity.Roles.indexOf(role) != -1;
107
+ }
108
+ /**
109
+ * Utilizzato da hasACExpression
110
+ *
111
+ * @ignore
112
+ */
113
+ hasPermission(permission) {
114
+ if (!this.Identity) {
115
+ console.warn("Elemento Identity non specificato in Access Control. Gli accessi saranno tutti liberi di default");
116
+ return true;
117
+ }
118
+ return this.Identity.Permissions && this.Identity.Permissions.length > 0 && this.Identity.Permissions.indexOf(permission) != -1;
119
+ }
120
+ /**
121
+ * Utilizzato da hasACExpression
122
+ *
123
+ * @ignore
124
+ */
125
+ hasCustom(value, tag) {
126
+ var items = this.taggedItemsCache.find(t => t.key == tag)?.items;
127
+ if (!items)
128
+ return true;
129
+ else if (items.length == 0)
130
+ return false;
131
+ else
132
+ return !!items.find(t => t == value);
133
+ }
134
+ /**
135
+ * 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"
136
+ */
137
+ has(expr) {
138
+ return this.hasACExpression(expr);
139
+ }
140
+ }
141
+ AccessControlService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
142
+ AccessControlService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlService });
143
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlService, decorators: [{
144
+ type: Injectable
145
+ }], ctorParameters: function () { return []; } });
146
+
147
+ /**
148
+ * Router Guard base per proteggere l'accesso alle route dell'applicazione. Per utilizzarla è sufficiente ereditarla e, nel costruttore della classe
149
+ * che la ereditavalorizzare la variabile Routes con le route permesse dal modulo e il permesso per cui si vuole riservare l'accesso. Ad esempio:
150
+ *
151
+ * ```typescript
152
+ * @Injectable()
153
+ * export class HasAuthGuardComponent extends BaseRouterGuard {
154
+ * constructor(acc: AccessControlService, router: Router, ms: MessageService, ts: BaseTokenService) {
155
+ * super(ms, acc, router, ts);
156
+ * this.Routes = [
157
+ * { route: "page_route", permission: "P:perm_one" },
158
+ * { route: "*", permission: "R:role_one" }
159
+ * ]
160
+ * }
161
+ * }
162
+ * ```
163
+ */
164
+ class AccessControlRouteGuard {
165
+ /**
166
+ * @ignore
167
+ */
168
+ constructor(msgService, ac, router, LOCALE) {
169
+ this.msgService = msgService;
170
+ this.ac = ac;
171
+ this.router = router;
172
+ /**
173
+ * Route di login che serve per reindirizzare alla pagina di login in caso di fallimento del controllo sui Permessi
174
+ *
175
+ * @default
176
+ */
177
+ this.LoginRoute = "login";
178
+ /**
179
+ * Permette di specificare delle Route sempre consentite, anche a livello di "Radice". Ad esempio la Root "test" permetterà
180
+ * l'accesso a tutte le route che anche solo iniziano per "test"
181
+ */
182
+ this.AlwaysAllowedRoots = [];
183
+ /**
184
+ * Lista di Route con la loro espressione di controllo per valutare i permessi
185
+ */
186
+ this.Routes = [];
187
+ this.lc = new LocalizationService(LOCALE ?? 'it-IT');
188
+ }
189
+ /**
190
+ * @ignore
191
+ */
192
+ canActivateChild(route, _) {
193
+ var url = route.url.join('/');
194
+ //Se l'applicazione non è pronta e non sto navigando nelle pagine consentite
195
+ if (!this.ac.Initialized && !this.AlwaysAllowedRoots.find(r => url.indexOf(r) != -1))
196
+ return Promise.resolve(false);
197
+ var routeMatched = false;
198
+ for (let i = 0; i < this.Routes.length; i++) {
199
+ let r = this.Routes[i];
200
+ //Se faccio match con la route significa che ho navigato in una delle route conosciute, altrimenti avverto ma lascio andare
201
+ if (url.indexOf(r.route) != -1) {
202
+ routeMatched = true;
203
+ return this.handleMatch(url, r);
204
+ }
205
+ }
206
+ //Se non faccio nessun match ma ho una route wildcard (*) prendo quella e controllo su quella
207
+ if (!routeMatched) {
208
+ var wildcardRoute = this.Routes.find(r => r.route == "*");
209
+ if (wildcardRoute)
210
+ return this.handleMatch(url, wildcardRoute);
211
+ else
212
+ console.log("Navigaizone avvenuta su route sconosciuta: " + url);
213
+ }
214
+ return Promise.resolve(true);
215
+ }
216
+ /**
217
+ * @ignore
218
+ */
219
+ handleMatch(fromurl, r) {
220
+ let identity = this.ac.Identity;
221
+ if (this.ac.has(r.permission) ||
222
+ (
223
+ // Considero anche la possibilità di avere l'access control inizializzato ma che l'account scope non sia ancora presente
224
+ // in questo caso suppongo sia un hard refresh e mi fido del fatto che l'utente possa entrarci
225
+ // TODO: Fixare meglio concatenando una promise che va a prendere l'account scope se serve
226
+ this.ac.Initialized &&
227
+ (!identity.Roles || identity.Roles.length == 0) &&
228
+ (!identity.Permissions || identity.Permissions.length == 0)))
229
+ return Promise.resolve(true);
230
+ else {
231
+ //Se sono nel sito originale (non ho aperto un newtab) blocco la navigazione
232
+ //Se ho aperto una nuova tab invece rispedisco al login
233
+ if (window.history.length > 2 && this.ac.isLoggedIn()) {
234
+ this.msgService.simpleError(this.lc.loc("You don't have the required permissions to view this page. The navigation has been blocked"));
235
+ return Promise.resolve(false);
236
+ }
237
+ else {
238
+ this.onRedirectInProgress();
239
+ this.router.navigate([this.LoginRoute, { fromUrl: fromurl }]);
240
+ }
241
+ }
242
+ }
243
+ /**
244
+ * Callback che viene eseguito prima che la Guard reindirizzi al login
245
+ */
246
+ onRedirectInProgress() {
247
+ }
248
+ }
249
+ AccessControlRouteGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlRouteGuard, deps: [{ token: i1.MessageService }, { token: AccessControlService }, { token: i3.Router }, { token: ACC_LOCALE, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
250
+ AccessControlRouteGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlRouteGuard });
251
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlRouteGuard, decorators: [{
252
+ type: Injectable
253
+ }], ctorParameters: function () { return [{ type: i1.MessageService }, { type: AccessControlService }, { type: i3.Router }, { type: undefined, decorators: [{
254
+ type: Optional
255
+ }, {
256
+ type: Inject,
257
+ args: [ACC_LOCALE]
258
+ }] }]; } });
259
+
260
+ // Angular
261
+ /**
262
+ * Direttiva che permette di gestire il controllo accessi su componenti HTML.
263
+ *
264
+ * Per gli esempi di utilizzo fare riferimento al README.
265
+ */
266
+ class AccessControlDirective {
267
+ /**
268
+ * Costruttore
269
+ *
270
+ * @ignore
271
+ */
272
+ constructor(templateRef, viewContainer, _ac) {
273
+ this.templateRef = templateRef;
274
+ this.viewContainer = viewContainer;
275
+ this._ac = _ac;
276
+ }
277
+ /**
278
+ * Input autoreferenziale per la direttiva
279
+ *
280
+ * @param {string} expression espressione da processare scritta come {Chiave}:{Valore}
281
+ *
282
+ * Le {Chiave} disponibili sono di default "R" per i ruoli e "P" per i permessi. È possibile espanderle con le Custom Permissions
283
+ */
284
+ set ac(expression) {
285
+ var allow = this._ac.has(expression);
286
+ //Se ho i permessi, proseguo creando la vista nel DOM, altrimenti rimuovo il template
287
+ if (allow)
288
+ this.viewContainer.createEmbeddedView(this.templateRef);
289
+ else
290
+ this.viewContainer.clear();
291
+ }
292
+ }
293
+ AccessControlDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: AccessControlService }], target: i0.ɵɵFactoryTarget.Directive });
294
+ AccessControlDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.1.1", type: AccessControlDirective, selector: "[ac]", inputs: { ac: "ac" }, ngImport: i0 });
295
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlDirective, decorators: [{
296
+ type: Directive,
297
+ args: [{
298
+ selector: '[ac]',
299
+ }]
300
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: AccessControlService }]; }, propDecorators: { ac: [{
301
+ type: Input
302
+ }] } });
303
+
304
+ /**
305
+ * Token da iniettare per ogni singolo componente per cui si vuole disattivare/attivare massivamente degli input in maniera contestuale
306
+ */
307
+ class ComponentContext {
308
+ }
309
+ ComponentContext.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ComponentContext, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
310
+ ComponentContext.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ComponentContext });
311
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ComponentContext, decorators: [{
312
+ type: Injectable
313
+ }] });
314
+
315
+ // Angular
316
+ /**
317
+ * Direttiva che permette di capire se l'elemento HTML su cui è utilizzata dev'essere disabilitato o no.
318
+ *
319
+ * Non ha effetto sugli elementi dichiarati in componenti che non dichiarano alcun ComponentContext
320
+ */
321
+ class ContextAwareDirective {
322
+ /**
323
+ * Costruttore
324
+ *
325
+ * @ignore
326
+ */
327
+ constructor(element, context, ac, ACC_CUSTOMKEY) {
328
+ this.context = context;
329
+ this.ac = ac;
330
+ this.ACC_CUSTOMKEY = ACC_CUSTOMKEY;
331
+ var allow = !this.context || !this.context.name || !this.ACC_CUSTOMKEY || this.ac.has(this.ACC_CUSTOMKEY + ":" + this.context.name);
332
+ if (!allow)
333
+ element.nativeElement.setAttribute("enabled", "true");
334
+ }
335
+ }
336
+ ContextAwareDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ContextAwareDirective, deps: [{ token: i0.ElementRef }, { token: ComponentContext, optional: true }, { token: AccessControlService }, { token: ACC_CUSTOMKEY, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
337
+ ContextAwareDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.1.1", type: ContextAwareDirective, selector: "[contextAware]", ngImport: i0 });
338
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: ContextAwareDirective, decorators: [{
339
+ type: Directive,
340
+ args: [{
341
+ selector: '[contextAware]',
342
+ }]
343
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ComponentContext, decorators: [{
344
+ type: Optional
345
+ }] }, { type: AccessControlService }, { type: undefined, decorators: [{
346
+ type: Optional
347
+ }, {
348
+ type: Inject,
349
+ args: [ACC_CUSTOMKEY]
350
+ }] }]; } });
351
+
352
+ class AccessControlModule {
353
+ static forRoot(config) {
354
+ return {
355
+ ngModule: AccessControlModule,
356
+ providers: [
357
+ AccessControlService,
358
+ AccessControlRouteGuard,
359
+ { provide: ACC_LOCALE, useValue: config?.locale || 'it-IT' },
360
+ { provide: ACC_CUSTOMKEY, useValue: config?.customKey || null }
361
+ ]
362
+ };
363
+ }
364
+ }
365
+ AccessControlModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
366
+ AccessControlModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlModule, declarations: [AccessControlDirective, ContextAwareDirective], imports: [LocalizationModule], exports: [AccessControlDirective, ContextAwareDirective] });
367
+ AccessControlModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlModule, imports: [[LocalizationModule]] });
368
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: AccessControlModule, decorators: [{
369
+ type: NgModule,
370
+ args: [{
371
+ imports: [LocalizationModule],
372
+ declarations: [AccessControlDirective, ContextAwareDirective],
373
+ exports: [AccessControlDirective, ContextAwareDirective]
374
+ }]
375
+ }] });
376
+
377
+ /**
378
+ * Configurazione Modulo AccessControl. Se non fornita verrà generata automaticamente con locale 'it-IT'
379
+ */
380
+ class AccessControlModuleConfig {
381
+ }
382
+
383
+ /*
384
+ * Public API Surface of access-control
385
+ */
386
+
387
+ /**
388
+ * Generated bundle index. Do not edit.
389
+ */
390
+
391
+ export { ACC_CUSTOMKEY, ACC_LOCALE, AccessControlDirective, AccessControlModule, AccessControlModuleConfig, AccessControlRouteGuard, AccessControlService, ComponentContext, ContextAwareDirective };
392
+ //# sourceMappingURL=esfaenza-access-control.mjs.map