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