zoukankan      html  css  js  c++  java
  • jcasbin 自定义函数

    以下主要说明自定义函数的使用

    参考代码

    • 自定义函数
      MyDemoFunc
     
    public class MyDemoFunc extends CustomFunction {
     
        @Override
        public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
            String name1 = FunctionUtils.getStringValue(arg1, env); // 使用了提供的帮助类
            String name2 = FunctionUtils.getStringValue(arg2, env);
            System.out.println("=================from func==================");
            System.out.println(name1+name2);
            System.out.println("=================end func==================");
            if(name1.equalsIgnoreCase(name2)){
                return AviatorBoolean.valueOf(true);
            }else{
                return  AviatorBoolean.valueOf(false);
            }
        }
     
        @Override
        public String getName() {
            return "dalongmydemo";
        }
    }
    • 代码集成
    MyDemoFunc2  myDemoFunc = new MyDemoFunc2();
    Enforcer enforcer = new Enforcer("src/main/resources/model2.conf","src/main/resources/policy2.csv");
    enforcer.addFunction(myDemoFunc.getName(),myDemoFunc);
    List<List<String>> result = enforcer.getImplicitPermissionsForUserInDomain("alice","tenant1");
    System.out.println(result);
    Boolean result2 = enforcer.enforce("root1","dalong","oneservice", "read");
    System.out.println(result2);

    说明

    对于自定义函数是由enforce方法调用的,其他模式不好使,需要注意,其他模式比如role还有权限的需要开发独立的函数(就是简单的普通函数)

    参考资料

    https://casbin.org/docs/en/function

  • 相关阅读:
    hdu 5119 Happy Matt Friends
    hdu 5128 The E-pang Palace
    hdu 5131 Song Jiang's rank list
    hdu 5135 Little Zu Chongzhi's Triangles
    hdu 5137 How Many Maos Does the Guanxi Worth
    hdu 5122 K.Bro Sorting
    Human Gene Functions
    Palindrome(最长公共子序列)
    A Simple problem
    Alignment ( 最长上升(下降)子序列 )
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14887342.html
Copyright © 2011-2022 走看看