@@ -57,12 +57,6 @@ public class CoreEnforcer {
57
57
boolean autoNotifyWatcher = true ;
58
58
boolean autoNotifyDispatcher = true ;
59
59
60
- // cached instance of AviatorEvaluatorInstance
61
- AviatorEvaluatorInstance aviatorEval ;
62
-
63
- // detect changes in Model so that we can invalidate AviatorEvaluatorInstance cache
64
- int modelModCount ;
65
-
66
60
void initialize () {
67
61
rmMap = new HashMap <>();
68
62
eft = new DefaultEffector ();
@@ -129,7 +123,6 @@ public void loadModel() {
129
123
model .loadModel (this .modelPath );
130
124
model .printModel ();
131
125
fm = FunctionMap .loadFunctionMap ();
132
- aviatorEval = null ;
133
126
}
134
127
135
128
/**
@@ -149,7 +142,6 @@ public Model getModel() {
149
142
public void setModel (Model model ) {
150
143
this .model = model ;
151
144
fm = FunctionMap .loadFunctionMap ();
152
- aviatorEval = null ;
153
145
}
154
146
155
147
/**
@@ -399,37 +391,31 @@ private boolean enforce(String matcher, Object... rvals) {
399
391
if (!enabled ) {
400
392
return true ;
401
393
}
402
- if (aviatorEval == null || modelModCount != model .getModCount ()) {
403
- synchronized (this ) {
404
- if (aviatorEval == null || modelModCount != model .getModCount ()) {
405
- // AviatorEvaluator instance must be rebuild
406
- Map <String , AviatorFunction > functions = new HashMap <>();
407
- for (Map .Entry <String , AviatorFunction > entry : fm .fm .entrySet ()) {
408
- String key = entry .getKey ();
409
- AviatorFunction function = entry .getValue ();
410
-
411
- functions .put (key , function );
412
- }
413
- if (model .model .containsKey ("g" )) {
414
- for (Map .Entry <String , Assertion > entry : model .model .get ("g" ).entrySet ()) {
415
- String key = entry .getKey ();
416
- Assertion ast = entry .getValue ();
417
-
418
- RoleManager rm = ast .rm ;
419
- functions .put (key , BuiltInFunctions .generateGFunction (key , rm ));
420
- }
421
- }
422
394
423
- aviatorEval = AviatorEvaluator .newInstance ();
424
- for (AviatorFunction f : functions .values ()) {
425
- aviatorEval .addFunction (f );
426
- }
427
- fm .setAviatorEval (aviatorEval );
395
+ Map <String , AviatorFunction > functions = new HashMap <>();
396
+ for (Map .Entry <String , AviatorFunction > entry : fm .fm .entrySet ()) {
397
+ String key = entry .getKey ();
398
+ AviatorFunction function = entry .getValue ();
428
399
429
- modelModCount = model .getModCount ();
430
- }
400
+ functions .put (key , function );
401
+ }
402
+ if (model .model .containsKey ("g" )) {
403
+ for (Map .Entry <String , Assertion > entry : model .model .get ("g" ).entrySet ()) {
404
+ String key = entry .getKey ();
405
+ Assertion ast = entry .getValue ();
406
+
407
+ RoleManager rm = ast .rm ;
408
+ functions .put (key , BuiltInFunctions .generateGFunction (key , rm ));
409
+ }
410
+ }
411
+ AviatorEvaluatorInstance aviatorEval = AviatorEvaluator .newInstance ();
412
+ for (AviatorFunction f : functions .values ()) {
413
+ if (aviatorEval .containsFunction (f .getName ())) {
414
+ aviatorEval .removeFunction (f .getName ());
431
415
}
416
+ aviatorEval .addFunction (f );
432
417
}
418
+ fm .setAviatorEval (aviatorEval );
433
419
434
420
String expString ;
435
421
if (matcher == null || "" .equals (matcher )) {
@@ -599,7 +585,6 @@ private boolean validateEnforceSection(String section, Object... rvals) {
599
585
* need to call it explicitly if you manipulate directly Model.
600
586
*/
601
587
public void resetExpressionEvaluator () {
602
- aviatorEval = null ;
603
588
fm .setAviatorEval (null );
604
589
}
605
590
0 commit comments