Class DistributedEnforcer


public class DistributedEnforcer extends SyncedEnforcer
DistributedEnforcer wraps SyncedEnforcer for dispatcher.
  • Constructor Details

    • DistributedEnforcer

      public DistributedEnforcer()
      DistributedEnforcer is the default constructor.
    • DistributedEnforcer

      public DistributedEnforcer(String modelPath, String policyFile)
      DistributedEnforcer initializes an enforcer with a model file and a policy file.
      Parameters:
      modelPath - the path of the model file.
      policyFile - the path of the policy file.
    • DistributedEnforcer

      public DistributedEnforcer(String modelPath, Adapter adapter)
      DistributedEnforcer initializes an enforcer with a database adapter.
      Parameters:
      modelPath - the path of the model file.
      adapter - the adapter.
    • DistributedEnforcer

      public DistributedEnforcer(Model m, Adapter adapter)
      DistributedEnforcer initializes an enforcer with a model and a database adapter.
      Parameters:
      m - the model.
      adapter - the adapter.
    • DistributedEnforcer

      public DistributedEnforcer(Model m)
      DistributedEnforcer initializes an enforcer with a model.
      Parameters:
      m - the model.
    • DistributedEnforcer

      public DistributedEnforcer(String modelPath)
      DistributedEnforcer initializes an enforcer with a model file.
      Parameters:
      modelPath - the path of the model file.
    • DistributedEnforcer

      public DistributedEnforcer(String modelPath, String policyFile, boolean enableLog)
      DistributedEnforcer initializes an enforcer with a model file, a policy file and an enable log flag.
      Parameters:
      modelPath - the path of the model file.
      policyFile - the path of the policy file.
      enableLog - whether to enable Casbin's log.
  • Method Details

    • addPolicySelf

      public List<List<String>> addPolicySelf(BooleanSupplier shouldPersist, String sec, String ptype, List<List<String>> rules)
      AddPolicySelf provides a method for dispatcher to add authorization rules to the current policy. The function returns the rules affected and error.
      Parameters:
      shouldPersist - whether the changes should be persisted.
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      rules - the rules.
      Returns:
      succeeds or not.
    • removePolicySelf

      public List<List<String>> removePolicySelf(BooleanSupplier shouldPersist, String sec, String ptype, List<List<String>> rules)
      RemovePolicySelf provides a method for dispatcher to remove policies from current policy. The function returns the rules affected and error.
      Parameters:
      shouldPersist - whether the changes should be persisted.
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      rules - the rules.
      Returns:
      succeeds or not.
    • removeFilteredPolicySelf

      public List<List<String>> removeFilteredPolicySelf(BooleanSupplier shouldPersist, String sec, String ptype, int fieldIndex, String... fieldValues)
      RemoveFilteredPolicySelf provides a method for dispatcher to remove an authorization rule from the current policy, field filters can be specified. The function returns the rules affected and error.
      Parameters:
      shouldPersist - whether the changes should be persisted.
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      fieldIndex - the policy rule's start index to be matched.
      fieldValues - the field values to be matched, value "" means not to match this field.
      Returns:
      succeeds or not.
    • clearPolicySelf

      public void clearPolicySelf(BooleanSupplier shouldPersist)
      ClearPolicySelf provides a method for dispatcher to clear all rules from the current policy.
      Parameters:
      shouldPersist - whether the changes should be persisted.
    • updatePolicySelf

      public boolean updatePolicySelf(BooleanSupplier shouldPersist, String sec, String ptype, List<String> oldRule, List<String> newRule)
      UpdatePolicySelf provides a method for dispatcher to update an authorization rule from the current policy.
      Parameters:
      shouldPersist - whether the changes should be persisted.
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      oldRule - the old rule.
      newRule - the new rule.
      Returns:
      succeeds or not.