Class DistributedEnforcer


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

      • DistributedEnforcer

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

        public DistributedEnforcer​(java.lang.String modelPath,
                                   java.lang.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​(java.lang.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​(java.lang.String modelPath)
        DistributedEnforcer initializes an enforcer with a model file.
        Parameters:
        modelPath - the path of the model file.
      • DistributedEnforcer

        public DistributedEnforcer​(java.lang.String modelPath,
                                   java.lang.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 Detail

      • addPolicySelf

        public java.util.List<java.util.List<java.lang.String>> addPolicySelf​(java.util.function.BooleanSupplier shouldPersist,
                                                                              java.lang.String sec,
                                                                              java.lang.String ptype,
                                                                              java.util.List<java.util.List<java.lang.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 java.util.List<java.util.List<java.lang.String>> removePolicySelf​(java.util.function.BooleanSupplier shouldPersist,
                                                                                 java.lang.String sec,
                                                                                 java.lang.String ptype,
                                                                                 java.util.List<java.util.List<java.lang.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 java.util.List<java.util.List<java.lang.String>> removeFilteredPolicySelf​(java.util.function.BooleanSupplier shouldPersist,
                                                                                         java.lang.String sec,
                                                                                         java.lang.String ptype,
                                                                                         int fieldIndex,
                                                                                         java.lang.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​(java.util.function.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​(java.util.function.BooleanSupplier shouldPersist,
                                        java.lang.String sec,
                                        java.lang.String ptype,
                                        java.util.List<java.lang.String> oldRule,
                                        java.util.List<java.lang.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.