Package org.casbin.jcasbin.model
Class Model
java.lang.Object
org.casbin.jcasbin.model.Policy
org.casbin.jcasbin.model.Model
Model represents the whole access control model.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addDef adds an assertion to the model.private void
findHierarchy
(Map<String, String> policyMap, Map<String, Integer> subjectHierarchyMap, List<String> set, String child) private String
getKeySuffix
(int i) int
getNameWithDomain
(String domain, String name) getParamsToken
(String value) getParamsToken Get ParamsToken from Assertion.ValuegetSubjectHierarchyMap
(List<List<String>> policies) boolean
hasSection
(String sec) hasSection checks if the section exists in the model.private boolean
loadAssertion
(Model model, Config cfg, String sec, String key) void
loadModel loads the model from model CONF file.void
loadModelFromConfig loads the model from the configuration.void
loadModelFromText
(String text) loadModelFromText loads the model from the text.private void
loadSection
(Model model, Config cfg, String sec) private void
loadSections
(Config cfg) Helper function for loadModel and loadModelFromTextstatic Model
newModel()
NewModel creates an empty model.static Model
newModelFromFile
(String path) NewModelFromString creates a model from a string which contains model text.static Model
newModelFromString
(String text) NewModelFromString creates a model from a string which contains model text.void
printModel prints the model to the log.saveModelToText saves the model to the text.private String
saveSectionToText
(String sec) saveSectionToText saves the section to the text.void
SetLogger sets the model's logger.void
sort policies by priority valuevoid
sort policies by hieraichy maptoText()
private void
writeString
(StringBuilder s, String sec, Map<String, String> tokenPatterns) Methods inherited from class org.casbin.jcasbin.model.Policy
addPolicies, addPolicy, buildConditionalRoleLinks, buildIncrementalConditionalRoleLinks, buildIncrementalRoleLinks, buildRoleLinks, clearPolicy, getFilteredPolicy, getPolicy, getValuesForFieldInPolicy, hasPolicies, hasPolicy, printPolicy, removeFilteredPolicy, removeFilteredPolicyReturnsEffects, removePolicies, removePolicy, savePolicyToText, updatePolicy
-
Field Details
-
sectionNameMap
-
requiredSections
-
modCount
protected int modCount -
domainIndex
private int domainIndex -
defaultDomain
-
defaultSeparator
-
paramsPattern
-
-
Constructor Details
-
Model
public Model()
-
-
Method Details
-
getModCount
public int getModCount() -
loadAssertion
-
getParamsToken
getParamsToken Get ParamsToken from Assertion.Value -
addDef
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
-
loadSection
-
loadSections
Helper function for loadModel and loadModelFromText- Parameters:
cfg
- the configuration parser
-
setLogger
SetLogger sets the model's logger.- Parameters:
logger
- the logger to be set for the model.
-
newModel
NewModel creates an empty model.- Returns:
- a new instance of the Model.
-
newModelFromFile
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
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
loadModel loads the model from model CONF file.- Parameters:
path
- the path of the model file.
-
loadModelFromText
loadModelFromText loads the model from the text.- Parameters:
text
- the model text.
-
loadModelFromConfig
loadModelFromConfig loads the model from the configuration.- Parameters:
cfg
- the model text.
-
hasSection
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
saveSectionToText saves the section to the text.- Returns:
- the section text.
-
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
-
findHierarchy
-
getNameWithDomain
-
toText
-
writeString
-