Class FileAdapter

java.lang.Object
org.casbin.jcasbin.persist.file_adapter.FileAdapter
All Implemented Interfaces:
Adapter

public class FileAdapter extends Object implements Adapter
FileAdapter is the file adapter for Casbin. It can load policy from file or save policy to file.
  • Field Details

    • filePath

      private String filePath
    • readOnly

      private boolean readOnly
    • byteArrayInputStream

      private ByteArrayInputStream byteArrayInputStream
  • Constructor Details

    • FileAdapter

      public FileAdapter(String filePath)
      FileAdapter is the constructor for FileAdapter.
      Parameters:
      filePath - the path of the policy file.
    • FileAdapter

      public FileAdapter(InputStream inputStream)
      FileAdapter is the constructor for FileAdapter.
      Parameters:
      inputStream - the policy file.inputStream
  • Method Details

    • loadPolicy

      public void loadPolicy(Model model)
      loadPolicy loads all policy rules from the storage.
      Specified by:
      loadPolicy in interface Adapter
      Parameters:
      model - the model.
    • savePolicy

      public void savePolicy(Model model)
      savePolicy saves all policy rules to the storage.
      Specified by:
      savePolicy in interface Adapter
      Parameters:
      model - the model.
    • getModelPolicy

      private List<String> getModelPolicy(Model model, String ptype)
    • loadPolicyData

      private void loadPolicyData(Model model, Helper.loadPolicyLineHandler<String,Model> handler, InputStream inputStream)
    • savePolicyFile

      private void savePolicyFile(String text)
    • addPolicy

      public void addPolicy(String sec, String ptype, List<String> rule)
      addPolicy adds a policy rule to the storage.
      Specified by:
      addPolicy in interface Adapter
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      rule - the rule, like (sub, obj, act).
    • removePolicy

      public void removePolicy(String sec, String ptype, List<String> rule)
      removePolicy removes a policy rule from the storage.
      Specified by:
      removePolicy in interface Adapter
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      rule - the rule, like (sub, obj, act).
    • removeFilteredPolicy

      public void removeFilteredPolicy(String sec, String ptype, int fieldIndex, String... fieldValues)
      removeFilteredPolicy removes policy rules that match the filter from the storage.
      Specified by:
      removeFilteredPolicy in interface Adapter
      Parameters:
      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.