Class Model

java.lang.Object
org.casbin.jcasbin.model.Policy
org.casbin.jcasbin.model.Model

public class Model extends Policy
Model represents the whole access control model.
  • Field Details

    • sectionNameMap

      public static final Map<String,String> sectionNameMap
    • requiredSections

      public static final String[] requiredSections
    • modCount

      protected int modCount
  • Constructor Details

    • Model

      public Model()
  • Method Details

    • getModCount

      public int getModCount()
    • addDef

      public boolean addDef(String sec, String key, String value)
      addDef adds an assertion to the model.
      Parameters:
      sec - the section, "p" or "g".
      key - the policy type, "p", "p2", .. or "g", "g2", ..
      value - the policy rule, separated by ", ".
      Returns:
      succeeds or not.
    • setLogger

      public void setLogger(Logger logger)
      SetLogger sets the model's logger.
      Parameters:
      logger - the logger to be set for the model.
    • newModel

      public static Model newModel()
      NewModel creates an empty model.
      Returns:
      a new instance of the Model.
    • newModelFromFile

      public static Model newModelFromFile(String path)
      NewModelFromString creates a model from a string which contains model text.
      Parameters:
      path - the path of the model file.
      Returns:
      the model loaded from file.
    • newModelFromString

      public static Model newModelFromString(String text)
      NewModelFromString creates a model from a string which contains model text.
      Parameters:
      text - the path of the file.
      Returns:
      the model loaded from text.
    • loadModel

      public void loadModel(String path)
      loadModel loads the model from model CONF file.
      Parameters:
      path - the path of the model file.
    • loadModelFromText

      public void loadModelFromText(String text)
      loadModelFromText loads the model from the text.
      Parameters:
      text - the model text.
    • loadModelFromConfig

      public void loadModelFromConfig(Config cfg)
      loadModelFromConfig loads the model from the configuration.
      Parameters:
      cfg - the model text.
    • hasSection

      public boolean hasSection(String sec)
      hasSection checks if the section exists in the model.
      Parameters:
      sec - the section name to check, such as "p" or "g".
      Returns:
      whether the section exists in the model.
    • saveModelToText

      public String saveModelToText()
      saveModelToText saves the model to the text.
      Returns:
      the model text.
    • printModel

      public void printModel()
      printModel prints the model to the log.
    • sortPoliciesByPriority

      public void sortPoliciesByPriority()
      sort policies by priority value
    • sortPoliciesBySubjectHieraichy

      public void sortPoliciesBySubjectHieraichy()
      sort policies by hieraichy map
    • getSubjectHierarchyMap

      public Map<String,Integer> getSubjectHierarchyMap(List<List<String>> policies)
    • getNameWithDomain

      public String getNameWithDomain(String domain, String name)
    • toText

      public String toText()