@@ -103,8 +103,8 @@ public static Model newModel(String text) {
103
103
* newModel creates a model.
104
104
*
105
105
* @param modelPath the path of the model file.
106
- * @param unused unused parameter, just for differentiating with
107
- * newModel(String text).
106
+ * @param unused unused parameter, just for differentiating with
107
+ * newModel(String text).
108
108
* @return the model.
109
109
*/
110
110
public static Model newModel (String modelPath , String unused ) {
@@ -227,7 +227,7 @@ public void setRoleManager(RoleManager rm) {
227
227
* setNamedRoleManager sets the role manager for the named policy.
228
228
*
229
229
* @param ptype the policy type.
230
- * @param rm the role manager.
230
+ * @param rm the role manager.
231
231
*/
232
232
public void setNamedRoleManager (String ptype , RoleManager rm ) {
233
233
setRoleManager (ptype , rm );
@@ -355,11 +355,11 @@ private void initRmMap() {
355
355
}
356
356
}
357
357
358
- private void initBuiltInFunction (){
358
+ private void initBuiltInFunction () {
359
359
for (Map .Entry <String , AviatorFunction > entry : fm .fm .entrySet ()) {
360
360
AviatorFunction function = entry .getValue ();
361
361
362
- if (aviatorEval .containsFunction (function .getName ())){
362
+ if (aviatorEval .containsFunction (function .getName ())) {
363
363
aviatorEval .removeFunction (function .getName ());
364
364
}
365
365
aviatorEval .addFunction (function );
@@ -444,10 +444,10 @@ private EnforceResult enforce(String matcher, Object... rvals) {
444
444
}
445
445
446
446
boolean compileCached = true ;
447
- if (fm .isModify ){
447
+ if (fm .isModify ) {
448
448
compileCached = false ;
449
449
initBuiltInFunction ();
450
- fm .isModify = false ;
450
+ fm .isModify = false ;
451
451
}
452
452
Map <String , AviatorFunction > gFunctions = new HashMap <>();
453
453
if (model .model .containsKey ("g" )) {
@@ -489,7 +489,7 @@ private EnforceResult enforce(String matcher, Object... rvals) {
489
489
490
490
expString = Util .convertInSyntax (expString );
491
491
// Use md5 encryption as cacheKey to prevent expString from being too long
492
- Expression expression = aviatorEval .compile (Util .md5 (expString ),expString , compileCached );
492
+ Expression expression = aviatorEval .compile (Util .md5 (expString ), expString , compileCached );
493
493
494
494
StreamEffector streamEffector = null ;
495
495
try {
@@ -510,8 +510,8 @@ private EnforceResult enforce(String matcher, Object... rvals) {
510
510
for (int i = 0 ; i < model .model .get ("p" ).get (pType ).policy .size (); i ++) {
511
511
List <String > pvals = model .model .get ("p" ).get (pType ).policy .get (i );
512
512
if (model .model .get ("p" ).get (pType ).tokens .length != pvals .size ()) {
513
- throw new CasbinMatcherException ("invalid request size: expected " + model .model .get ("p" ).get (pType ).tokens .length +
514
- ", got " + pvals .size ()+ ", rvals: " + Arrays .toString (rvals ));
513
+ throw new CasbinMatcherException ("invalid request size: expected " + model .model .get ("p" ).get (pType ).tokens .length +
514
+ ", got " + pvals .size () + ", rvals: " + Arrays .toString (rvals ));
515
515
}
516
516
517
517
// Util.logPrint("Policy Rule: " + pvals);
@@ -535,18 +535,18 @@ private EnforceResult enforce(String matcher, Object... rvals) {
535
535
if (streamEffector == null ) {
536
536
continue ;
537
537
}
538
- } else if (result instanceof Float ) {
539
- if ((float ) result == 0 ) {
538
+ } else if (result instanceof Double || result instanceof Long ) {
539
+ if ((( Number ) result ). floatValue () == 0 ) {
540
540
policyEffects [i ] = Effect .Indeterminate ;
541
541
} else {
542
- matcherResults [i ] = (float ) result ;
542
+ matcherResults [i ] = (( Number ) result ). floatValue () ;
543
543
policyEffects [i ] = Effect .Allow ;
544
544
}
545
545
if (streamEffector == null ) {
546
546
continue ;
547
547
}
548
548
} else {
549
- throw new CasbinMatcherException ("matcher result should be bool, int or float " );
549
+ throw new CasbinMatcherException ("matcher result should be Boolean, Double or Long " );
550
550
}
551
551
if (policyEffects [i ] == Effect .Allow && parameters .containsKey (pType + "_eft" )) {
552
552
String eft = (String ) parameters .get (pType + "_eft" );
@@ -675,12 +675,12 @@ public EnforceResult enforceExWithMatcher(String matcher, Object... rvals) {
675
675
/**
676
676
* addNamedMatchingFunc add MatchingFunc by ptype RoleManager
677
677
*/
678
- public boolean addNamedMatchingFunc (String ptype , String name , BiPredicate <String , String > fn ){
679
- if (rmMap .containsKey (ptype )){
678
+ public boolean addNamedMatchingFunc (String ptype , String name , BiPredicate <String , String > fn ) {
679
+ if (rmMap .containsKey (ptype )) {
680
680
DomainManager rm = (DomainManager ) rmMap .get (ptype );
681
681
rm .addMatchingFunc (name , fn );
682
682
clearRmMap ();
683
- if (autoBuildRoleLinks ){
683
+ if (autoBuildRoleLinks ) {
684
684
buildRoleLinks ();
685
685
}
686
686
return true ;
@@ -691,12 +691,12 @@ public boolean addNamedMatchingFunc(String ptype, String name, BiPredicate<Strin
691
691
/**
692
692
* addNamedMatchingFunc add MatchingFunc by ptype RoleManager
693
693
*/
694
- public boolean addNamedDomainMatchingFunc (String ptype , String name , BiPredicate <String , String > fn ){
695
- if (rmMap .containsKey (ptype )){
694
+ public boolean addNamedDomainMatchingFunc (String ptype , String name , BiPredicate <String , String > fn ) {
695
+ if (rmMap .containsKey (ptype )) {
696
696
DomainManager rm = (DomainManager ) rmMap .get (ptype );
697
697
rm .addDomainMatchingFunc (name , fn );
698
698
clearRmMap ();
699
- if (autoBuildRoleLinks ){
699
+ if (autoBuildRoleLinks ) {
700
700
buildRoleLinks ();
701
701
}
702
702
return true ;
@@ -763,6 +763,6 @@ public void setAutoNotifyDispatcher(boolean autoNotifyDispatcher) {
763
763
}
764
764
765
765
protected boolean mustUseDispatcher () {
766
- return this .dispatcher != null && this .autoNotifyDispatcher ;
766
+ return this .dispatcher != null && this .autoNotifyDispatcher ;
767
767
}
768
768
}
0 commit comments