@authup/access 1.0.0-beta.26 → 1.0.0-beta.27
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/dist/index.cjs +131 -131
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +131 -131
- package/dist/index.mjs.map +1 -1
- package/dist/permission/types.d.ts +2 -2
- package/dist/permission/types.d.ts.map +1 -1
- package/dist/policy/built-in/attribute-names/evaluator.d.ts +4 -4
- package/dist/policy/built-in/attribute-names/evaluator.d.ts.map +1 -1
- package/dist/policy/built-in/attributes/evaluator.d.ts +3 -3
- package/dist/policy/built-in/attributes/evaluator.d.ts.map +1 -1
- package/dist/policy/built-in/composite/evaluator.d.ts +3 -3
- package/dist/policy/built-in/composite/evaluator.d.ts.map +1 -1
- package/dist/policy/built-in/date/evaluator.d.ts +3 -3
- package/dist/policy/built-in/date/evaluator.d.ts.map +1 -1
- package/dist/policy/built-in/identity/evaluator.d.ts +3 -3
- package/dist/policy/built-in/identity/evaluator.d.ts.map +1 -1
- package/dist/policy/built-in/permission-binding/module.d.ts +4 -4
- package/dist/policy/built-in/permission-binding/module.d.ts.map +1 -1
- package/dist/policy/built-in/realm-match/evaluator.d.ts +3 -3
- package/dist/policy/built-in/realm-match/evaluator.d.ts.map +1 -1
- package/dist/policy/built-in/time/evaluator.d.ts +3 -3
- package/dist/policy/built-in/time/evaluator.d.ts.map +1 -1
- package/dist/policy/evaluator/data/validator.d.ts +2 -2
- package/dist/policy/evaluator/data/validator.d.ts.map +1 -1
- package/dist/policy/evaluator/types.d.ts +11 -11
- package/dist/policy/evaluator/types.d.ts.map +1 -1
- package/dist/policy/types.d.ts +1 -1
- package/dist/policy/types.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -84,30 +84,30 @@ class AttributeNamesPolicyValidator extends Container {
|
|
|
84
84
|
|
|
85
85
|
class AttributeNamesPolicyEvaluator {
|
|
86
86
|
async can(ctx) {
|
|
87
|
-
return ctx.
|
|
87
|
+
return ctx.config.type === BuiltInPolicyType.ATTRIBUTE_NAMES;
|
|
88
88
|
}
|
|
89
|
-
async
|
|
90
|
-
return this.validator.run(ctx.
|
|
89
|
+
async validateConfig(ctx) {
|
|
90
|
+
return this.validator.run(ctx.config);
|
|
91
91
|
}
|
|
92
|
-
async
|
|
93
|
-
if (!isObject(ctx.
|
|
92
|
+
async validateInput(ctx) {
|
|
93
|
+
if (!isObject(ctx.input.attributes)) {
|
|
94
94
|
throw PolicyError.evaluatorContextInvalid();
|
|
95
95
|
}
|
|
96
|
-
return ctx.
|
|
96
|
+
return ctx.input;
|
|
97
97
|
}
|
|
98
98
|
async evaluate(ctx) {
|
|
99
|
-
if (!ctx.
|
|
99
|
+
if (!ctx.input.attributes) {
|
|
100
100
|
throw PolicyError.evaluatorContextInvalid();
|
|
101
101
|
}
|
|
102
|
-
const attributes = flattenObject(ctx.
|
|
102
|
+
const attributes = flattenObject(ctx.input.attributes);
|
|
103
103
|
const keys = Object.keys(attributes);
|
|
104
104
|
for(let i = 0; i < keys.length; i++){
|
|
105
|
-
const index = ctx.
|
|
105
|
+
const index = ctx.config.names.indexOf(keys[i]);
|
|
106
106
|
if (index === -1) {
|
|
107
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
107
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
110
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
111
111
|
}
|
|
112
112
|
constructor(){
|
|
113
113
|
this.validator = new AttributeNamesPolicyValidator();
|
|
@@ -133,24 +133,24 @@ class AttributesPolicyValidator extends Container {
|
|
|
133
133
|
|
|
134
134
|
class AttributesPolicyEvaluator {
|
|
135
135
|
async can(ctx) {
|
|
136
|
-
return ctx.
|
|
136
|
+
return ctx.config.type === BuiltInPolicyType.ATTRIBUTES;
|
|
137
137
|
}
|
|
138
|
-
async
|
|
139
|
-
return this.validator.run(ctx.
|
|
138
|
+
async validateConfig(ctx) {
|
|
139
|
+
return this.validator.run(ctx.config);
|
|
140
140
|
}
|
|
141
|
-
async
|
|
142
|
-
if (!isObject(ctx.
|
|
141
|
+
async validateInput(ctx) {
|
|
142
|
+
if (!isObject(ctx.input.attributes)) {
|
|
143
143
|
throw PolicyError.evaluatorContextInvalid();
|
|
144
144
|
}
|
|
145
|
-
return ctx.
|
|
145
|
+
return ctx.input;
|
|
146
146
|
}
|
|
147
147
|
async evaluate(ctx) {
|
|
148
|
-
if (!ctx.
|
|
148
|
+
if (!ctx.input.attributes) {
|
|
149
149
|
throw PolicyError.evaluatorContextInvalid();
|
|
150
150
|
}
|
|
151
|
-
this.fixQuery(ctx.
|
|
152
|
-
const testIt = guard(ctx.
|
|
153
|
-
return maybeInvertPolicyOutcome(testIt(ctx.
|
|
151
|
+
this.fixQuery(ctx.config.query);
|
|
152
|
+
const testIt = guard(ctx.config.query);
|
|
153
|
+
return maybeInvertPolicyOutcome(testIt(ctx.input.attributes), ctx.config.invert);
|
|
154
154
|
}
|
|
155
155
|
fixQuery(query) {
|
|
156
156
|
const keys = Object.keys(query);
|
|
@@ -238,31 +238,31 @@ class PolicyDataValidator extends Container {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
async function evaluatePolicy(ctx) {
|
|
241
|
-
if (ctx.options.exclude && ctx.options.exclude.length > 0 && ctx.options.exclude.indexOf(ctx.
|
|
242
|
-
if (typeof ctx.
|
|
243
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
241
|
+
if (ctx.options.exclude && ctx.options.exclude.length > 0 && ctx.options.exclude.indexOf(ctx.config.type) !== -1) {
|
|
242
|
+
if (typeof ctx.config.invert === 'boolean') {
|
|
243
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
244
244
|
}
|
|
245
245
|
return true;
|
|
246
246
|
}
|
|
247
|
-
if (ctx.options.include && ctx.options.include.length > 0 && ctx.options.include.indexOf(ctx.
|
|
248
|
-
if (typeof ctx.
|
|
249
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
247
|
+
if (ctx.options.include && ctx.options.include.length > 0 && ctx.options.include.indexOf(ctx.config.type) === -1) {
|
|
248
|
+
if (typeof ctx.config.invert === 'boolean') {
|
|
249
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
250
250
|
}
|
|
251
251
|
return true;
|
|
252
252
|
}
|
|
253
|
-
const evaluator = ctx.evaluators[ctx.
|
|
253
|
+
const evaluator = ctx.evaluators[ctx.config.type];
|
|
254
254
|
if (!evaluator) {
|
|
255
|
-
throw PolicyError.evaluatorNotFound(ctx.
|
|
255
|
+
throw PolicyError.evaluatorNotFound(ctx.config.type);
|
|
256
256
|
}
|
|
257
257
|
try {
|
|
258
258
|
const canEvaluate = await evaluator.can(ctx);
|
|
259
259
|
if (canEvaluate) {
|
|
260
|
-
const
|
|
261
|
-
const
|
|
260
|
+
const config = await evaluator.validateConfig(ctx);
|
|
261
|
+
const input = await evaluator.validateInput(ctx);
|
|
262
262
|
return await evaluator.evaluate({
|
|
263
263
|
...ctx,
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
input,
|
|
265
|
+
config
|
|
266
266
|
});
|
|
267
267
|
}
|
|
268
268
|
} catch (e) {
|
|
@@ -296,44 +296,44 @@ class CompositePolicyValidator extends Container {
|
|
|
296
296
|
|
|
297
297
|
class CompositePolicyEvaluator {
|
|
298
298
|
async can(ctx) {
|
|
299
|
-
return isCompositePolicy(ctx.
|
|
299
|
+
return isCompositePolicy(ctx.config);
|
|
300
300
|
}
|
|
301
|
-
async
|
|
302
|
-
return this.validator.run(ctx.
|
|
301
|
+
async validateConfig(ctx) {
|
|
302
|
+
return this.validator.run(ctx.config);
|
|
303
303
|
}
|
|
304
|
-
async
|
|
305
|
-
return ctx.
|
|
304
|
+
async validateInput(ctx) {
|
|
305
|
+
return ctx.input;
|
|
306
306
|
}
|
|
307
307
|
async evaluate(ctx) {
|
|
308
308
|
let count = 0;
|
|
309
|
-
const decisionStrategy = ctx.
|
|
310
|
-
for(let i = 0; i < ctx.
|
|
311
|
-
const childPolicy = ctx.
|
|
309
|
+
const decisionStrategy = ctx.config.decisionStrategy ?? DecisionStrategy.UNANIMOUS;
|
|
310
|
+
for(let i = 0; i < ctx.config.children.length; i++){
|
|
311
|
+
const childPolicy = ctx.config.children[i];
|
|
312
312
|
let outcome;
|
|
313
313
|
if (isCompositePolicy(childPolicy)) {
|
|
314
314
|
outcome = await this.evaluate({
|
|
315
315
|
...ctx,
|
|
316
|
-
|
|
316
|
+
config: childPolicy
|
|
317
317
|
});
|
|
318
318
|
} else {
|
|
319
319
|
outcome = await evaluatePolicy({
|
|
320
320
|
...ctx,
|
|
321
|
-
|
|
321
|
+
config: childPolicy
|
|
322
322
|
});
|
|
323
323
|
}
|
|
324
324
|
if (outcome) {
|
|
325
325
|
if (decisionStrategy === DecisionStrategy.AFFIRMATIVE) {
|
|
326
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
326
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
327
327
|
}
|
|
328
328
|
count++;
|
|
329
329
|
} else {
|
|
330
330
|
if (decisionStrategy === DecisionStrategy.UNANIMOUS) {
|
|
331
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
331
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
332
332
|
}
|
|
333
333
|
count--;
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
|
-
return maybeInvertPolicyOutcome(count > 0, ctx.
|
|
336
|
+
return maybeInvertPolicyOutcome(count > 0, ctx.config.invert);
|
|
337
337
|
}
|
|
338
338
|
constructor(){
|
|
339
339
|
this.validator = new CompositePolicyValidator();
|
|
@@ -363,34 +363,34 @@ function toDate$1(input) {
|
|
|
363
363
|
}
|
|
364
364
|
class DatePolicyEvaluator {
|
|
365
365
|
async can(ctx) {
|
|
366
|
-
return ctx.
|
|
366
|
+
return ctx.config.type === BuiltInPolicyType.DATE;
|
|
367
367
|
}
|
|
368
|
-
async
|
|
369
|
-
return this.validator.run(ctx.
|
|
368
|
+
async validateConfig(ctx) {
|
|
369
|
+
return this.validator.run(ctx.config);
|
|
370
370
|
}
|
|
371
|
-
async
|
|
372
|
-
return ctx.
|
|
371
|
+
async validateInput(ctx) {
|
|
372
|
+
return ctx.input;
|
|
373
373
|
}
|
|
374
374
|
async evaluate(ctx) {
|
|
375
375
|
let now;
|
|
376
|
-
if (ctx.
|
|
377
|
-
now = normalizeDate$1(toDate$1(ctx.
|
|
376
|
+
if (ctx.input.dateTime) {
|
|
377
|
+
now = normalizeDate$1(toDate$1(ctx.input.dateTime));
|
|
378
378
|
} else {
|
|
379
379
|
now = normalizeDate$1(new Date());
|
|
380
380
|
}
|
|
381
|
-
if (ctx.
|
|
382
|
-
const start = normalizeDate$1(toDate$1(ctx.
|
|
381
|
+
if (ctx.config.start) {
|
|
382
|
+
const start = normalizeDate$1(toDate$1(ctx.config.start));
|
|
383
383
|
if (now < start) {
|
|
384
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
384
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
|
-
if (ctx.
|
|
388
|
-
const end = normalizeDate$1(toDate$1(ctx.
|
|
387
|
+
if (ctx.config.end) {
|
|
388
|
+
const end = normalizeDate$1(toDate$1(ctx.config.end));
|
|
389
389
|
if (now > end) {
|
|
390
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
390
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
393
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
394
394
|
}
|
|
395
395
|
constructor(){
|
|
396
396
|
this.validator = new DatePolicyValidator();
|
|
@@ -406,24 +406,24 @@ class IdentityPolicyValidator extends Container {
|
|
|
406
406
|
|
|
407
407
|
class IdentityPolicyEvaluator {
|
|
408
408
|
async can(ctx) {
|
|
409
|
-
return ctx.
|
|
409
|
+
return ctx.config.type === BuiltInPolicyType.IDENTITY;
|
|
410
410
|
}
|
|
411
|
-
async
|
|
412
|
-
return this.validator.run(ctx.
|
|
411
|
+
async validateConfig(ctx) {
|
|
412
|
+
return this.validator.run(ctx.config);
|
|
413
413
|
}
|
|
414
|
-
async
|
|
415
|
-
return ctx.
|
|
414
|
+
async validateInput(ctx) {
|
|
415
|
+
return ctx.input;
|
|
416
416
|
}
|
|
417
417
|
async evaluate(ctx) {
|
|
418
|
-
if (!isObject(ctx.
|
|
419
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
418
|
+
if (!isObject(ctx.input.identity)) {
|
|
419
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
420
420
|
}
|
|
421
|
-
const types = ctx.
|
|
421
|
+
const types = ctx.config.types || [];
|
|
422
422
|
if (types.length === 0) {
|
|
423
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
423
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
424
424
|
}
|
|
425
|
-
const typeAllowed = types.indexOf(ctx.
|
|
426
|
-
return maybeInvertPolicyOutcome(typeAllowed, ctx.
|
|
425
|
+
const typeAllowed = types.indexOf(ctx.input.identity.type) !== -1;
|
|
426
|
+
return maybeInvertPolicyOutcome(typeAllowed, ctx.config.invert);
|
|
427
427
|
}
|
|
428
428
|
constructor(){
|
|
429
429
|
this.validator = new IdentityPolicyValidator();
|
|
@@ -436,20 +436,20 @@ class PermissionBindingPolicyValidator extends Container {
|
|
|
436
436
|
|
|
437
437
|
class PermissionBindingPolicyEvaluator {
|
|
438
438
|
async can(ctx) {
|
|
439
|
-
return ctx.
|
|
439
|
+
return ctx.config.type === BuiltInPolicyType.PERMISSION_BINDING;
|
|
440
440
|
}
|
|
441
|
-
async
|
|
442
|
-
return this.validator.run(ctx.
|
|
441
|
+
async validateConfig(ctx) {
|
|
442
|
+
return this.validator.run(ctx.config);
|
|
443
443
|
}
|
|
444
|
-
async
|
|
445
|
-
if (!isObject(ctx.
|
|
444
|
+
async validateInput(ctx) {
|
|
445
|
+
if (!isObject(ctx.input.identity) && !isObject(ctx.input.permission)) {
|
|
446
446
|
throw PolicyError.evaluatorContextInvalid();
|
|
447
447
|
}
|
|
448
|
-
return ctx.
|
|
448
|
+
return ctx.input;
|
|
449
449
|
}
|
|
450
450
|
async evaluate(ctx) {
|
|
451
451
|
// todo: this must be changed when the permission-checker not only checks owned permissions.
|
|
452
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
452
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
453
453
|
}
|
|
454
454
|
constructor(){
|
|
455
455
|
this.validator = new PermissionBindingPolicyValidator();
|
|
@@ -470,32 +470,32 @@ class RealmMatchPolicyValidator extends Container {
|
|
|
470
470
|
|
|
471
471
|
class RealmMatchPolicyEvaluator {
|
|
472
472
|
async can(ctx) {
|
|
473
|
-
return ctx.
|
|
473
|
+
return ctx.config.type === BuiltInPolicyType.REALM_MATCH;
|
|
474
474
|
}
|
|
475
|
-
async
|
|
476
|
-
return this.validator.run(ctx.
|
|
475
|
+
async validateConfig(ctx) {
|
|
476
|
+
return this.validator.run(ctx.config);
|
|
477
477
|
}
|
|
478
|
-
async
|
|
479
|
-
if (!isObject(ctx.
|
|
478
|
+
async validateInput(ctx) {
|
|
479
|
+
if (!isObject(ctx.input.attributes) || !isObject(ctx.input.identity)) {
|
|
480
480
|
throw PolicyError.evaluatorContextInvalid();
|
|
481
481
|
}
|
|
482
|
-
return ctx.
|
|
482
|
+
return ctx.input;
|
|
483
483
|
}
|
|
484
484
|
async evaluate(ctx) {
|
|
485
|
-
if (!ctx.
|
|
485
|
+
if (!ctx.input.attributes || !ctx.input.identity) {
|
|
486
486
|
throw PolicyError.evaluatorContextInvalid();
|
|
487
487
|
}
|
|
488
|
-
const identityMasterMatchAll = ctx.
|
|
489
|
-
if (identityMasterMatchAll && ctx.
|
|
490
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
488
|
+
const identityMasterMatchAll = ctx.config.identityMasterMatchAll ?? true;
|
|
489
|
+
if (identityMasterMatchAll && ctx.input.identity.realmName && ctx.input.identity.realmName === 'master') {
|
|
490
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
491
491
|
}
|
|
492
492
|
let keys;
|
|
493
|
-
if (ctx.
|
|
494
|
-
if (Array.isArray(ctx.
|
|
495
|
-
keys = ctx.
|
|
493
|
+
if (ctx.config.attributeName) {
|
|
494
|
+
if (Array.isArray(ctx.config.attributeName)) {
|
|
495
|
+
keys = ctx.config.attributeName;
|
|
496
496
|
} else {
|
|
497
497
|
keys = [
|
|
498
|
-
ctx.
|
|
498
|
+
ctx.config.attributeName
|
|
499
499
|
];
|
|
500
500
|
}
|
|
501
501
|
} else {
|
|
@@ -505,11 +505,11 @@ class RealmMatchPolicyEvaluator {
|
|
|
505
505
|
'realmId',
|
|
506
506
|
'realmName'
|
|
507
507
|
];
|
|
508
|
-
ctx.
|
|
508
|
+
ctx.config.decisionStrategy = DecisionStrategy.CONSENSUS;
|
|
509
509
|
}
|
|
510
|
-
const attributeNameStrict = ctx.
|
|
510
|
+
const attributeNameStrict = ctx.config.attributeNameStrict ?? true;
|
|
511
511
|
if (!attributeNameStrict) {
|
|
512
|
-
const resourceKeys = Object.keys(ctx.
|
|
512
|
+
const resourceKeys = Object.keys(ctx.input.attributes);
|
|
513
513
|
const keysToAdd = [];
|
|
514
514
|
for(let i = 0; i < resourceKeys.length; i++){
|
|
515
515
|
let contains = false;
|
|
@@ -529,29 +529,29 @@ class RealmMatchPolicyEvaluator {
|
|
|
529
529
|
}
|
|
530
530
|
let count = 0;
|
|
531
531
|
for(let i = 0; i < keys.length; i++){
|
|
532
|
-
if (!hasOwnProperty(ctx.
|
|
532
|
+
if (!hasOwnProperty(ctx.input.attributes, keys[i])) {
|
|
533
533
|
continue;
|
|
534
534
|
}
|
|
535
535
|
let outcome = false;
|
|
536
|
-
const attributeValue = ctx.
|
|
537
|
-
if (attributeValue === null && ctx.
|
|
536
|
+
const attributeValue = ctx.input.attributes[keys[i]];
|
|
537
|
+
if (attributeValue === null && ctx.config.attributeNullMatchAll) {
|
|
538
538
|
outcome = true;
|
|
539
|
-
} else if (attributeValue === ctx.
|
|
539
|
+
} else if (attributeValue === ctx.input.identity.realmId || attributeValue === ctx.input.identity.realmName) {
|
|
540
540
|
outcome = true;
|
|
541
541
|
}
|
|
542
542
|
if (outcome) {
|
|
543
|
-
if (ctx.
|
|
544
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
543
|
+
if (ctx.config.decisionStrategy === DecisionStrategy.AFFIRMATIVE) {
|
|
544
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
545
545
|
}
|
|
546
546
|
count++;
|
|
547
547
|
} else {
|
|
548
|
-
if (ctx.
|
|
549
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
548
|
+
if (ctx.config.decisionStrategy === DecisionStrategy.UNANIMOUS) {
|
|
549
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
550
550
|
}
|
|
551
551
|
count--;
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
|
-
return maybeInvertPolicyOutcome(count > 0, ctx.
|
|
554
|
+
return maybeInvertPolicyOutcome(count > 0, ctx.config.invert);
|
|
555
555
|
}
|
|
556
556
|
constructor(){
|
|
557
557
|
this.validator = new RealmMatchPolicyValidator();
|
|
@@ -617,55 +617,55 @@ function toDate(input, dateRef) {
|
|
|
617
617
|
}
|
|
618
618
|
class TimePolicyEvaluator {
|
|
619
619
|
async can(ctx) {
|
|
620
|
-
return ctx.
|
|
620
|
+
return ctx.config.type === BuiltInPolicyType.TIME;
|
|
621
621
|
}
|
|
622
|
-
async
|
|
623
|
-
return this.validator.run(ctx.
|
|
622
|
+
async validateConfig(ctx) {
|
|
623
|
+
return this.validator.run(ctx.config);
|
|
624
624
|
}
|
|
625
|
-
async
|
|
626
|
-
return ctx.
|
|
625
|
+
async validateInput(ctx) {
|
|
626
|
+
return ctx.input;
|
|
627
627
|
}
|
|
628
628
|
async evaluate(ctx) {
|
|
629
629
|
let now;
|
|
630
|
-
if (ctx.
|
|
631
|
-
now = toDate(ctx.
|
|
630
|
+
if (ctx.input.dateTime) {
|
|
631
|
+
now = toDate(ctx.input.dateTime);
|
|
632
632
|
} else {
|
|
633
633
|
now = new Date();
|
|
634
634
|
}
|
|
635
|
-
if (ctx.
|
|
636
|
-
const start = normalizeDate(toDate(ctx.
|
|
635
|
+
if (ctx.config.start) {
|
|
636
|
+
const start = normalizeDate(toDate(ctx.config.start, now), now);
|
|
637
637
|
if (now < start) {
|
|
638
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
638
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
|
-
if (ctx.
|
|
642
|
-
const end = normalizeDate(toDate(ctx.
|
|
641
|
+
if (ctx.config.end) {
|
|
642
|
+
const end = normalizeDate(toDate(ctx.config.end, now), now);
|
|
643
643
|
if (now > end) {
|
|
644
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
644
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
|
-
if (ctx.
|
|
648
|
-
if (isIntervalForDayOfWeek(ctx.
|
|
649
|
-
if (now.getDay() !== ctx.
|
|
650
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
647
|
+
if (ctx.config.interval) {
|
|
648
|
+
if (isIntervalForDayOfWeek(ctx.config.interval) && ctx.config.dayOfWeek) {
|
|
649
|
+
if (now.getDay() !== ctx.config.dayOfWeek) {
|
|
650
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
|
-
if (isIntervalForDayOfMonth(ctx.
|
|
654
|
-
if (now.getDate() !== ctx.
|
|
655
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
653
|
+
if (isIntervalForDayOfMonth(ctx.config.interval) && ctx.config.dayOfMonth) {
|
|
654
|
+
if (now.getDate() !== ctx.config.dayOfMonth) {
|
|
655
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
656
656
|
}
|
|
657
657
|
}
|
|
658
|
-
if (isIntervalForDayOfYear(ctx.
|
|
658
|
+
if (isIntervalForDayOfYear(ctx.config.interval) && ctx.config.dayOfYear) {
|
|
659
659
|
const start = new Date(now.getFullYear(), 0, 0);
|
|
660
660
|
const diff = now.getTime() - start.getTime() + (start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000;
|
|
661
661
|
const oneDay = 1000 * 60 * 60 * 24;
|
|
662
662
|
const dayOfYear = Math.floor(diff / oneDay);
|
|
663
|
-
if (dayOfYear !== ctx.
|
|
664
|
-
return maybeInvertPolicyOutcome(false, ctx.
|
|
663
|
+
if (dayOfYear !== ctx.config.dayOfYear) {
|
|
664
|
+
return maybeInvertPolicyOutcome(false, ctx.config.invert);
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
|
-
return maybeInvertPolicyOutcome(true, ctx.
|
|
668
|
+
return maybeInvertPolicyOutcome(true, ctx.config.invert);
|
|
669
669
|
}
|
|
670
670
|
constructor(){
|
|
671
671
|
this.validator = new TimePolicyValidator();
|
|
@@ -901,11 +901,11 @@ class PermissionChecker {
|
|
|
901
901
|
let outcome;
|
|
902
902
|
try {
|
|
903
903
|
outcome = await this.policyEngine.evaluate({
|
|
904
|
-
|
|
905
|
-
...ctx.
|
|
904
|
+
input: {
|
|
905
|
+
...ctx.input || {},
|
|
906
906
|
permission: entity
|
|
907
907
|
},
|
|
908
|
-
|
|
908
|
+
config: entity.policy,
|
|
909
909
|
options: {
|
|
910
910
|
include: options.policiesIncluded,
|
|
911
911
|
exclude: options.policiesExcluded
|