Class Model


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

      • sectionNameMap

        public static final java.util.Map<java.lang.String,​java.lang.String> sectionNameMap
      • requiredSections

        public static final java.lang.String[] requiredSections
      • modCount

        protected int modCount
      • domainIndex

        private int domainIndex
      • defaultDomain

        private java.lang.String defaultDomain
      • defaultSeparator

        private java.lang.String defaultSeparator
      • paramsPattern

        private static final java.util.regex.Pattern paramsPattern
    • Constructor Detail

      • Model

        public Model()
    • Method Detail

      • getModCount

        public int getModCount()
      • loadAssertion

        private boolean loadAssertion​(Model model,
                                      Config cfg,
                                      java.lang.String sec,
                                      java.lang.String key)
      • getParamsToken

        private static java.util.List<java.lang.String> getParamsToken​(java.lang.String value)
        getParamsToken Get ParamsToken from Assertion.Value
      • addDef

        public boolean addDef​(java.lang.String sec,
                              java.lang.String key,
                              java.lang.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 java.lang.String getKeySuffix​(int i)
      • loadSection

        private void loadSection​(Model model,
                                 Config cfg,
                                 java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String path)
        loadModel loads the model from model CONF file.
        Parameters:
        path - the path of the model file.
      • loadModelFromText

        public void loadModelFromText​(java.lang.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​(java.lang.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 java.lang.String saveSectionToText​(java.lang.String sec)
        saveSectionToText saves the section to the text.
        Returns:
        the section text.
      • saveModelToText

        public java.lang.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 java.util.Map<java.lang.String,​java.lang.Integer> getSubjectHierarchyMap​(java.util.List<java.util.List<java.lang.String>> policies)
      • findHierarchy

        private void findHierarchy​(java.util.Map<java.lang.String,​java.lang.String> policyMap,
                                   java.util.Map<java.lang.String,​java.lang.Integer> subjectHierarchyMap,
                                   java.util.List<java.lang.String> set,
                                   java.lang.String child)
      • getNameWithDomain

        public java.lang.String getNameWithDomain​(java.lang.String domain,
                                                  java.lang.String name)
      • toText

        public java.lang.String toText()
      • writeString

        private void writeString​(java.lang.StringBuilder s,
                                 java.lang.String sec,
                                 java.util.Map<java.lang.String,​java.lang.String> tokenPatterns)