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
    • domainIndex

      private int domainIndex
    • defaultDomain

      private String defaultDomain
    • defaultSeparator

      private String defaultSeparator
    • paramsPattern

      private static final Pattern paramsPattern
  • Constructor Details

    • Model

      public Model()
  • Method Details

    • getModCount

      public int getModCount()
    • loadAssertion

      private boolean loadAssertion(Model model, Config cfg, String sec, String key)
    • getParamsToken

      private static List<String> getParamsToken(String value)
      getParamsToken Get ParamsToken from Assertion.Value
    • 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.
    • getKeySuffix

      private String getKeySuffix(int i)
    • loadSection

      private void loadSection(Model model, Config cfg, String sec)
    • loadSections

      private void loadSections(Config cfg)
      Helper function for loadModel and loadModelFromText
      Parameters:
      cfg - the configuration parser
    • 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.
    • saveSectionToText

      private String saveSectionToText(String sec)
      saveSectionToText saves the section to the text.
      Returns:
      the section text.
    • 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)
    • findHierarchy

      private void findHierarchy(Map<String,String> policyMap, Map<String,Integer> subjectHierarchyMap, List<String> set, String child)
    • getNameWithDomain

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

      public String toText()
    • writeString

      private void writeString(StringBuilder s, String sec, Map<String,String> tokenPatterns)